|
|
@ -1,15 +1,20 @@ |
|
|
|
|
|
|
|
# The bot commands implemented in here are present no matter which module is loaded |
|
|
|
|
|
|
|
|
|
|
|
import botconfig |
|
|
|
import botconfig |
|
|
|
from tools import decorators |
|
|
|
from tools import decorators |
|
|
|
import logging |
|
|
|
import logging |
|
|
|
import tools.moduleloader as ld |
|
|
|
import tools.moduleloader as ld |
|
|
|
import traceback |
|
|
|
import traceback |
|
|
|
|
|
|
|
from settings import common as var |
|
|
|
|
|
|
|
|
|
|
|
def on_privmsg(cli, rawnick, chan, msg): |
|
|
|
def on_privmsg(cli, rawnick, chan, msg): |
|
|
|
currmod = ld.MODULES[ld.CURRENT_MODULE] |
|
|
|
if var.MODULE_READY: |
|
|
|
|
|
|
|
currmod = ld.MODULES[ld.CURRENT_MODULE] |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
currmod = None |
|
|
|
|
|
|
|
|
|
|
|
if chan != botconfig.NICK: #not a PM |
|
|
|
if chan != botconfig.NICK: #not a PM |
|
|
|
if "" in currmod.COMMANDS.keys(): |
|
|
|
if currmod and "" in currmod.COMMANDS.keys(): |
|
|
|
for fn in currmod.COMMANDS[""]: |
|
|
|
for fn in currmod.COMMANDS[""]: |
|
|
|
try: |
|
|
|
try: |
|
|
|
fn(cli, rawnick, chan, msg) |
|
|
|
fn(cli, rawnick, chan, msg) |
|
|
@ -20,11 +25,11 @@ def on_privmsg(cli, rawnick, chan, msg): |
|
|
|
logging.error(traceback.format_exc()) |
|
|
|
logging.error(traceback.format_exc()) |
|
|
|
cli.msg(chan, "An error has occurred and has been logged.") |
|
|
|
cli.msg(chan, "An error has occurred and has been logged.") |
|
|
|
# Now that is always called first. |
|
|
|
# Now that is always called first. |
|
|
|
for x in set(list(COMMANDS.keys()) + list(currmod.COMMANDS.keys())): |
|
|
|
for x in set(list(COMMANDS.keys()) + (list(currmod.COMMANDS.keys()) if currmod else list())): |
|
|
|
if x and msg.lower().startswith(botconfig.CMD_CHAR+x): |
|
|
|
if x and msg.lower().startswith(botconfig.CMD_CHAR+x): |
|
|
|
h = msg[len(x)+1:] |
|
|
|
h = msg[len(x)+1:] |
|
|
|
if not h or h[0] == " " or not x: |
|
|
|
if not h or h[0] == " " or not x: |
|
|
|
for fn in COMMANDS.get(x,[])+currmod.COMMANDS.get(x,[]): |
|
|
|
for fn in COMMANDS.get(x,[])+(currmod.COMMANDS.get(x,[]) if currmod else []): |
|
|
|
try: |
|
|
|
try: |
|
|
|
fn(cli, rawnick, chan, h.lstrip()) |
|
|
|
fn(cli, rawnick, chan, h.lstrip()) |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
@ -35,7 +40,7 @@ def on_privmsg(cli, rawnick, chan, msg): |
|
|
|
cli.msg(chan, "An error has occurred and has been logged.") |
|
|
|
cli.msg(chan, "An error has occurred and has been logged.") |
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
for x in set(list(PM_COMMANDS.keys()) + list(currmod.PM_COMMANDS.keys())): |
|
|
|
for x in set(list(PM_COMMANDS.keys()) + (list(currmod.PM_COMMANDS.keys()) if currmod else list())): |
|
|
|
if msg.lower().startswith(botconfig.CMD_CHAR+x): |
|
|
|
if msg.lower().startswith(botconfig.CMD_CHAR+x): |
|
|
|
h = msg[len(x)+1:] |
|
|
|
h = msg[len(x)+1:] |
|
|
|
elif not x or msg.lower().startswith(x): |
|
|
|
elif not x or msg.lower().startswith(x): |
|
|
@ -43,7 +48,7 @@ def on_privmsg(cli, rawnick, chan, msg): |
|
|
|
else: |
|
|
|
else: |
|
|
|
continue |
|
|
|
continue |
|
|
|
if not h or h[0] == " " or not x: |
|
|
|
if not h or h[0] == " " or not x: |
|
|
|
for fn in PM_COMMANDS.get(x, [])+currmod.PM_COMMANDS.get(x,[]): |
|
|
|
for fn in PM_COMMANDS.get(x, [])+(currmod.PM_COMMANDS.get(x,[]) if currmod else []): |
|
|
|
try: |
|
|
|
try: |
|
|
|
fn(cli, rawnick, h.lstrip()) |
|
|
|
fn(cli, rawnick, h.lstrip()) |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
@ -54,12 +59,16 @@ def on_privmsg(cli, rawnick, chan, msg): |
|
|
|
cli.msg(chan, "An error has occurred and has been logged.") |
|
|
|
cli.msg(chan, "An error has occurred and has been logged.") |
|
|
|
|
|
|
|
|
|
|
|
def __unhandled__(cli, prefix, cmd, *args): |
|
|
|
def __unhandled__(cli, prefix, cmd, *args): |
|
|
|
currmod = ld.MODULES[ld.CURRENT_MODULE] |
|
|
|
if var.MODULE_READY: |
|
|
|
if cmd in set(list(HOOKS.keys())+list(currmod.HOOKS.keys())): |
|
|
|
currmod = ld.MODULES[ld.CURRENT_MODULE] |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
currmod = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if cmd in set(list(HOOKS.keys())+(list(currmod.HOOKS.keys()) if currmod else list())): |
|
|
|
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, [])+currmod.HOOKS.get(cmd, []): |
|
|
|
for fn in HOOKS.get(cmd, [])+(currmod.HOOKS.get(cmd, []) if currmod else []): |
|
|
|
try: |
|
|
|
try: |
|
|
|
fn(cli, prefix, *largs) |
|
|
|
fn(cli, prefix, *largs) |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
@ -84,7 +93,13 @@ hook = decorators.generate(HOOKS, raw_nick=True, permissions=False) |
|
|
|
|
|
|
|
|
|
|
|
def connect_callback(cli): |
|
|
|
def connect_callback(cli): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
identified = False |
|
|
|
|
|
|
|
need_ghost = False |
|
|
|
|
|
|
|
|
|
|
|
def prepare_stuff(*args): |
|
|
|
def prepare_stuff(*args): |
|
|
|
|
|
|
|
if var.MODULE_READY: |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
cli.join(botconfig.CHANNEL) |
|
|
|
cli.join(botconfig.CHANNEL) |
|
|
|
cli.msg("ChanServ", "op "+botconfig.CHANNEL) |
|
|
|
cli.msg("ChanServ", "op "+botconfig.CHANNEL) |
|
|
|
|
|
|
|
|
|
|
@ -93,26 +108,68 @@ def connect_callback(cli): |
|
|
|
|
|
|
|
|
|
|
|
ld.MODULES[ld.CURRENT_MODULE].connect_callback(cli) |
|
|
|
ld.MODULES[ld.CURRENT_MODULE].connect_callback(cli) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var.MODULE_READY = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cli.nick(botconfig.NICK) # just in case |
|
|
|
|
|
|
|
|
|
|
|
if botconfig.JOIN_AFTER_CLOAKED: |
|
|
|
if botconfig.JOIN_AFTER_CLOAKED: |
|
|
|
prepare_stuff = hook("event_hosthidden", hookid=294)(prepare_stuff) |
|
|
|
prepare_stuff = hook("event_hosthidden", hookid=294)(prepare_stuff) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
prepare_stuff = hook("event_hosthidden", hookid=294)(prepare_stuff) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@hook("mode") |
|
|
|
|
|
|
|
def check_if_identified(cli, spam, egg, m, *etc): |
|
|
|
|
|
|
|
if m == "+i": |
|
|
|
|
|
|
|
identified = True |
|
|
|
|
|
|
|
|
|
|
|
@hook("nicknameinuse") |
|
|
|
@hook("nicknameinuse") |
|
|
|
def mustghost(cli, *blah): |
|
|
|
def mustghost(cli, *blah): |
|
|
|
|
|
|
|
cli.ns_identify(cli.password) |
|
|
|
cli.nick(botconfig.NICK+"_") |
|
|
|
cli.nick(botconfig.NICK+"_") |
|
|
|
cli.ns_ghost() |
|
|
|
if identified: |
|
|
|
cli.nick(botconfig.NICK) |
|
|
|
cli.ns_ghost() |
|
|
|
prepare_stuff(cli) |
|
|
|
cli.nick(botconfig.NICK) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
@hook("mode") |
|
|
|
|
|
|
|
def do_ghost(cli, spam, egg, m, *etc): |
|
|
|
|
|
|
|
if m == "+i": |
|
|
|
|
|
|
|
cli.ns_ghost() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not botconfig.JOIN_AFTER_CLOAKED: |
|
|
|
|
|
|
|
prepare_stuff(cli) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@hook("quit", hookid=232) |
|
|
|
|
|
|
|
def after_ghost(cli, nick, reason): |
|
|
|
|
|
|
|
if nick == botconfig.NICK and reason == "Disconnected by services": |
|
|
|
|
|
|
|
cli.nick(botconfig.NICK) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
decorators.unhook(HOOKS, 232) |
|
|
|
|
|
|
|
|
|
|
|
@hook("unavailresource") |
|
|
|
@hook("unavailresource") |
|
|
|
def mustrelease(cli, *blah): |
|
|
|
def mustrelease(cli, *blah): |
|
|
|
|
|
|
|
cli.ns_identify(cli.password) |
|
|
|
cli.nick(botconfig.NICK+"_") |
|
|
|
cli.nick(botconfig.NICK+"_") |
|
|
|
cli.ns_release() |
|
|
|
if identified: |
|
|
|
cli.nick(botconfig.NICK) |
|
|
|
cli.ns_release() |
|
|
|
prepare_stuff(cli) |
|
|
|
cli.nick(botconfig.NICK) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
@hook("mode") |
|
|
|
|
|
|
|
def do_release(cli, spam, egg, m, *etc): |
|
|
|
|
|
|
|
if m == "+i": |
|
|
|
|
|
|
|
cli.ns_release() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not botconfig.JOIN_AFTER_CLOAKED: |
|
|
|
|
|
|
|
prepare_stuff(cli) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@hook("notice", hookid=233) |
|
|
|
|
|
|
|
def after_release(cli, *etc): #hopefully this works |
|
|
|
|
|
|
|
cli.nick(botconfig.NICK) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
decorators.unhook(HOOKS, 233) |
|
|
|
|
|
|
|
|
|
|
|
if not botconfig.JOIN_AFTER_CLOAKED: # join immediately |
|
|
|
if not botconfig.JOIN_AFTER_CLOAKED: # join immediately |
|
|
|
prepare_stuff(cli) |
|
|
|
pass |
|
|
|
|
|
|
|
# prepare_stuff(cli) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|