Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Conversation Memory (Alpha)
import datetime
import plugins
from hangups.ui.utils import get_conv_name
convmem = {}
def _initialise(bot):
plugins.register_handler(_watch_message, type="allmessages")
plugins.register_handler(_watch_rename, type="rename")
plugins.register_handler(_watch_member, type="membership")
plugins.register_shared('convmem.removeconv', _conv_remove)
def _update_conversation_list(bot):
for conv in bot._conv_list.get_all():
_conv_update(bot, conv, source="init")
def _watch_rename(bot, event, command):
_conv_update(bot, event.conv, source="renm")
def _watch_message(bot, event, command):
_conv_update(bot, event.conv, source="chat")
def _watch_member(bot, event, command):
_conv_update(bot, event.conv, source="mmbr")
def _conv_update(bot, conv, source="unknown"):
conv_title = get_conv_name(conv)
if conv.id_ not in convmem:
convmem[conv.id_] = {}
convmem[conv.id_] = {
"title": conv_title,
"source": source,
def _conv_remove(bot, convid):
if convid in convmem:
print("convmem: removing {}".format(convid))
def _memory_save(bot):
bot.memory.set_by_path(['convmem'], convmem)
def _memory_load(bot):
if bot.memory.exists(['convmem']):
convs = bot.memory.get_by_path(['convmem'])
for convid in convs:
convmem[convid] = convs[convid]
def dumpconv(bot, event):
for convid, convdata in convmem.items():
print("{} {} {}".format(convid, convdata["source"], convdata["title"]))
print("total: {}".format(len(convmem)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.