Added an append feature to .remember

This commit is contained in:
Parker Smith 2011-03-16 15:04:37 +08:00 committed by rmmh
parent f3b26969f8
commit 154f457f3a
1 changed files with 17 additions and 3 deletions

View File

@ -22,21 +22,35 @@ def get_memory(db, chan, word):
@hook.command
def remember(inp, nick='', chan='', db=None):
".remember <word> <data> -- maps word to data in the memory"
".remember <word> [+]<data> -- maps word to data in the memory"
db_init(db)
append = False
try:
head, tail = inp.split(None, 1)
except ValueError:
return remember.__doc__
data = get_memory(db, chan, head)
if tail[0] == '+' and len(tail) > 1:
append = True
# ignore + symbol
new = tail[1:]
# data is stored with the input so ignore it when re-adding it
tail = data.replace('"', "''")[2:] + ' ' + new
db.execute("replace into memory(chan, word, data, nick) values"
" (?,lower(?),?,?)", (chan, head, head + ' ' + tail, nick))
db.commit()
if data:
return 'forgetting "%s", remembering this instead.' % \
data.replace('"', "''")
if append:
return "appending %s to %s" % (new, data.replace('"', "''")[2:])
else:
return 'forgetting "%s", remembering this instead.' % \
data.replace('"', "''")
else:
return 'done.'