Merge pull request #46 from rmoore/master

Make .seen persistent.
master
mutantmonkey 2013-01-01 12:33:30 -08:00
commit de05bb732e
1 changed files with 5 additions and 9 deletions

View File

@ -7,13 +7,12 @@ Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/ http://inamidst.com/phenny/
""" """
import time import time, os, shelve
from tools import deprecated from tools import deprecated
@deprecated @deprecated
def f_seen(self, origin, match, args): def f_seen(self, origin, match, args):
""".seen <nick> - Reports when <nick> was last seen.""" """.seen <nick> - Reports when <nick> was last seen."""
if origin.sender == '#talis': return
nick = match.group(2).lower() nick = match.group(2).lower()
if not hasattr(self, 'seen'): if not hasattr(self, 'seen'):
return self.msg(origin.sender, '?') return self.msg(origin.sender, '?')
@ -30,15 +29,12 @@ f_seen.rule = (['seen'], r'(\S+)')
def f_note(self, origin, match, args): def f_note(self, origin, match, args):
def note(self, origin, match, args): def note(self, origin, match, args):
if not hasattr(self.bot, 'seen'): if not hasattr(self.bot, 'seen'):
self.bot.seen = {} fn = self.nick + '-' + self.config.host + '.seen.db'
path = os.path.join(os.path.expanduser('~/.phenny'), fn)
self.bot.seen = shelve.open(path)
if origin.sender.startswith('#'): if origin.sender.startswith('#'):
# if origin.sender == '#inamidst': return
self.seen[origin.nick.lower()] = (origin.sender, time.time()) self.seen[origin.nick.lower()] = (origin.sender, time.time())
self.seen.sync()
# if not hasattr(self, 'chanspeak'):
# self.chanspeak = {}
# if (len(args) > 2) and args[2].startswith('#'):
# self.chanspeak[args[2]] = args[0]
try: note(self, origin, match, args) try: note(self, origin, match, args)
except Exception as e: print(e) except Exception as e: print(e)