now unhooking is more specific, auth by server password, persistent !away
This commit is contained in:
parent
ff3f22a2e5
commit
649fc46127
@ -13,7 +13,7 @@ import botconfig
|
|||||||
|
|
||||||
def generate(fdict, **kwargs):
|
def generate(fdict, **kwargs):
|
||||||
"""Generates a decorator generator. Always use this"""
|
"""Generates a decorator generator. Always use this"""
|
||||||
def cmd(*s, raw_nick=False, admin_only=False, owner_only=False):
|
def cmd(*s, raw_nick=False, admin_only=False, owner_only=False, id=-1):
|
||||||
def dec(f):
|
def dec(f):
|
||||||
def innerf(*args):
|
def innerf(*args):
|
||||||
largs = list(args)
|
largs = list(args)
|
||||||
@ -49,9 +49,19 @@ def generate(fdict, **kwargs):
|
|||||||
innerf.owner_only = owner_only
|
innerf.owner_only = owner_only
|
||||||
innerf.raw_nick = raw_nick
|
innerf.raw_nick = raw_nick
|
||||||
innerf.admin_only = admin_only
|
innerf.admin_only = admin_only
|
||||||
|
innerf.id = id
|
||||||
innerf.__doc__ = f.__doc__
|
innerf.__doc__ = f.__doc__
|
||||||
return innerf
|
return innerf
|
||||||
|
|
||||||
return dec
|
return dec
|
||||||
|
|
||||||
return lambda *args, **kwarargs: cmd(*args, **kwarargs) if kwarargs else cmd(*args, **kwargs)
|
return lambda *args, **kwarargs: cmd(*args, **kwarargs) if kwarargs else cmd(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def unhook(hdict, id):
|
||||||
|
for cmd in list(hdict.keys()):
|
||||||
|
for x in hdict[cmd]:
|
||||||
|
if x.id == id:
|
||||||
|
hdict[cmd].remove(x)
|
||||||
|
if not hdict[cmd]:
|
||||||
|
del hdict[cmd]
|
@ -101,6 +101,7 @@ class IRCClient(object):
|
|||||||
self.real_name = ""
|
self.real_name = ""
|
||||||
self.host = None
|
self.host = None
|
||||||
self.port = None
|
self.port = None
|
||||||
|
self.password = ""
|
||||||
self.connect_cb = None
|
self.connect_cb = None
|
||||||
self.blocking = True
|
self.blocking = True
|
||||||
self.lock = threading.RLock()
|
self.lock = threading.RLock()
|
||||||
@ -173,6 +174,7 @@ class IRCClient(object):
|
|||||||
|
|
||||||
self.nick(self.nickname)
|
self.nick(self.nickname)
|
||||||
self.user(self.nickname, self.real_name)
|
self.user(self.nickname, self.real_name)
|
||||||
|
self.send("PASS :{0}\r\n".format(self.password if self.password else "NOPASS"))
|
||||||
|
|
||||||
if self.connect_cb:
|
if self.connect_cb:
|
||||||
self.connect_cb(self)
|
self.connect_cb(self)
|
||||||
|
18
var.py
18
var.py
@ -147,4 +147,20 @@ class ChangedRolesMode(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise InvalidModeException("A bad value was used in mode roles.")
|
raise InvalidModeException("A bad value was used in mode roles.")
|
||||||
for k in ROLES_GUIDE.keys():
|
for k in ROLES_GUIDE.keys():
|
||||||
self.ROLES_GUIDE[k] = tuple(lx)
|
self.ROLES_GUIDE[k] = tuple(lx)
|
||||||
|
|
||||||
|
|
||||||
|
# Load saved settings
|
||||||
|
import pickle
|
||||||
|
import os
|
||||||
|
|
||||||
|
if os.path.exists("data.dat"):
|
||||||
|
with open("data.dat", "rb") as lf:
|
||||||
|
data = pickle.load(lf)
|
||||||
|
if not isinstance(data, dict) or "away" not in data:
|
||||||
|
raise Exception("data.dat is not valid!")
|
||||||
|
AWAY = data["away"]
|
||||||
|
|
||||||
|
def save_data():
|
||||||
|
with open("data.dat", "wb") as wdf:
|
||||||
|
pickle.dump({"away":AWAY}, wdf)
|
@ -82,6 +82,7 @@ def main():
|
|||||||
"":__unhandled__},
|
"":__unhandled__},
|
||||||
host=botconfig.HOST,
|
host=botconfig.HOST,
|
||||||
port=botconfig.PORT,
|
port=botconfig.PORT,
|
||||||
|
password=botconfig.PASS,
|
||||||
nickname=botconfig.NICK,
|
nickname=botconfig.NICK,
|
||||||
connect_cb=wolfgame.connect_callback
|
connect_cb=wolfgame.connect_callback
|
||||||
)
|
)
|
||||||
|
63
wolfgame.py
63
wolfgame.py
@ -42,12 +42,18 @@ def connect_callback(cli):
|
|||||||
var.USERS = []
|
var.USERS = []
|
||||||
var.CLOAKS = []
|
var.CLOAKS = []
|
||||||
|
|
||||||
@hook("whoreply")
|
@hook("whoreply", id=294)
|
||||||
def on_whoreply(cli, server, dunno, chan, dunno1,
|
def on_whoreply(cli, server, dunno, chan, dunno1,
|
||||||
cloak, dunno3, user, status, dunno4):
|
cloak, dunno3, user, status, dunno4):
|
||||||
if user in var.USERS: return # Don't add someone who is already there
|
if user in var.USERS: return # Don't add someone who is already there
|
||||||
var.USERS.append(user)
|
var.USERS.append(user)
|
||||||
var.CLOAKS.append(cloak)
|
var.CLOAKS.append(cloak)
|
||||||
|
|
||||||
|
@hook("endofwho", id=294)
|
||||||
|
def afterwho(*args):
|
||||||
|
decorators.unhook(HOOKS, 294)
|
||||||
|
|
||||||
|
|
||||||
cli.who(botconfig.CHANNEL)
|
cli.who(botconfig.CHANNEL)
|
||||||
|
|
||||||
@hook("nicknameinuse")
|
@hook("nicknameinuse")
|
||||||
@ -246,7 +252,7 @@ def pinger(cli, nick, chan, rest):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@hook("whoreply")
|
@hook("whoreply", id=800)
|
||||||
def on_whoreply(cli, server, dunno, chan, dunno1,
|
def on_whoreply(cli, server, dunno, chan, dunno1,
|
||||||
cloak, dunno3, user, status, dunno4):
|
cloak, dunno3, user, status, dunno4):
|
||||||
if not var.PINGING: return
|
if not var.PINGING: return
|
||||||
@ -258,15 +264,14 @@ def pinger(cli, nick, chan, rest):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@hook("endofwho")
|
@hook("endofwho", id=800)
|
||||||
def do_ping(*args):
|
def do_ping(*args):
|
||||||
if not var.PINGING: return
|
if not var.PINGING: return
|
||||||
|
|
||||||
cli.msg(chan, "PING! "+" ".join(TO_PING))
|
cli.msg(chan, "PING! "+" ".join(TO_PING))
|
||||||
var.PINGING = False
|
var.PINGING = False
|
||||||
|
|
||||||
HOOKS.pop("whoreply")
|
decorators.unhook(HOOKS, 800)
|
||||||
HOOKS.pop("endofwho")
|
|
||||||
|
|
||||||
cli.who(chan)
|
cli.who(chan)
|
||||||
|
|
||||||
@ -284,6 +289,8 @@ def away(cli, nick, *rest):
|
|||||||
cli.notice(nick, "You are now no longer marked as away.")
|
cli.notice(nick, "You are now no longer marked as away.")
|
||||||
return
|
return
|
||||||
var.AWAY.append(cloak)
|
var.AWAY.append(cloak)
|
||||||
|
var.save_data()
|
||||||
|
|
||||||
cli.notice(nick, "You are now marked as away.")
|
cli.notice(nick, "You are now marked as away.")
|
||||||
|
|
||||||
|
|
||||||
@ -896,8 +903,8 @@ def begin_day(cli):
|
|||||||
var.GUARDED = {}
|
var.GUARDED = {}
|
||||||
|
|
||||||
cli.msg(chan, ("The villagers must now vote for whom to lynch. "+
|
cli.msg(chan, ("The villagers must now vote for whom to lynch. "+
|
||||||
'Use "{0}lynch <nick>" to cast your vote. 3 votes '+
|
'Use "{0}lynch <nick>" to cast your vote. {1} votes '+
|
||||||
'are required to lynch.').format(botconfig.CMD_CHAR))
|
'are required to lynch.').format(botconfig.CMD_CHAR, len(var.list_players()) // 2 + 1))
|
||||||
|
|
||||||
if var.DAY_TIME_LIMIT > 0: # Time limit enabled
|
if var.DAY_TIME_LIMIT > 0: # Time limit enabled
|
||||||
var.DAY_ID = timetime()
|
var.DAY_ID = timetime()
|
||||||
@ -1163,7 +1170,8 @@ def shoot(cli, nick, chan, rest):
|
|||||||
cli.msg(chan, ("\u0002{0}\u0002 is a villager and is injured but "+
|
cli.msg(chan, ("\u0002{0}\u0002 is a villager and is injured but "+
|
||||||
"will have a full recovery. S/He will be resting "+
|
"will have a full recovery. S/He will be resting "+
|
||||||
"for the day.").format(victim))
|
"for the day.").format(victim))
|
||||||
var.WOUNDED.append(victim)
|
if victim not in var.WOUNDED:
|
||||||
|
var.WOUNDED.append(victim)
|
||||||
chk_decision(cli)
|
chk_decision(cli)
|
||||||
elif rand <= chances[0] + chances[1]:
|
elif rand <= chances[0] + chances[1]:
|
||||||
cli.msg(chan, "\u0002{0}\u0002 is a lousy shooter. S/He missed!".format(nick))
|
cli.msg(chan, "\u0002{0}\u0002 is a lousy shooter. S/He missed!".format(nick))
|
||||||
@ -1850,7 +1858,7 @@ def fwait(cli, nick, chan, rest):
|
|||||||
else:
|
else:
|
||||||
var.CAN_START_TIME += timedelta(seconds=extra)
|
var.CAN_START_TIME += timedelta(seconds=extra)
|
||||||
var.WAITED += 1
|
var.WAITED += 1
|
||||||
cli.msg(chan, ("\u0002{0}\u0002 increased the wait time by "+
|
cli.msg(chan, ("\u0002{0}\u0002 forcibly increased the wait time by "+
|
||||||
"{1} seconds.").format(nick, extra))
|
"{1} seconds.").format(nick, extra))
|
||||||
|
|
||||||
|
|
||||||
@ -1938,7 +1946,7 @@ def show_admins(cli, nick, chan, rest):
|
|||||||
"""Pings the admins that are available."""
|
"""Pings the admins that are available."""
|
||||||
admins = []
|
admins = []
|
||||||
|
|
||||||
@hook("whoreply")
|
@hook("whoreply", id = 4)
|
||||||
def on_whoreply(cli, server, dunno, chan, dunno1,
|
def on_whoreply(cli, server, dunno, chan, dunno1,
|
||||||
cloak, dunno3, user, status, dunno4):
|
cloak, dunno3, user, status, dunno4):
|
||||||
if ((cloak in botconfig.ADMINS or cloak in botconfig.OWNERS) and 'G' not in status and
|
if ((cloak in botconfig.ADMINS or cloak in botconfig.OWNERS) and 'G' not in status and
|
||||||
@ -1947,12 +1955,11 @@ def show_admins(cli, nick, chan, rest):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@hook("endofwho")
|
@hook("endofwho", id = 4)
|
||||||
def show(*args):
|
def show(*args):
|
||||||
cli.msg(chan, "Available admins: "+" ".join(admins))
|
cli.msg(chan, "Available admins: "+" ".join(admins))
|
||||||
|
|
||||||
HOOKS.pop("whoreply") # todo, makes this better :(
|
decorators.unhook(HOOKS, 4)
|
||||||
HOOKS.pop("endofwho")
|
|
||||||
|
|
||||||
cli.who(chan)
|
cli.who(chan)
|
||||||
|
|
||||||
@ -2010,6 +2017,36 @@ if botconfig.DEBUG_MODE:
|
|||||||
cli.msg(chan, "Operation successful.")
|
cli.msg(chan, "Operation successful.")
|
||||||
else:
|
else:
|
||||||
cli.msg(chan, "That command was not found.")
|
cli.msg(chan, "That command was not found.")
|
||||||
|
|
||||||
|
|
||||||
|
@cmd("rforce", admin_only=True)
|
||||||
|
def rforcepm(cli, nick, chan, rest):
|
||||||
|
rst = re.split(" +",rest)
|
||||||
|
if len(rst) < 2:
|
||||||
|
cli.msg(chan, "The syntax is incorrect.")
|
||||||
|
return
|
||||||
|
who = rst.pop(0).strip()
|
||||||
|
who.replace("_", " ")
|
||||||
|
|
||||||
|
if who not in var.ROLES or not var.ROLES[who]:
|
||||||
|
cli.msg(chan, nick+": invalid role")
|
||||||
|
return
|
||||||
|
|
||||||
|
cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1)
|
||||||
|
if cmd in PM_COMMANDS.keys() and not PM_COMMANDS[cmd][0].owner_only:
|
||||||
|
for fn in PM_COMMANDS[cmd]:
|
||||||
|
for guy in var.ROLES[who]:
|
||||||
|
fn(cli, guy, " ".join(rst))
|
||||||
|
cli.msg(chan, "Operation successful.")
|
||||||
|
#if var.PHASE == "night": <- Causes problems with night starting twice.
|
||||||
|
# chk_nightdone(cli)
|
||||||
|
elif cmd.lower() in COMMANDS.keys() and not COMMANDS[cmd][0].owner_only:
|
||||||
|
for fn in COMMANDS[cmd]:
|
||||||
|
for guy in var.ROLES[who]:
|
||||||
|
fn(cli, guy, chan, " ".join(rst))
|
||||||
|
cli.msg(chan, "Operation successful.")
|
||||||
|
else:
|
||||||
|
cli.msg(chan, "That command was not found.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user