sasl authentication, improved bot regain/release behavior, botconfig.py updated!
This commit is contained in:
parent
4a959597a7
commit
e02402d77e
@ -7,7 +7,7 @@ NICK = "mywolfbot"
|
|||||||
CMD_CHAR = "!"
|
CMD_CHAR = "!"
|
||||||
CHANGING_HOST_QUIT_MESSAGE = "Changing host"
|
CHANGING_HOST_QUIT_MESSAGE = "Changing host"
|
||||||
|
|
||||||
JOIN_AFTER_CLOAKED = True # Set to false if the bot does not have a cloak
|
SASL_AUTHENTICATION = False # put account name in USERNAME ^ if different from nick
|
||||||
DISABLE_DEBUG_MODE = False # Entirely disable debug mode
|
DISABLE_DEBUG_MODE = False # Entirely disable debug mode
|
||||||
IGNORE_HIDDEN_COMMANDS = True # Ignore commands sent to @#channel or +#channel
|
IGNORE_HIDDEN_COMMANDS = True # Ignore commands sent to @#channel or +#channel
|
||||||
ALLOW_NOTICE_COMMANDS = False # allow /notice #channel !command to be interpreted as a command
|
ALLOW_NOTICE_COMMANDS = False # allow /notice #channel !command to be interpreted as a command
|
||||||
|
@ -6,6 +6,7 @@ import logging
|
|||||||
import tools.moduleloader as ld
|
import tools.moduleloader as ld
|
||||||
import traceback
|
import traceback
|
||||||
from settings import common as var
|
from settings import common as var
|
||||||
|
from base64 import b64encode
|
||||||
|
|
||||||
def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
||||||
currmod = ld.MODULES[ld.CURRENT_MODULE]
|
currmod = ld.MODULES[ld.CURRENT_MODULE]
|
||||||
@ -94,9 +95,6 @@ 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):
|
||||||
cli.join(botconfig.CHANNEL)
|
cli.join(botconfig.CHANNEL)
|
||||||
cli.msg("ChanServ", "op "+botconfig.CHANNEL)
|
cli.msg("ChanServ", "op "+botconfig.CHANNEL)
|
||||||
@ -106,66 +104,55 @@ def connect_callback(cli):
|
|||||||
|
|
||||||
ld.MODULES[ld.CURRENT_MODULE].connect_callback(cli)
|
ld.MODULES[ld.CURRENT_MODULE].connect_callback(cli)
|
||||||
|
|
||||||
cli.nick(botconfig.NICK) # just in case
|
cli.nick(botconfig.NICK) # very important (for regain/release)
|
||||||
|
|
||||||
if botconfig.JOIN_AFTER_CLOAKED:
|
prepare_stuff = hook("endofmotd", hookid=294)(prepare_stuff)
|
||||||
prepare_stuff = hook("event_hosthidden", hookid=294)(prepare_stuff)
|
|
||||||
else:
|
|
||||||
prepare_stuff = hook("endofmotd", hookid=294)(prepare_stuff)
|
|
||||||
|
|
||||||
@hook("mode")
|
def mustregain(cli, *blah):
|
||||||
def check_if_identified(cli, spam, egg, m, *etc):
|
cli.ns_regain()
|
||||||
if m == "+i":
|
|
||||||
identified = True
|
|
||||||
|
|
||||||
@hook("nicknameinuse")
|
def mustrelease(cli, *rest):
|
||||||
def mustghost(cli, *blah):
|
cli.ns_release()
|
||||||
cli.ns_identify(cli.password)
|
cli.nick(botconfig.NICK)
|
||||||
|
|
||||||
|
@hook("unavailresource", hookid=239)
|
||||||
|
@hook("nicknameinuse", hookid=239)
|
||||||
|
def must_use_temp_nick(cli, *etc):
|
||||||
cli.nick(botconfig.NICK+"_")
|
cli.nick(botconfig.NICK+"_")
|
||||||
if identified:
|
cli.user(botconfig.NICK, "")
|
||||||
cli.ns_ghost()
|
|
||||||
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:
|
decorators.unhook(HOOKS, 239)
|
||||||
prepare_stuff(cli)
|
hook("unavailresource")(mustrelease)
|
||||||
|
hook("nicknameinuse")(mustregain)
|
||||||
|
|
||||||
@hook("quit", hookid=232)
|
if botconfig.SASL_AUTHENTICATION:
|
||||||
def after_ghost(cli, nick, reason):
|
|
||||||
if nick == botconfig.NICK and reason == "Disconnected by services":
|
|
||||||
cli.nick(botconfig.NICK)
|
|
||||||
|
|
||||||
decorators.unhook(HOOKS, 232)
|
@hook("authenticate")
|
||||||
|
def auth_plus(cli, something, plus):
|
||||||
|
if plus == "+":
|
||||||
|
nick_b = bytes(botconfig.USERNAME if botconfig.USERNAME else botconfig.NICK, "utf-8")
|
||||||
|
pass_b = bytes(botconfig.PASS, "utf-8")
|
||||||
|
secrt_msg = b'\0'.join((nick_b, nick_b, pass_b))
|
||||||
|
print(secrt_msg)
|
||||||
|
cli.send("AUTHENTICATE " + b64encode(secrt_msg).decode("utf-8"))
|
||||||
|
|
||||||
@hook("unavailresource")
|
@hook("cap")
|
||||||
def mustrelease(cli, *blah):
|
def on_cap(cli, svr, mynick, ack, cap):
|
||||||
cli.ns_identify(cli.password)
|
if ack.upper() == "ACK" and "sasl" in cap:
|
||||||
cli.nick(botconfig.NICK+"_")
|
cli.send("AUTHENTICATE PLAIN")
|
||||||
if identified:
|
|
||||||
cli.ns_release()
|
|
||||||
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:
|
@hook("903")
|
||||||
prepare_stuff(cli)
|
def on_successful_auth(cli, blah, blahh, blahhh):
|
||||||
|
cli.cap("END")
|
||||||
|
|
||||||
@hook("notice", hookid=233)
|
@hook("904")
|
||||||
def after_release(cli, *etc): #hopefully this works
|
@hook("905")
|
||||||
cli.nick(botconfig.NICK)
|
@hook("906")
|
||||||
|
@hook("907")
|
||||||
decorators.unhook(HOOKS, 233)
|
def on_failure_auth(cli, *etc):
|
||||||
|
cli.quit()
|
||||||
if not botconfig.JOIN_AFTER_CLOAKED: # join immediately
|
print("Authentication failed. Did you fill the account name "+
|
||||||
pass
|
"in botconfig.USERNAME if it's different from the bot nick?")
|
||||||
# prepare_stuff(cli)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ def connect_callback(cli):
|
|||||||
cmodes.append(("-q", quieted))
|
cmodes.append(("-q", quieted))
|
||||||
|
|
||||||
@hook("mode", hookid=294)
|
@hook("mode", hookid=294)
|
||||||
def on_give_me_ops(cli, blah, blahh, modeaction, target):
|
def on_give_me_ops(cli, blah, blahh, modeaction, target=""):
|
||||||
if modeaction == "+o" and target == botconfig.NICK and var.PHASE == "none":
|
if modeaction == "+o" and target == botconfig.NICK and var.PHASE == "none":
|
||||||
decorators.unhook(HOOKS, 294)
|
decorators.unhook(HOOKS, 294)
|
||||||
mass_mode(cli, cmodes)
|
mass_mode(cli, cmodes)
|
||||||
@ -357,7 +357,7 @@ def join(cli, nick, chann_, rest):
|
|||||||
|
|
||||||
if var.PHASE == "none":
|
if var.PHASE == "none":
|
||||||
|
|
||||||
cli.mode(chan, "+v", nick, nick+"!*@*")
|
cli.mode(chan, "+v", nick)
|
||||||
var.ROLES["person"].append(nick)
|
var.ROLES["person"].append(nick)
|
||||||
var.PHASE = "join"
|
var.PHASE = "join"
|
||||||
var.WAITED = 0
|
var.WAITED = 0
|
||||||
@ -374,7 +374,7 @@ def join(cli, nick, chann_, rest):
|
|||||||
cli.notice(nick, "Sorry but the game is already running. Try again next time.")
|
cli.notice(nick, "Sorry but the game is already running. Try again next time.")
|
||||||
else:
|
else:
|
||||||
|
|
||||||
cli.mode(chan, "+v", nick, nick+"!*@*")
|
cli.mode(chan, "+v", nick)
|
||||||
var.ROLES["person"].append(nick)
|
var.ROLES["person"].append(nick)
|
||||||
cli.msg(chan, '\u0002{0}\u0002 has joined the game.'.format(nick))
|
cli.msg(chan, '\u0002{0}\u0002 has joined the game.'.format(nick))
|
||||||
|
|
||||||
|
@ -107,6 +107,7 @@ class IRCClient(object):
|
|||||||
self.authname = ""
|
self.authname = ""
|
||||||
self.connect_cb = None
|
self.connect_cb = None
|
||||||
self.blocking = True
|
self.blocking = True
|
||||||
|
self.sasl_auth = False
|
||||||
self.lock = threading.RLock()
|
self.lock = threading.RLock()
|
||||||
|
|
||||||
self.tokenbucket = TokenBucket(23, 1.73)
|
self.tokenbucket = TokenBucket(23, 1.73)
|
||||||
@ -147,7 +148,7 @@ class IRCClient(object):
|
|||||||
for arg in args]), i))
|
for arg in args]), i))
|
||||||
|
|
||||||
msg = bytes(" ", "utf_8").join(bargs)
|
msg = bytes(" ", "utf_8").join(bargs)
|
||||||
logging.info('---> send "{0}"'.format(msg))
|
logging.info('---> send {0}'.format(str(msg)[1:]))
|
||||||
|
|
||||||
while not self.tokenbucket.consume(1):
|
while not self.tokenbucket.consume(1):
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
@ -178,12 +179,19 @@ class IRCClient(object):
|
|||||||
if not self.blocking:
|
if not self.blocking:
|
||||||
self.socket.setblocking(0)
|
self.socket.setblocking(0)
|
||||||
|
|
||||||
self.send("PASS {0}:{1}".format(self.authname if self.authname else self.nickname,
|
if not self.sasl_auth:
|
||||||
self.password if self.password else "NOPASS"))
|
self.send("PASS {0}:{1}".format(self.authname if self.authname else self.nickname,
|
||||||
|
self.password if self.password else "NOPASS"))
|
||||||
|
else:
|
||||||
|
self.cap("LS")
|
||||||
|
|
||||||
self.nick(self.nickname)
|
self.nick(self.nickname)
|
||||||
self.user(self.nickname, self.real_name)
|
self.user(self.nickname, self.real_name)
|
||||||
|
|
||||||
|
if self.sasl_auth:
|
||||||
|
self.cap("REQ", "multi-prefix")
|
||||||
|
self.cap("REQ", "sasl")
|
||||||
|
|
||||||
if self.connect_cb:
|
if self.connect_cb:
|
||||||
try:
|
try:
|
||||||
self.connect_cb(self)
|
self.connect_cb(self)
|
||||||
@ -268,6 +276,8 @@ class IRCClient(object):
|
|||||||
self.msg("NickServ", "GHOST "+self.nickname)
|
self.msg("NickServ", "GHOST "+self.nickname)
|
||||||
def ns_release(self):
|
def ns_release(self):
|
||||||
self.msg("NickServ", "RELEASE "+self.nickname)
|
self.msg("NickServ", "RELEASE "+self.nickname)
|
||||||
|
def ns_regain(self):
|
||||||
|
self.msg("NickServ", "REGAIN "+self.nickname)
|
||||||
def user(self, uname, rname):
|
def user(self, uname, rname):
|
||||||
self.send("USER", uname, self.host, self.host,
|
self.send("USER", uname, self.host, self.host,
|
||||||
rname or uname)
|
rname or uname)
|
||||||
|
@ -51,6 +51,7 @@ def main():
|
|||||||
authname=botconfig.USERNAME,
|
authname=botconfig.USERNAME,
|
||||||
password=botconfig.PASS,
|
password=botconfig.PASS,
|
||||||
nickname=botconfig.NICK,
|
nickname=botconfig.NICK,
|
||||||
|
sasl_auth=botconfig.SASL_AUTHENTICATION,
|
||||||
connect_cb=modules.common.connect_callback
|
connect_cb=modules.common.connect_callback
|
||||||
)
|
)
|
||||||
cli.mainLoop()
|
cli.mainLoop()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user