diff --git a/vars.py b/vars.py new file mode 100644 index 0000000..558b00e --- /dev/null +++ b/vars.py @@ -0,0 +1,4 @@ +GAME_STARTED = False +ROLES = {"person" : []} +ORIGINAL_ROLES = None +PHASE = "none" # "join", "day", or "night" \ No newline at end of file diff --git a/wolfbot.py b/wolfbot.py index 867b955..aa44fbc 100644 --- a/wolfbot.py +++ b/wolfbot.py @@ -6,32 +6,28 @@ import logging import botconfig def connect_callback(cli): - helpers.identify(cli, botconfig.PASS) - helpers.join(cli, botconfig.CHANNEL) - helpers.msg(cli, "ChanServ", "op "+botconfig.CHANNEL) - helpers.msg(cli, botconfig.CHANNEL, "\u0002Wolfbot2 is here.\u0002") + cli.identify(botconfig.PASS) + cli.join(botconfig.CHANNEL) + cli.msg("ChanServ", "op "+botconfig.CHANNEL) + cli.msg(botconfig.CHANNEL, "\u0002Wolfbot2 is here.\u0002") -G_PM_COMMANDS = [] -G_COMMANDS = [] +G_PM_COMMAND = [] +G_COMMAND = [] COMMANDS = {} PM_COMMANDS = {} HOOKS = {} -def cmd(s, pmOnly = False): +def cmd(s, pm = False): def dec(f): - if s is None and pmOnly: - G_PM_COMMANDS.append(f) - elif s is None and not pmOnly: - G_COMMANDS.append(f) - elif pmOnly: - if s in PM_COMMANDS: - PM_COMMANDS[s].append(f) - else: PM_COMMANDS[s] = [f] + if s is None and pm: + G_PM_COMMAND = f + elif s is None and not pm: + G_COMMAND = f + elif pm: + PM_COMMANDS[s] = f else: - if s in COMMANDS: - COMMANDS[s].append(f) - else: COMMANDS[s] = [f] + COMMANDS[s] = f return f return dec @@ -45,21 +41,17 @@ class WolfBotHandler(DefaultCommandHandler): def __init__(self, client): super().__init__(client) - def privmsg(self, rawnick, chan, msg): - print("{0} in {1} said: {2}".format(rawnick, chan, msg)) - + def privmsg(self, rawnick, chan, msg): if chan != botconfig.NICK: #not a PM - for x in COMMANDS: + for x in COMMANDS.keys(): if msg.startswith(x): msg = msg.replace(x, "", 1) - for f in COMMANDS[x]: - f(self.client, rawnick, chan, msg.lstrip()) + COMMANDS[x](self.client, rawnick, chan, msg.lstrip()) else: - for x in PM_COMMANDS: + for x in PM_COMMANDS.keys(): if msg.startswith(x): msg = msg.replace(x, "", 1) - for f in PM_COMMANDS[x]: - f(self.client, rawnick, msg.lstrip()) + PM_COMMANDS[x](self.client, rawnick, msg.lstrip()) def nick(self, fro, to): print(fro, to) @@ -73,20 +65,58 @@ def main(): while True: next(conn) -#Game Logic Begins: + +# Game Logic Begins: + +import vars + +def reset_game(): + vars.GAME_STARTED = False + vars.ROLES = {"person" : []} + vars.PHASE = "none" -@cmd("!say", True) -def join(cli, rawnick, rest): +# Command Handlers: +@cmd("!say", pm=True) +def say(cli, rawnick, rest): # To be removed later cli.msg(botconfig.CHANNEL, "{0} says: {1}".format(parse_nick(rawnick)[0], rest)) -@cmd("!bye", True) -@cmd("!bye", False) -def forced_exit(cli, rawnick, *rest): +@cmd("!bye", pm=True) +@cmd("!bye", pm=False) +def forced_exit(cli, rawnick, *rest): # Admin Only if parse_nick(rawnick)[0] in botconfig.ADMINS: cli.quit("Forced quit from admin") raise SystemExit -#Game Logic Ends +@cmd("!join", pm=False) +def join(cli, rawnick, chan, rest): + if vars.PHASE != "none": + return + + vars.GAME_STARTED = True + + nick = parse_nick(rawnick)[0] + cli.msg(chan, '{0} has started a game of Werewolf. \ +Type "!join" to join. Type "!start" to start the game. \ +Type "!wait" to increase join wait time.'.format(nick)) + + vars.ROLES["person"].append(nick) + vars.PHASE = "join" + + + +@cmd("!stats", pm=False) +def stats(cli, rawnick, chan, rest): + if vars.PHASE == "none": + return + nick = parse_nick(rawnick)[0] + pl = [] + for x in vars.ROLES.values(): pl.extend(x) + cli.msg(chan, '{0}: {1} players: {2}'.format(nick, + len(pl), ", ".join(pl))) + + +# Game Logic Ends + if __name__ == "__main__": main() \ No newline at end of file