File size: 1,114 Bytes
097caae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
from dotenv import load_dotenv
import configparser
class HistoryManager:
def __init__(self):
#Loading env variables
try:
load_dotenv()
except:
print("No .env file")
#Loading config file
self.config=configparser.ConfigParser()
self.config.read("config.ini")
self.chat_history = {}
def add_message(self, chat_id, sender, message):
if chat_id not in self.chat_history:
self.chat_history[chat_id] = []
self.chat_history[chat_id].append((sender, message))
def get_messages(self, chat_id):
return self.chat_history.get(chat_id, [])
def clear_chat(self, chat_id):
if chat_id in self.chat_history:
del self.chat_history[chat_id]
def format_chat(self, chat_id):
formatted_chat = ""
messages = self.get_messages(chat_id)
for sender, message in messages:
formatted_chat += f"{sender} message= {message}\n"
return formatted_chat
def chat_exists(self, chat_id):
return chat_id in self.chat_history |