def update(self, conv, source="unknown", automatic_save=True): conv_title = hangups_get_conv_name(conv) if conv.id_ not in self.catalog: self.catalog[conv.id_] = {} """base information""" self.catalog[conv.id_] = { "title": conv_title, "source": source, "users" : [], # uninitialised "updated": datetime.datetime.now().strftime("%Y%m%d%H%M%S")} """store the user list""" self.catalog[conv.id_]["users"] = [[[user.id_.chat_id, user.id_.gaia_id], user.full_name ] for user in conv.users if not user.is_self] """store the conversation type: GROUP, ONE_TO_ONE""" if conv._conversation.type_ == hangups.schemas.ConversationType.GROUP: self.catalog[conv.id_]["type"] = "GROUP" else: # conv._conversation.type_ == hangups.schemas.ConversationType.STICKY_ONE_TO_ONE self.catalog[conv.id_]["type"] = "ONE_TO_ONE" if automatic_save: self.save_to_memory() logging.info("conversation_memory(): updated {} {}".format(conv.id_, conv_title))
def _conv_update(bot, conv, source="unknown"): conv_title = hangups_get_conv_name(conv) if conv.id_ not in convmem: convmem[conv.id_] = {} convmem[conv.id_] = { "title": conv_title, "source": source, "users" : [], # uninitialised "updated": datetime.datetime.now().strftime("%Y%m%d%H%M%S")} convmem[conv.id_]["users"] = [[ user.id_, user.full_name ] for user in conv.users if not user.is_self] # expensive to store _memory_save(bot)
def get_name(self, conv, truncate=False): """drop-in replacement for hangups.ui.utils.get_conv_name truncate added for backward-compatibility, should be always False """ if isinstance(conv, str): convid = conv else: convid = conv.id_ try: convdata = self.catalog[convid] title = convdata["title"] except (KeyError, AttributeError) as e: if not isinstance(conv, str): title = hangups_get_conv_name(conv, truncate=False) else: raise ValueError("could not determine conversation name") return title