Skip to content

Commit

Permalink
add argparse to main
Browse files Browse the repository at this point in the history
  • Loading branch information
vesche committed Feb 20, 2018
1 parent 9cb5a60 commit e616aed
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions stabbybot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,57 @@
# https://github.com/vesche/stabbybot
#

import argparse
import websocket

import state
import comm
import brain


SERVER = '45.77.80.61:443'
# SERVER = '45.77.80.61'
GAME_URL = 'http://stabby.io'
GAME_VER = '000.0.4.3'
USERNAME = 'sb'


def get_parser():
parser = argparse.ArgumentParser(description='stabbybot')
parser.add_argument('-s', '--server',
help='server ip', required=True, type=str)
parser.add_argument('-u', '--username',
help='username', default='sb', type=str)
return parser


def main():
parser = get_parser()
args = vars(parser.parse_args())
server = args['server']
username = args['username']

ws = websocket.WebSocket()
ws.settimeout(1)
ws.connect('ws://%s' % SERVER, origin=GAME_URL)
ws.connect('ws://%s:443' % server, origin=GAME_URL)

# instantiate classes
# incoming = comm.Incoming()
gs = state.GameState()
outgoing = comm.Outgoing(ws)
# bot = brain.GenOne(outgoing)
bot = brain.GenTwo(outgoing)

# init comms
outgoing.begin(GAME_VER)
outgoing.setname(USERNAME)
outgoing.setname(username)

try:
while True:
raw_data = ws.recv()
# incoming.process(data)
comm.incoming(gs, raw_data)

# tmp, need some sort of logging
if gs.game_state['dead']:
print('[-] You have been killed.')
break

# bot.testB(gs.game_state)

bot.main(gs.game_state)
except KeyboardInterrupt:
pass
Expand Down

0 comments on commit e616aed

Please sign in to comment.