|
from dotenv import load_dotenv |
|
import configparser |
|
|
|
class HistoryManager: |
|
|
|
def __init__(self): |
|
|
|
|
|
try: |
|
load_dotenv() |
|
except: |
|
print("No .env 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 |