make log append work, make bot respond to PMs, other minor cleanups
This commit is contained in:
parent
e46e42d4b9
commit
94d9fd22f0
7
bot.py
7
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)
|
||||
|
|
|
@ -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:
|
||||
|
|
2
irc.py
2
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <word> <data> -- 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')
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
remember.py: written by Scaevolus 2009
|
||||
"""
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/python
|
||||
"weather, thanks to google"
|
||||
|
||||
from __future__ import with_statement
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/python
|
||||
'''Searches wikipedia and returns first sentence of article
|
||||
Scaevolus 2009'''
|
||||
|
||||
|
|
Loading…
Reference in New Issue