diff --git a/requirements.txt b/requirements.txt index 29ab8a3..3bc6ce7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ -aiogram==2.25.1 +aiogram==3.1.1 openai==0.27.8 +PyYAML==6.0.1 diff --git a/src/config.yaml b/src/config.yaml new file mode 100644 index 0000000..3392efe --- /dev/null +++ b/src/config.yaml @@ -0,0 +1,23 @@ +TELEGRAM: + TOKEN: 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 + PRIVATE_ANSWER: + +BOT: + ANSWER: + HELP_ANSWER: + START_ANSWER: + ABOUT_ANSWER: + +ROLES: + ADMIN: + MODERATOR: + USER: + DEFAULT_FOR_ADMIN: + +DATABASE: + MESSAGE_LIMIT: + +GPT_MODULE: + TRIGGER_FRONT: + TRIGGER_ALL: + REPLY_IGNORE: diff --git a/src/config.json b/src/modules/AdminChat.py similarity index 100% rename from src/config.json rename to src/modules/AdminChat.py diff --git a/src/modules/Config.py b/src/modules/Config.py new file mode 100644 index 0000000..99e2c70 --- /dev/null +++ b/src/modules/Config.py @@ -0,0 +1,21 @@ +import os + +from yaml import load, Loader + + +class Config: + def __init__(self): + self.bot_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.getcwd()))) + self.config_dir = os.path.join(self.bot_dir, 'config.yaml') + + def get_config(self): + return load(open(self.config_dir), Loader=Loader) + + def get_bot_token(self): + return self.get_config()['BOT']['TOKEN'] + + def get_roles(self): + return self.get_config()['ROLES'] + + def get_bot_answers(self): + return self.get_config()['BOT']['ANSWER'] diff --git a/src/modules/DataBase.py b/src/modules/DataBase.py index 2d092d4..b52ea2f 100644 --- a/src/modules/DataBase.py +++ b/src/modules/DataBase.py @@ -7,7 +7,6 @@ class DataBase: self.bot_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.getcwd()))) self.db = sqlite3.connect(os.path.join(self.bot_dir, 'DataBase/OCAB_DB.db')) self.cursor = self.db.cursor() - self.check_db() # Проверки наличия таблиц в базе данных def check_db(self): @@ -82,6 +81,10 @@ class DataBase: self.cursor.execute("""SELECT * FROM user_list WHERE user_id=?""", (user_id,)) return self.cursor.fetchone() + async def get_user_role(self, user_id): + self.cursor.execute("""SELECT user_role FROM user_list WHERE user_id=?""", (user_id,)) + return self.cursor.fetchone() + async def get_message(self, message_id): self.cursor.execute("""SELECT * FROM message_list WHERE message_id=?""", (message_id,)) return self.cursor.fetchone() diff --git a/src/modules/Moderation.py b/src/modules/Moderation.py new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/Roles.py b/src/modules/Roles.py index e69de29..ee13a4f 100644 --- a/src/modules/Roles.py +++ b/src/modules/Roles.py @@ -0,0 +1,33 @@ +from Config import Config +from DataBase import DataBase + + +class Roles: + def __init__(self): + self.DB = DataBase() + self.Config = Config() + self.user_role_name = self.Config.get_roles()['USER'] + self.moderator_role_name = self.Config.get_roles()['MODERATOR'] + self.admin_role_name = self.Config.get_roles()['ADMIN'] + + async def check_admin_permission(self, user_id): + if await self.DB.get_user_role(user_id) == 2: + return True + else: + return False + + async def check_moderator_permission(self, user_id): + if await self.DB.get_user_role(user_id) == 1: + return True + else: + return False + + async def get_role_name(self, role_number): + if role_number == 0: + return self.user_role_name + elif role_number == 1: + return self.moderator_role_name + elif role_number == 2: + return self.admin_role_name + else: + return None