diff --git a/tipbot/irc.py b/tipbot/ircutils.py similarity index 98% rename from tipbot/irc.py rename to tipbot/ircutils.py index 95ed996..55471ef 100644 --- a/tipbot/irc.py +++ b/tipbot/ircutils.py @@ -32,6 +32,7 @@ current_send_delay = irc_min_send_delay irc_network = None irc_port = None irc_name = None +irc_quitting = False userstable=dict() registered_users=set() @@ -115,6 +116,11 @@ def Join(chan): def Part(chan): SendIRC ( 'PART ' + chan) +def Quit(msg): + global irc_quitting + irc_quitting = True + SendIRC ( 'QUIT%s' % msg) + def Who(chan): userstable[chan] = dict() SendIRC ( 'WHO ' + chan) @@ -280,6 +286,9 @@ def IRCLoop(on_idle,on_identified,on_command): continue if data.find('ERROR :Closing Link:') == 0: + if irc_quitting: + log_info('IRC stopped, bye') + break log_warn('We were kicked from IRC, reconnecting in 5 seconds') time.sleep(5) last_ping_time = time.time() diff --git a/tipbot/modules/irc.py b/tipbot/modules/irc.py index edc19e6..5e0a1db 100644 --- a/tipbot/modules/irc.py +++ b/tipbot/modules/irc.py @@ -39,6 +39,11 @@ def PartChannel(nick,chan,cmd): pchan = chan Part(pchan) +def QuitIRC(nick,chan,cmd): + msg = "" + for w in cmd[:1]: + msg = msg + " " + w + Quit(msg) RegisterCommand({ 'module': __name__, @@ -56,3 +61,10 @@ RegisterCommand({ 'admin': True, 'help': "Makes %s part from a channel" % (config.tipbot_name) }) +RegisterCommand({ + 'module': __name__, + 'name': 'quit', + 'function': QuitIRC, + 'admin': True, + 'help': "Makes %s quit IRC" % (config.tipbot_name) +})