diff --git a/bot.py b/bot.py index 6045376..0e43dca 100755 --- a/bot.py +++ b/bot.py @@ -92,7 +92,10 @@ class Input(object): self.paraml = paraml self.msg = msg if command == "PRIVMSG": - self.chan = paraml[0] + if paraml[0] != bot.nick: + self.chan = paraml[0] + else: + self.chan = nick else: self.chan = "" @@ -110,7 +113,7 @@ class FakeBot(object): self.chan = input.chan def say(self, msg): - self.bot.irc.msg(self.input.paraml[0], msg) + self.bot.irc.msg(self.chan, msg) def reply(self, msg): self.say(self.input.nick + ': ' + msg) diff --git a/core/sieve.py b/core/sieve.py index 0735d02..47d7381 100644 --- a/core/sieve.py +++ b/core/sieve.py @@ -16,10 +16,7 @@ def sieve_suite(bot, input, func, args): args.setdefault('prefix', True) if args.get('prefix', True): - hook = r'^(?:[.!]|' + bot.nick +r'[:,]*\s*)' + hook - - if input.command == 'INVITE': - print func, hook + hook = (r'^(?:[.!]|' if input.chan != input.nick else r'^(?:[.!]?|') + bot.nick +r'[:,]*\s*)' + hook input.re = re.match(hook, input.msg, flags=re.I) if input.re is None: diff --git a/irc.py b/irc.py index a5af647..27d19ee 100644 --- a/irc.py +++ b/irc.py @@ -8,7 +8,7 @@ import Queue queue = Queue.Queue -def decode(txt, codecs=['utf-8', 'iso-8859-1', 'shift_jis', 'cp1252']): +def decode(txt): for codec in ('utf-8', 'iso-8859-1', 'shift_jis', 'cp1252'): try: return txt.decode(codec) diff --git a/plugins/dice.py b/plugins/dice.py old mode 100755 new mode 100644 index 9cd2aa0..9e9cedd --- a/plugins/dice.py +++ b/plugins/dice.py @@ -1,6 +1,5 @@ -#!/usr/bin/env python """ -dice.py written by Scaevolus 2008, updated 2009 +dice.py: written by Scaevolus 2008, updated 2009 simulates dicerolls """ import re diff --git a/plugins/log.py b/plugins/log.py index 1a56220..a9bfa46 100644 --- a/plugins/log.py +++ b/plugins/log.py @@ -18,26 +18,11 @@ timestamp_format = '%H:%M:%S' def get_log_filename(dir, network, chan): return os.path.join(dir, 'log', gmtime('%Y'), network, - gmtime('%%s.%m-%d.log') % chan) + gmtime('%%s.%m-%d.log') % chan).lower() def gmtime(format): return time.strftime(format, time.gmtime()) -def load_memory(filename, mtimes={}): - if not os.path.exists(filename): - return {} - mtime = os.stat(filename).st_mtime - if mtimes.get(filename, 0) != mtime: - mtimes[filename] = mtime - return dict((x.split(None, 1)[0].lower(), x.strip()) for x in - codecs.open(filename, 'r', 'utf-8')) - -def save_memory(filename, memory): - out = codecs.open(filename, 'w', 'utf-8') - out.write('\n'.join(sorted(memory.itervalues()))) - out.flush() - out.close() - def get_log_fd(dir, network, chan): fn = get_log_filename(dir, network, chan) cache_key = '%s %s' % (network, chan) @@ -50,7 +35,7 @@ def get_log_fd(dir, network, chan): dir = os.path.split(fn)[0] if not os.path.exists(dir): os.makedirs(dir) - fd = codecs.open(fn, 'wab', 'utf-8') + fd = codecs.open(fn, 'a', 'utf-8') log_fds[cache_key] = (fn, fd) return fd @@ -59,10 +44,9 @@ def get_log_fd(dir, network, chan): def log(bot, input): ".remember -- maps word to data in the memory" with lock: - fd = get_log_fd(bot.persist_dir, bot.network, 'RAW') + fd = get_log_fd(bot.persist_dir, bot.network, 'raw') fd.write(gmtime(timestamp_format) + ' ' + input.raw + '\n') if input.chan: fd = get_log_fd(bot.persist_dir, bot.network, input.chan) fd.write(gmtime(timestamp_format) + ' ' + input.raw + '\n') - diff --git a/plugins/remember.py b/plugins/remember.py index 0319a8d..6a2846c 100644 --- a/plugins/remember.py +++ b/plugins/remember.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python """ remember.py: written by Scaevolus 2009 """ diff --git a/plugins/weather.py b/plugins/weather.py old mode 100755 new mode 100644 index 2570934..1f668f7 --- a/plugins/weather.py +++ b/plugins/weather.py @@ -1,4 +1,3 @@ -#!/usr/bin/python "weather, thanks to google" from __future__ import with_statement diff --git a/plugins/wikipedia.py b/plugins/wikipedia.py index 6c4567f..cdc8a53 100644 --- a/plugins/wikipedia.py +++ b/plugins/wikipedia.py @@ -1,4 +1,3 @@ -#!/usr/bin/python '''Searches wikipedia and returns first sentence of article Scaevolus 2009'''