From 94edcff5c6a0c680c6511f091e7c73a00fc1c450 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Wed, 19 Mar 2014 17:27:36 +1300 Subject: [PATCH 1/2] Delete religion.py --- disabled_stuff/religion.py | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 disabled_stuff/religion.py diff --git a/disabled_stuff/religion.py b/disabled_stuff/religion.py deleted file mode 100644 index 552b23f..0000000 --- a/disabled_stuff/religion.py +++ /dev/null @@ -1,38 +0,0 @@ -from util import hook, http - - -@hook.command('god') -@hook.command -def bible(inp): - """.bible -- gets from the Bible (ESV)""" - - base_url = ('http://www.esvapi.org/v2/rest/passageQuery?key=IP&' - 'output-format=plain-text&include-heading-horizontal-lines&' - 'include-headings=false&include-passage-horizontal-lines=false&' - 'include-passage-references=false&include-short-copyright=false&' - 'include-footnotes=false&line-length=0&' - 'include-heading-horizontal-lines=false') - - text = http.get(base_url, passage=inp) - - text = ' '.join(text.split()) - - if len(text) > 400: - text = text[:text.rfind(' ', 0, 400)] + '...' - - return text - - -@hook.command('allah') -@hook.command -def koran(inp): # Koran look-up plugin by Ghetto Wizard - """.koran -- gets from the Koran""" - - url = 'http://quod.lib.umich.edu/cgi/k/koran/koran-idx?type=simple' - - results = http.get_html(url, q1=inp).xpath('//li') - - if not results: - return 'No results for ' + inp - - return results[0].text_content() From 0a774ee9bc28c6f8dc12f0ab6d245f2e7ceea211 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Wed, 19 Mar 2014 19:40:52 +1300 Subject: [PATCH 2/2] split self-tracking to new plugin --- plugins/core_misc.py | 22 ---------------------- plugins/core_tracker.py | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 22 deletions(-) create mode 100644 plugins/core_tracker.py diff --git a/plugins/core_misc.py b/plugins/core_misc.py index 06c72b7..9507016 100644 --- a/plugins/core_misc.py +++ b/plugins/core_misc.py @@ -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): diff --git a/plugins/core_tracker.py b/plugins/core_tracker.py new file mode 100644 index 0000000..d02a65e --- /dev/null +++ b/plugins/core_tracker.py @@ -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))