Mass overhaul to the decorators
This commit is contained in:
parent
416ded936d
commit
ca2e901d58
@ -1,167 +1,222 @@
|
|||||||
# Copyright (c) 2011, Jimmy Cao
|
# Old, obsolete & original code by jcao219
|
||||||
# All rights reserved.
|
# rewritten by Vgr
|
||||||
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
# Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
||||||
# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
import botconfig
|
import botconfig
|
||||||
import src.settings as var
|
|
||||||
from oyoyo.parse import parse_nick
|
from oyoyo.parse import parse_nick
|
||||||
|
from src import settings as var
|
||||||
from src import logger
|
from src import logger
|
||||||
|
|
||||||
adminlog = logger(None)
|
adminlog = logger(None)
|
||||||
|
|
||||||
def generate(fdict, permissions=True, **kwargs):
|
COMMANDS = defaultdict(list)
|
||||||
"""Generates a decorator generator. Always use this"""
|
HOOKS = defaultdict(list)
|
||||||
def cmd(*s, raw_nick=False, admin_only=False, owner_only=False, chan=True, pm=False,
|
|
||||||
game=False, join=False, none=False, playing=False, roles=(), hookid=-1):
|
|
||||||
def dec(f):
|
|
||||||
def innerf(*args):
|
|
||||||
largs = list(args)
|
|
||||||
rawnick = largs[1]
|
|
||||||
if not permissions:
|
|
||||||
return f(*largs)
|
|
||||||
if len(largs) > 1 and largs[1]:
|
|
||||||
nick, _, _, cloak = parse_nick(largs[1])
|
|
||||||
|
|
||||||
if cloak is None:
|
class cmd:
|
||||||
cloak = ""
|
def __init__(self, *cmds, raw_nick=False, admin_only=False, owner_only=False,
|
||||||
|
chan=True, pm=False, join=False, none=False, game=False, playing=False, roles=()):
|
||||||
|
|
||||||
|
self.cmds = cmds
|
||||||
|
self.raw_nick = raw_nick
|
||||||
|
self.admin_only = admin_only
|
||||||
|
self.owner_only = owner_only
|
||||||
|
self.chan = chan
|
||||||
|
self.pm = pm
|
||||||
|
self.join = join
|
||||||
|
self.none = none
|
||||||
|
self.game = game
|
||||||
|
self.playing = playing
|
||||||
|
self.roles = roles
|
||||||
|
self.func = None
|
||||||
|
self.aftergame = False
|
||||||
|
self.name = cmds[0]
|
||||||
|
|
||||||
|
alias = False
|
||||||
|
self.aliases = []
|
||||||
|
for name in cmds:
|
||||||
|
for func in COMMANDS[name]:
|
||||||
|
if (func.owner_only != owner_only or
|
||||||
|
func.admin_only != admin_only):
|
||||||
|
raise ValueError("unmatching protection levels for " + func.name)
|
||||||
|
|
||||||
|
COMMANDS[name].append(self)
|
||||||
|
if alias:
|
||||||
|
self.aliases.append(self)
|
||||||
|
alias = True
|
||||||
|
|
||||||
|
def __call__(self, *args):
|
||||||
|
if self.func is None: # when function is defined; set self.func and call itself again
|
||||||
|
self.func = args[0]
|
||||||
|
self.__doc__ = self.func.__doc__
|
||||||
|
return self
|
||||||
|
|
||||||
|
largs = list(args)
|
||||||
|
|
||||||
|
cli, rawnick, chan, rest = largs
|
||||||
|
nick, mode, user, cloak = parse_nick(rawnick)
|
||||||
|
|
||||||
|
if cloak is None:
|
||||||
|
cloak = ""
|
||||||
|
|
||||||
|
if not self.raw_nick:
|
||||||
|
largs[1] = nick
|
||||||
|
|
||||||
|
if nick == "<console>":
|
||||||
|
return self.func(*largs) # special case; no questions
|
||||||
|
|
||||||
|
if not self.pm and chan == nick:
|
||||||
|
return # PM command, not allowed
|
||||||
|
|
||||||
|
if not self.chan and chan != nick:
|
||||||
|
return # channel command, not allowed
|
||||||
|
|
||||||
|
if chan.startswith("#") and chan != botconfig.CHANNEL and not (admin_only or owner_only):
|
||||||
|
if "" in self.cmds:
|
||||||
|
return # don't have empty commands triggering in other channels
|
||||||
|
for command in self.cmds:
|
||||||
|
if command in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
if nick in var.USERS and var.USERS[nick]["account"] != "*":
|
||||||
|
acc = var.USERS[nick]["account"]
|
||||||
|
else:
|
||||||
|
acc = None
|
||||||
|
|
||||||
|
if "" in self.cmds:
|
||||||
|
return self.func(*largs)
|
||||||
|
|
||||||
|
if self.game and var.PHASE not in ("day", "night") + (("join",) if self.join else ()):
|
||||||
|
if chan == nick:
|
||||||
|
pm(cli, nick, "No game is currently running.")
|
||||||
|
else:
|
||||||
|
cli.notice(nick, "No game is currently running.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if ((self.join and self.none and var.PHASE not in ("join", "none")) or
|
||||||
|
(self.none and not self.join and var.PHASE != "none")):
|
||||||
|
if chan == nick:
|
||||||
|
pm(cli, nick, "Sorry, but the game is already running. Try again next time.")
|
||||||
|
else:
|
||||||
|
cli.notice(nick, "Sorry, but the game is already running. Try again next time.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.join and not self.none:
|
||||||
|
if var.PHASE == "none":
|
||||||
|
if chan == nick:
|
||||||
|
pm(cli, nick, "No game is currently running.")
|
||||||
else:
|
else:
|
||||||
nick = ""
|
cli.notice(nick, "No game is currently running.")
|
||||||
cloak = ""
|
return
|
||||||
if not raw_nick and len(largs) > 1 and largs[1]:
|
|
||||||
largs[1] = nick
|
if var.PHASE != "join" and not self.game:
|
||||||
if nick == "<console>":
|
if chan == nick:
|
||||||
return f(*largs) # special case; no questions
|
pm(cli, nick, "Werewolf is already in play.")
|
||||||
if not pm and largs[2] == nick: # PM command
|
|
||||||
return
|
|
||||||
if not chan and largs[2] != nick: # channel command
|
|
||||||
return
|
|
||||||
if largs[2].startswith("#") and largs[2] != botconfig.CHANNEL and not admin_only and not owner_only:
|
|
||||||
if "" in s:
|
|
||||||
return # Don't have empty commands triggering in other channels
|
|
||||||
allowed = False
|
|
||||||
for cmdname in s:
|
|
||||||
if cmdname in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
|
|
||||||
allowed = True
|
|
||||||
break
|
|
||||||
if not allowed:
|
|
||||||
return
|
|
||||||
if nick in var.USERS.keys() and var.USERS[nick]["account"] != "*":
|
|
||||||
acc = var.USERS[nick]["account"]
|
|
||||||
else:
|
else:
|
||||||
acc = None
|
cli.notice(nick, "Werewolf is already in play.")
|
||||||
if "" in s:
|
return
|
||||||
return f(*largs)
|
|
||||||
if game and var.PHASE not in ("day", "night") + (("join",) if join else ()):
|
|
||||||
largs[0].notice(nick, "No game is currently running.")
|
|
||||||
return
|
|
||||||
if ((join and none and var.PHASE not in ("join", "none"))
|
|
||||||
or (none and not join and var.PHASE != "none")):
|
|
||||||
largs[0].notice(nick, "Sorry, but the game is already running. Try again next time.")
|
|
||||||
return
|
|
||||||
if join and not none:
|
|
||||||
if var.PHASE == "none":
|
|
||||||
largs[0].notice(nick, "No game is currently running.")
|
|
||||||
return
|
|
||||||
if var.PHASE != "join" and not game:
|
|
||||||
largs[0].notice(nick, "Werewolf is already in play.")
|
|
||||||
return
|
|
||||||
if playing and (nick not in var.list_players() or nick in var.DISCONNECTED.keys()):
|
|
||||||
largs[0].notice(nick, "You're not currently playing.")
|
|
||||||
return
|
|
||||||
if roles:
|
|
||||||
for role in roles:
|
|
||||||
if nick in var.ROLES[role]:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
if acc:
|
|
||||||
for pattern in var.DENY_ACCOUNTS.keys():
|
|
||||||
if fnmatch.fnmatch(acc.lower(), pattern.lower()):
|
|
||||||
for cmdname in s:
|
|
||||||
if cmdname in var.DENY_ACCOUNTS[pattern]:
|
|
||||||
largs[0].notice(nick, "You do not have permission to use that command.")
|
|
||||||
return
|
|
||||||
for pattern in var.ALLOW_ACCOUNTS.keys():
|
|
||||||
if fnmatch.fnmatch(acc.lower(), pattern.lower()):
|
|
||||||
for cmdname in s:
|
|
||||||
if cmdname in var.ALLOW_ACCOUNTS[pattern]:
|
|
||||||
if admin_only or owner_only:
|
|
||||||
adminlog(largs[2], rawnick, s[0], largs[3])
|
|
||||||
return f(*largs)
|
|
||||||
if not var.ACCOUNTS_ONLY and cloak:
|
|
||||||
for pattern in var.DENY.keys():
|
|
||||||
if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
|
|
||||||
for cmdname in s:
|
|
||||||
if cmdname in var.DENY[pattern]:
|
|
||||||
largs[0].notice(nick, "You do not have permission to use that command.")
|
|
||||||
return
|
|
||||||
for pattern in var.ALLOW.keys():
|
|
||||||
if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
|
|
||||||
for cmdname in s:
|
|
||||||
if cmdname in var.ALLOW[pattern]:
|
|
||||||
if admin_only or owner_only:
|
|
||||||
adminlog(largs[2], rawnick, s[0], largs[3])
|
|
||||||
return f(*largs) # no questions
|
|
||||||
if owner_only:
|
|
||||||
if var.is_owner(nick, cloak):
|
|
||||||
adminlog(largs[2], rawnick, s[0], largs[3])
|
|
||||||
return f(*largs)
|
|
||||||
else:
|
|
||||||
largs[0].notice(nick, "You are not the owner.")
|
|
||||||
return
|
|
||||||
if admin_only:
|
|
||||||
if var.is_admin(nick, cloak):
|
|
||||||
adminlog(largs[2], rawnick, s[0], largs[3])
|
|
||||||
return f(*largs)
|
|
||||||
else:
|
|
||||||
largs[0].notice(nick, "You are not an admin.")
|
|
||||||
return
|
|
||||||
return f(*largs)
|
|
||||||
alias = False
|
|
||||||
innerf.aliases = []
|
|
||||||
for x in s:
|
|
||||||
if x not in fdict.keys():
|
|
||||||
fdict[x] = []
|
|
||||||
else:
|
|
||||||
for fn in fdict[x]:
|
|
||||||
if (fn.owner_only != owner_only or
|
|
||||||
fn.admin_only != admin_only):
|
|
||||||
raise Exception("Command: "+x+" has non-matching protection levels!")
|
|
||||||
fdict[x].append(innerf)
|
|
||||||
if alias:
|
|
||||||
innerf.aliases.append(x)
|
|
||||||
alias = True
|
|
||||||
innerf.owner_only = owner_only
|
|
||||||
innerf.raw_nick = raw_nick
|
|
||||||
innerf.admin_only = admin_only
|
|
||||||
innerf.chan = chan
|
|
||||||
innerf.pm = pm
|
|
||||||
innerf.none = none
|
|
||||||
innerf.join = join
|
|
||||||
innerf.game = game
|
|
||||||
innerf.playing = playing
|
|
||||||
innerf.roles = roles
|
|
||||||
innerf.hookid = hookid
|
|
||||||
innerf.aftergame = False
|
|
||||||
innerf.__doc__ = f.__doc__
|
|
||||||
return innerf
|
|
||||||
|
|
||||||
return dec
|
if self.playing and (nick not in var.list_players() or nick in var.DISCONNECTED):
|
||||||
|
if chan == nick:
|
||||||
|
pm(cli, nick, "You're not currently playing.")
|
||||||
|
else:
|
||||||
|
cli.notice(nick, "You're not currently playing.")
|
||||||
|
return
|
||||||
|
|
||||||
return lambda *args, **kwarargs: cmd(*args, **kwarargs) if kwarargs else cmd(*args, **kwargs)
|
if self.roles:
|
||||||
|
for role in self.roles:
|
||||||
|
if nick in var.ROLES[role]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
return self.func(*largs) # don't check restrictions for role commands
|
||||||
|
|
||||||
def unhook(hdict, hookid):
|
if acc:
|
||||||
for cmd in list(hdict.keys()):
|
for pattern in var.DENY_ACCOUNTS:
|
||||||
for x in hdict[cmd]:
|
if fnmatch.fnmatch(acc.lower(), pattern.lower()):
|
||||||
if x.hookid == hookid:
|
for command in self.cmds:
|
||||||
hdict[cmd].remove(x)
|
if command in var.DENY_ACCOUNTS[pattern]:
|
||||||
if not hdict[cmd]:
|
if chan == nick:
|
||||||
del hdict[cmd]
|
pm(cli, nick, "You do not have permission to use that command.")
|
||||||
|
else:
|
||||||
|
cli.notice(nick, "You do not have permission to use that command.")
|
||||||
|
return
|
||||||
|
|
||||||
|
for pattern in var.ALLOW_ACCOUNTS:
|
||||||
|
if fnmatch.fnmatch(acc.lower(), pattern.lower()):
|
||||||
|
for command in self.cmds:
|
||||||
|
if command in var.ALLOW_ACCOUNTS[pattern]:
|
||||||
|
if self.admin_only or self.owner_only:
|
||||||
|
adminlog(chan, rawnick, self.name, rest)
|
||||||
|
return self.func(*largs)
|
||||||
|
|
||||||
|
if not var.ACCOUNTS_ONLY and cloak:
|
||||||
|
for pattern in var.DENY:
|
||||||
|
if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
|
||||||
|
for command in self.cmds:
|
||||||
|
if command in var.DENY[pattern]:
|
||||||
|
if chan == nick:
|
||||||
|
pm(cli, nick, "You do not have permission to use that command.")
|
||||||
|
else:
|
||||||
|
cli.notice(nick, "You do not have permission to use that command.")
|
||||||
|
return
|
||||||
|
|
||||||
|
for pattern in var.ALLOW:
|
||||||
|
if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
|
||||||
|
for command in self.cmds:
|
||||||
|
if command in var.ALLOW[pattern]:
|
||||||
|
if self.admin_only or self.owner_only:
|
||||||
|
adminlog(chan, rawnick, self.name, rest)
|
||||||
|
return self.func(*largs)
|
||||||
|
|
||||||
|
if self.owner_only:
|
||||||
|
if var.is_owner(nick, cloak):
|
||||||
|
adminlog(chan, rawnick, self.name, rest)
|
||||||
|
return self.func(*largs)
|
||||||
|
|
||||||
|
if chan == nick:
|
||||||
|
pm(cli, nick, "You are not the owner.")
|
||||||
|
else:
|
||||||
|
cli.notice(nick, "You are not the owner.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.admin_only:
|
||||||
|
if var.is_admin(nick, cloak):
|
||||||
|
adminlog(chan, rawnick, self.name, rest)
|
||||||
|
return self.func(*largs)
|
||||||
|
|
||||||
|
if chan == nick:
|
||||||
|
pm(cli, nick, "You are not an admin.")
|
||||||
|
else:
|
||||||
|
cli.notice(nick, "You are not an admin.")
|
||||||
|
return
|
||||||
|
|
||||||
|
return self.func(*largs)
|
||||||
|
|
||||||
|
class hook:
|
||||||
|
def __init__(self, name, hookid=-1):
|
||||||
|
self.name = name
|
||||||
|
self.hookid = hookid
|
||||||
|
self.func = None
|
||||||
|
|
||||||
|
HOOKS[name].append(self)
|
||||||
|
|
||||||
|
def __call__(self, *args):
|
||||||
|
if self.func is None:
|
||||||
|
self.func = args[0]
|
||||||
|
self.__doc__ = self.func.__doc__
|
||||||
|
return self
|
||||||
|
return self.func(*args)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def unhook(hookid):
|
||||||
|
for each in list(HOOKS):
|
||||||
|
for inner in list(HOOKS[each]):
|
||||||
|
if inner.hookid == hookid:
|
||||||
|
HOOKS[each].remove(inner)
|
||||||
|
if not HOOKS[each]:
|
||||||
|
del HOOKS[each]
|
||||||
|
@ -15,6 +15,7 @@ from src import wolfgame
|
|||||||
log = logger("errors.log")
|
log = logger("errors.log")
|
||||||
alog = logger(None)
|
alog = logger(None)
|
||||||
|
|
||||||
|
hook = decorators.hook
|
||||||
|
|
||||||
def notify_error(cli, chan, target_logger):
|
def notify_error(cli, chan, target_logger):
|
||||||
msg = "An error has occurred and has been logged."
|
msg = "An error has occurred and has been logged."
|
||||||
@ -56,18 +57,17 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
if chan == botconfig.NICK:
|
if chan == botconfig.NICK:
|
||||||
chan = parse_nick(rawnick)[0]
|
chan = parse_nick(rawnick)[0]
|
||||||
|
|
||||||
if "" in wolfgame.COMMANDS.keys():
|
for fn in decorators.COMMANDS[""]:
|
||||||
for fn in wolfgame.COMMANDS[""]:
|
try:
|
||||||
try:
|
fn(cli, rawnick, chan, msg)
|
||||||
fn(cli, rawnick, chan, msg)
|
except Exception:
|
||||||
except Exception:
|
if botconfig.DEBUG_MODE:
|
||||||
if botconfig.DEBUG_MODE:
|
raise
|
||||||
raise
|
else:
|
||||||
else:
|
notify_error(cli, chan, log)
|
||||||
notify_error(cli, chan, log)
|
|
||||||
|
|
||||||
|
|
||||||
for x in set(list(COMMANDS.keys()) + list(wolfgame.COMMANDS.keys())):
|
for x in decorators.COMMANDS:
|
||||||
if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(botconfig.CMD_CHAR):
|
if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(botconfig.CMD_CHAR):
|
||||||
break # channel message but no prefix; ignore
|
break # channel message but no prefix; ignore
|
||||||
if msg.lower().startswith(botconfig.CMD_CHAR+x):
|
if msg.lower().startswith(botconfig.CMD_CHAR+x):
|
||||||
@ -77,7 +77,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
if not h or h[0] == " ":
|
if not h or h[0] == " ":
|
||||||
for fn in COMMANDS.get(x, []) + (wolfgame.COMMANDS.get(x, [])):
|
for fn in decorators.COMMANDS.get(x, []):
|
||||||
try:
|
try:
|
||||||
fn(cli, rawnick, chan, h.lstrip())
|
fn(cli, rawnick, chan, h.lstrip())
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -86,13 +86,13 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
else:
|
else:
|
||||||
notify_error(cli, chan, log)
|
notify_error(cli, chan, log)
|
||||||
|
|
||||||
|
|
||||||
def unhandled(cli, prefix, cmd, *args):
|
def unhandled(cli, prefix, cmd, *args):
|
||||||
if cmd in set(list(HOOKS.keys()) + list(wolfgame.HOOKS.keys())):
|
if cmd in decorators.HOOKS:
|
||||||
largs = list(args)
|
largs = list(args)
|
||||||
for i,arg in enumerate(largs):
|
for i,arg in enumerate(largs):
|
||||||
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
|
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
|
||||||
for fn in HOOKS.get(cmd, []) + wolfgame.HOOKS.get(cmd, []):
|
for fn in decorators.HOOKS.get(cmd, []):
|
||||||
try:
|
try:
|
||||||
fn(cli, prefix, *largs)
|
fn(cli, prefix, *largs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -101,13 +101,6 @@ def unhandled(cli, prefix, cmd, *args):
|
|||||||
else:
|
else:
|
||||||
notify_error(cli, botconfig.CHANNEL, log)
|
notify_error(cli, botconfig.CHANNEL, log)
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = {}
|
|
||||||
HOOKS = {}
|
|
||||||
|
|
||||||
cmd = decorators.generate(COMMANDS)
|
|
||||||
hook = decorators.generate(HOOKS, raw_nick=True, permissions=False)
|
|
||||||
|
|
||||||
def connect_callback(cli):
|
def connect_callback(cli):
|
||||||
|
|
||||||
def prepare_stuff(*args):
|
def prepare_stuff(*args):
|
||||||
@ -123,7 +116,7 @@ def connect_callback(cli):
|
|||||||
|
|
||||||
cli.cap("REQ", "extended-join")
|
cli.cap("REQ", "extended-join")
|
||||||
cli.cap("REQ", "account-notify")
|
cli.cap("REQ", "account-notify")
|
||||||
|
|
||||||
wolfgame.connect_callback(cli)
|
wolfgame.connect_callback(cli)
|
||||||
|
|
||||||
cli.nick(botconfig.NICK) # very important (for regain/release)
|
cli.nick(botconfig.NICK) # very important (for regain/release)
|
||||||
@ -147,7 +140,7 @@ def connect_callback(cli):
|
|||||||
cli.nick(botconfig.NICK+"_")
|
cli.nick(botconfig.NICK+"_")
|
||||||
cli.user(botconfig.NICK, "")
|
cli.user(botconfig.NICK, "")
|
||||||
|
|
||||||
decorators.unhook(HOOKS, 239)
|
hook.unhook(HOOKS, 239)
|
||||||
hook("unavailresource")(mustrelease)
|
hook("unavailresource")(mustrelease)
|
||||||
hook("nicknameinuse")(mustregain)
|
hook("nicknameinuse")(mustregain)
|
||||||
|
|
||||||
|
@ -49,14 +49,12 @@ debuglog = logger("debug.log", write=False, display=False) # will be True if in
|
|||||||
errlog = logger("errors.log")
|
errlog = logger("errors.log")
|
||||||
plog = logger(None) #use this instead of print so that logs have timestamps
|
plog = logger(None) #use this instead of print so that logs have timestamps
|
||||||
|
|
||||||
COMMANDS = {}
|
|
||||||
HOOKS = {}
|
|
||||||
|
|
||||||
is_admin = var.is_admin
|
is_admin = var.is_admin
|
||||||
is_owner = var.is_owner
|
is_owner = var.is_owner
|
||||||
|
|
||||||
cmd = decorators.generate(COMMANDS)
|
cmd = decorators.cmd
|
||||||
hook = decorators.generate(HOOKS, raw_nick=True, permissions=False)
|
hook = decorators.hook
|
||||||
|
COMMANDS = decorators.COMMANDS
|
||||||
|
|
||||||
# Game Logic Begins:
|
# Game Logic Begins:
|
||||||
|
|
||||||
@ -228,7 +226,7 @@ def connect_callback(cli):
|
|||||||
notify_error(cli, botconfig.CHANNEL, errlog)
|
notify_error(cli, botconfig.CHANNEL, errlog)
|
||||||
|
|
||||||
# Unhook the WHO hooks
|
# Unhook the WHO hooks
|
||||||
decorators.unhook(HOOKS, 295)
|
hook.unhook(295)
|
||||||
|
|
||||||
|
|
||||||
#bot can be tricked into thinking it's still opped by doing multiple modes at once
|
#bot can be tricked into thinking it's still opped by doing multiple modes at once
|
||||||
@ -378,6 +376,8 @@ def pm(cli, target, message): # message either privmsg or notice, depending on
|
|||||||
|
|
||||||
cli.msg(target, message)
|
cli.msg(target, message)
|
||||||
|
|
||||||
|
decorators.pm = pm
|
||||||
|
|
||||||
def reset_settings():
|
def reset_settings():
|
||||||
var.CURRENT_GAMEMODE.teardown()
|
var.CURRENT_GAMEMODE.teardown()
|
||||||
var.CURRENT_GAMEMODE = var.GAME_MODES["default"][0]()
|
var.CURRENT_GAMEMODE = var.GAME_MODES["default"][0]()
|
||||||
@ -898,7 +898,7 @@ def join_timer_handler(cli):
|
|||||||
# I was lucky to catch this in testing, as it requires precise timing
|
# I was lucky to catch this in testing, as it requires precise timing
|
||||||
# it only failed if a join happened while this outer func had started
|
# it only failed if a join happened while this outer func had started
|
||||||
var.PINGING_IFS = False
|
var.PINGING_IFS = False
|
||||||
decorators.unhook(HOOKS, 387)
|
hook.unhook(387)
|
||||||
if to_ping:
|
if to_ping:
|
||||||
to_ping.sort(key=lambda x: x.lower())
|
to_ping.sort(key=lambda x: x.lower())
|
||||||
|
|
||||||
@ -6703,7 +6703,7 @@ def show_admins(cli, nick, chan, rest):
|
|||||||
else:
|
else:
|
||||||
cli.msg(chan, msg)
|
cli.msg(chan, msg)
|
||||||
|
|
||||||
decorators.unhook(HOOKS, 4)
|
hook.unhook(4)
|
||||||
var.ADMIN_PINGING = False
|
var.ADMIN_PINGING = False
|
||||||
|
|
||||||
if nick == chan:
|
if nick == chan:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user