|
|
@ -6,32 +6,28 @@ import logging |
|
|
|
import botconfig |
|
|
|
import botconfig |
|
|
|
|
|
|
|
|
|
|
|
def connect_callback(cli): |
|
|
|
def connect_callback(cli): |
|
|
|
helpers.identify(cli, botconfig.PASS) |
|
|
|
cli.identify(botconfig.PASS) |
|
|
|
helpers.join(cli, botconfig.CHANNEL) |
|
|
|
cli.join(botconfig.CHANNEL) |
|
|
|
helpers.msg(cli, "ChanServ", "op "+botconfig.CHANNEL) |
|
|
|
cli.msg("ChanServ", "op "+botconfig.CHANNEL) |
|
|
|
helpers.msg(cli, botconfig.CHANNEL, "\u0002Wolfbot2 is here.\u0002") |
|
|
|
cli.msg(botconfig.CHANNEL, "\u0002Wolfbot2 is here.\u0002") |
|
|
|
|
|
|
|
|
|
|
|
G_PM_COMMANDS = [] |
|
|
|
G_PM_COMMAND = [] |
|
|
|
G_COMMANDS = [] |
|
|
|
G_COMMAND = [] |
|
|
|
COMMANDS = {} |
|
|
|
COMMANDS = {} |
|
|
|
PM_COMMANDS = {} |
|
|
|
PM_COMMANDS = {} |
|
|
|
|
|
|
|
|
|
|
|
HOOKS = {} |
|
|
|
HOOKS = {} |
|
|
|
|
|
|
|
|
|
|
|
def cmd(s, pmOnly = False): |
|
|
|
def cmd(s, pm = False): |
|
|
|
def dec(f): |
|
|
|
def dec(f): |
|
|
|
if s is None and pmOnly: |
|
|
|
if s is None and pm: |
|
|
|
G_PM_COMMANDS.append(f) |
|
|
|
G_PM_COMMAND = f |
|
|
|
elif s is None and not pmOnly: |
|
|
|
elif s is None and not pm: |
|
|
|
G_COMMANDS.append(f) |
|
|
|
G_COMMAND = f |
|
|
|
elif pmOnly: |
|
|
|
elif pm: |
|
|
|
if s in PM_COMMANDS: |
|
|
|
PM_COMMANDS[s] = f |
|
|
|
PM_COMMANDS[s].append(f) |
|
|
|
|
|
|
|
else: PM_COMMANDS[s] = [f] |
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
if s in COMMANDS: |
|
|
|
COMMANDS[s] = f |
|
|
|
COMMANDS[s].append(f) |
|
|
|
|
|
|
|
else: COMMANDS[s] = [f] |
|
|
|
|
|
|
|
return f |
|
|
|
return f |
|
|
|
return dec |
|
|
|
return dec |
|
|
|
|
|
|
|
|
|
|
@ -46,20 +42,16 @@ class WolfBotHandler(DefaultCommandHandler): |
|
|
|
super().__init__(client) |
|
|
|
super().__init__(client) |
|
|
|
|
|
|
|
|
|
|
|
def privmsg(self, rawnick, chan, msg): |
|
|
|
def privmsg(self, rawnick, chan, msg): |
|
|
|
print("{0} in {1} said: {2}".format(rawnick, chan, msg)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if chan != botconfig.NICK: #not a PM |
|
|
|
if chan != botconfig.NICK: #not a PM |
|
|
|
for x in COMMANDS: |
|
|
|
for x in COMMANDS.keys(): |
|
|
|
if msg.startswith(x): |
|
|
|
if msg.startswith(x): |
|
|
|
msg = msg.replace(x, "", 1) |
|
|
|
msg = msg.replace(x, "", 1) |
|
|
|
for f in COMMANDS[x]: |
|
|
|
COMMANDS[x](self.client, rawnick, chan, msg.lstrip()) |
|
|
|
f(self.client, rawnick, chan, msg.lstrip()) |
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
for x in PM_COMMANDS: |
|
|
|
for x in PM_COMMANDS.keys(): |
|
|
|
if msg.startswith(x): |
|
|
|
if msg.startswith(x): |
|
|
|
msg = msg.replace(x, "", 1) |
|
|
|
msg = msg.replace(x, "", 1) |
|
|
|
for f in PM_COMMANDS[x]: |
|
|
|
PM_COMMANDS[x](self.client, rawnick, msg.lstrip()) |
|
|
|
f(self.client, rawnick, msg.lstrip()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def nick(self, fro, to): |
|
|
|
def nick(self, fro, to): |
|
|
|
print(fro, to) |
|
|
|
print(fro, to) |
|
|
@ -73,20 +65,58 @@ def main(): |
|
|
|
while True: |
|
|
|
while True: |
|
|
|
next(conn) |
|
|
|
next(conn) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Game Logic Begins: |
|
|
|
# Game Logic Begins: |
|
|
|
|
|
|
|
|
|
|
|
@cmd("!say", True) |
|
|
|
import vars |
|
|
|
def join(cli, rawnick, rest): |
|
|
|
|
|
|
|
|
|
|
|
def reset_game(): |
|
|
|
|
|
|
|
vars.GAME_STARTED = False |
|
|
|
|
|
|
|
vars.ROLES = {"person" : []} |
|
|
|
|
|
|
|
vars.PHASE = "none" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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)) |
|
|
|
cli.msg(botconfig.CHANNEL, "{0} says: {1}".format(parse_nick(rawnick)[0], rest)) |
|
|
|
|
|
|
|
|
|
|
|
@cmd("!bye", True) |
|
|
|
@cmd("!bye", pm=True) |
|
|
|
@cmd("!bye", False) |
|
|
|
@cmd("!bye", pm=False) |
|
|
|
def forced_exit(cli, rawnick, *rest): |
|
|
|
def forced_exit(cli, rawnick, *rest): # Admin Only |
|
|
|
if parse_nick(rawnick)[0] in botconfig.ADMINS: |
|
|
|
if parse_nick(rawnick)[0] in botconfig.ADMINS: |
|
|
|
cli.quit("Forced quit from admin") |
|
|
|
cli.quit("Forced quit from admin") |
|
|
|
raise SystemExit |
|
|
|
raise SystemExit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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 |
|
|
|
# Game Logic Ends |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|
main() |
|
|
|
main() |