|
@ -2,11 +2,12 @@ import os |
|
|
import matrix_pygmalion_bot.translate as translate |
|
|
import matrix_pygmalion_bot.translate as translate |
|
|
|
|
|
|
|
|
class ChatMessage: |
|
|
class ChatMessage: |
|
|
def __init__(self, event_id, timestamp, user_name, is_own_message, relates_to_event, message, language="en", english_original_message=None): |
|
|
def __init__(self, event_id, timestamp, user_name, is_own_message, is_command, relates_to_event, message, language="en", english_original_message=None): |
|
|
self.event_id = event_id |
|
|
self.event_id = event_id |
|
|
self.timestamp = timestamp |
|
|
self.timestamp = timestamp |
|
|
self.user_name = user_name |
|
|
self.user_name = user_name |
|
|
self.is_own_message = is_own_message |
|
|
self.is_own_message = is_own_message |
|
|
|
|
|
self.is_command = is_command |
|
|
self.relates_to_event = relates_to_event |
|
|
self.relates_to_event = relates_to_event |
|
|
self.num_tokens = None |
|
|
self.num_tokens = None |
|
|
self.message = {} |
|
|
self.message = {} |
|
@ -18,6 +19,7 @@ class ChatMessage: |
|
|
self.message["en"] = translate.translate(message, language, "en") |
|
|
self.message["en"] = translate.translate(message, language, "en") |
|
|
self.language = language |
|
|
self.language = language |
|
|
self.num_tokens = None |
|
|
self.num_tokens = None |
|
|
|
|
|
|
|
|
def __str__(self): |
|
|
def __str__(self): |
|
|
return str("{}: {}".format(self.user_name, self.message[self.language])) |
|
|
return str("{}: {}".format(self.user_name, self.message[self.language])) |
|
|
def getTranslation(self, to_lang): |
|
|
def getTranslation(self, to_lang): |
|
@ -43,15 +45,15 @@ class ChatHistory: |
|
|
for i in range(num_items): |
|
|
for i in range(num_items): |
|
|
event_id, item = self.chat_history.popitem() |
|
|
event_id, item = self.chat_history.popitem() |
|
|
return item |
|
|
return item |
|
|
def add(self, event_id, timestamp, user_name, is_own_message, relates_to_event, message, language="en", english_original_message=None): |
|
|
def add(self, event_id, timestamp, user_name, is_own_message, is_command, relates_to_event, message, language="en", english_original_message=None): |
|
|
chat_message = ChatMessage(event_id, timestamp, user_name, is_own_message, relates_to_event, message, language, english_original_message) |
|
|
chat_message = ChatMessage(event_id, timestamp, user_name, is_own_message, is_command, relates_to_event, message, language, english_original_message) |
|
|
self.chat_history[chat_message.event_id] = chat_message |
|
|
self.chat_history[chat_message.event_id] = chat_message |
|
|
os.makedirs("./chatlogs", exist_ok=True) |
|
|
os.makedirs("./chatlogs", exist_ok=True) |
|
|
with open("chatlogs/" + self.bot_name + "_" + self.room_name + ".txt", "a") as f: |
|
|
with open("chatlogs/" + self.bot_name + "_" + self.room_name + ".txt", "a") as f: |
|
|
f.write("{}: {}\n".format(user_name, message)) |
|
|
f.write("{}: {}\n".format(user_name, message)) |
|
|
return chat_message |
|
|
return chat_message |
|
|
def getLastItem(self): |
|
|
def getLastItem(self): |
|
|
key, chat_item = reversed(self.chat_history.items())[0] |
|
|
key, chat_item = list(self.chat_history.items())[-1] |
|
|
return chat_item |
|
|
return chat_item |
|
|
|
|
|
|
|
|
class BotChatHistory: |
|
|
class BotChatHistory: |
|
|