mirror of
https://gitflic.ru/project/maks1ms/ocab.git
synced 2024-12-23 16:23:01 +03:00
Добавлены новые модули.
- Config.py Модуль взаимодействия с config.yaml - Roles.py Модуль проверки прав доступа пользователя.
This commit is contained in:
parent
16664179ea
commit
7f232eff50
@ -1,2 +1,3 @@
|
||||
aiogram==2.25.1
|
||||
aiogram==3.1.1
|
||||
openai==0.27.8
|
||||
PyYAML==6.0.1
|
||||
|
23
src/config.yaml
Normal file
23
src/config.yaml
Normal file
@ -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:
|
21
src/modules/Config.py
Normal file
21
src/modules/Config.py
Normal file
@ -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']
|
@ -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()
|
||||
|
0
src/modules/Moderation.py
Normal file
0
src/modules/Moderation.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user