split self-tracking to new plugin

This commit is contained in:
Luke Rogers 2014-03-19 19:40:52 +13:00
parent 94edcff5c6
commit 0a774ee9bc
2 changed files with 27 additions and 22 deletions

View File

@ -7,9 +7,6 @@ from util import hook
socket.setdefaulttimeout(10)
nick_re = re.compile(":(.+?)!")
# Auto-join on Invite (Configurable, defaults to True)
@hook.event('INVITE')
def invite(paraml, conn=None):
@ -53,25 +50,6 @@ def onjoin(paraml, conn=None, bot=None):
bot.logger.info("ONJOIN hook completed. Bot ready.")
@hook.event("KICK")
def onkick(paraml, conn=None, chan=None):
# if the bot has been kicked, remove from the channel list
if paraml[1] == conn.nick:
conn.channels.remove(chan)
auto_rejoin = conn.config.get('auto_rejoin', False)
if auto_rejoin:
conn.join(paraml[0])
@hook.event("NICK")
def onnick(paraml, bot=None, conn=None, raw=None):
old_nick = nick_re.search(raw).group(1)
new_nick = str(paraml[0])
if old_nick == conn.nick:
conn.nick = new_nick
bot.logger.info("Bot nick changed from '{}' to '{}'.".format(old_nick, new_nick))
@hook.singlethread
@hook.event('004')
def keep_alive(paraml, conn=None):

27
plugins/core_tracker.py Normal file
View File

@ -0,0 +1,27 @@
# plugin to keep track of bot state
import re
from util import hook
nick_re = re.compile(":(.+?)!")
@hook.event("KICK")
def on_kick(paraml, conn=None, chan=None):
# if the bot has been kicked, remove from the channel list
if paraml[1] == conn.nick:
conn.channels.remove(chan)
auto_rejoin = conn.config.get('auto_rejoin', False)
if auto_rejoin:
conn.join(paraml[0])
@hook.event("NICK")
def on_nick(paraml, bot=None, conn=None, raw=None):
old_nick = nick_re.search(raw).group(1)
new_nick = str(paraml[0])
if old_nick == conn.nick:
conn.nick = new_nick
bot.logger.info("Bot nick changed from '{}' to '{}'.".format(old_nick, new_nick))