From 3c5b3a8b1e43c38970bd6cf3e7e07c52305c31ad Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 24 May 2023 11:28:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D1=8B=20FS?= =?UTF-8?q?M=20=D0=BC=D0=B0=D1=88=D0=B8=D0=BD=D1=8B=20=D1=81=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D0=B9.=20=D0=A2=D0=B5=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D1=8C=20=D0=BE=D0=BD=D0=B8=20=D1=81=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=B0=D1=8E=D1=82=D1=81=D1=8F=20=D0=B0=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=20=D0=98?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B0=D0=B7?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B8=20=D0=BA=D0=BD=D0=BE=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/access.py | 12 +----- bot_modules/buttons.py | 33 +--------------- bot_modules/comments.py | 29 +------------- bot_modules/languages.py | 29 +------------- bot_modules/messages.py | 33 +--------------- bot_modules/mod_simple_message.py | 4 +- bot_modules/mod_table_operate.py | 45 +++++++++++++++++++++- bot_modules/needs.py | 29 +------------- bot_modules/profile.py | 6 +-- bot_modules/projects.py | 29 +------------- bot_modules/tasks.py | 29 +------------- .../{groups.py => users_groups_agregator.py} | 6 +-- main.py | 15 ++++---- 13 files changed, 67 insertions(+), 232 deletions(-) rename bot_modules/{groups.py => users_groups_agregator.py} (96%) diff --git a/bot_modules/access.py b/bot_modules/access.py index b5b2529..d6ecd2d 100644 --- a/bot_modules/access.py +++ b/bot_modules/access.py @@ -13,11 +13,6 @@ from aiogram.dispatcher.filters.state import State, StatesGroup class FSMRequestToBDAccess(StatesGroup): sqlRequest = State() -class FSMEditAccessItem(StatesGroup): - item_field = State() - -class FSMEditDefaultAccessItem(StatesGroup): - item_field = State() # --------------------------------------------------------- # БД module_name = 'access' @@ -107,16 +102,11 @@ messages = { mod_table_operate.Messages.SUCCESS_EDIT: moduleaccess_success_edit_message, } -fsm = { - mod_table_operate.FSMs.EDIT_ACCESS: FSMEditAccessItem, - mod_table_operate.FSMs.EDIT_DEFAULT_ACCESS: FSMEditDefaultAccessItem, - } - init_access = f'{user_access.user_access_group_new}=-' class ModuleAccess(mod_table_operate.TableOperateModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(table, messages, button_names, fsm, None, None, init_access, a_ChildModuleNameList, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) + super().__init__(table, messages, button_names, None, None, init_access, a_ChildModuleNameList, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) self.m_SqlRequestButtonName = self.CreateButton('sql request', sql_request_button_name) self.m_RequestStartMessage = self.CreateMessage('equest start', request_start_message) diff --git a/bot_modules/buttons.py b/bot_modules/buttons.py index e2cef12..991af83 100644 --- a/bot_modules/buttons.py +++ b/bot_modules/buttons.py @@ -7,29 +7,6 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table, bot_messages from bot_modules import mod_table_operate, mod_simple_message, access_utils from template import bd_item -from aiogram.dispatcher import FSMContext -from aiogram.dispatcher.filters.state import State, StatesGroup - -class FSMCreateButton(StatesGroup): - name = State() - desc = State() - photo = State() - -class FSMEditButtonPhotoItem(StatesGroup): - item_id = State() - item_field = State() - -class FSMEditButtonNameItem(StatesGroup): - item_id = State() - item_field = State() - -class FSMEditButtonDescItem(StatesGroup): - item_id = State() - item_field = State() - -class FSMEditButtonAccessItem(StatesGroup): - item_id = State() - item_field = State() # --------------------------------------------------------- # БД module_name = 'buttons' @@ -62,14 +39,6 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_all}=-' -fsm = { - mod_table_operate.FSMs.CREATE: FSMCreateButton, - mod_table_operate.FSMs.EDIT_NAME: FSMEditButtonNameItem, - mod_table_operate.FSMs.EDIT_DESC: FSMEditButtonDescItem, - mod_table_operate.FSMs.EDIT_PHOTO: FSMEditButtonPhotoItem, - mod_table_operate.FSMs.EDIT_ACCESS: FSMEditButtonAccessItem, - } - # --------------------------------------------------------- # Сообщения и кнопки @@ -159,7 +128,7 @@ messages = { class ModuleButtons(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(table, messages, button_names, fsm, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) def GetName(self): return module_name diff --git a/bot_modules/comments.py b/bot_modules/comments.py index 8217dc8..d9c9c42 100644 --- a/bot_modules/comments.py +++ b/bot_modules/comments.py @@ -6,25 +6,6 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_modules import mod_table_operate, mod_simple_message -from aiogram.dispatcher import FSMContext -from aiogram.dispatcher.filters.state import State, StatesGroup - -class FSMCreateComment(StatesGroup): - name = State() - desc = State() - photo = State() - -class FSMEditCommentPhotoItem(StatesGroup): - item_field = State() - -class FSMEditCommentNameItem(StatesGroup): - item_field = State() - -class FSMEditCommentDescItem(StatesGroup): - item_field = State() - -class FSMEditCommentAccessItem(StatesGroup): - item_field = State() # --------------------------------------------------------- # БД module_name = 'comments' @@ -50,14 +31,6 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_new}=va' -fsm = { - mod_table_operate.FSMs.CREATE: FSMCreateComment, - mod_table_operate.FSMs.EDIT_NAME: FSMEditCommentNameItem, - mod_table_operate.FSMs.EDIT_DESC: FSMEditCommentDescItem, - mod_table_operate.FSMs.EDIT_PHOTO: FSMEditCommentPhotoItem, - mod_table_operate.FSMs.EDIT_ACCESS: FSMEditCommentAccessItem, - } - # --------------------------------------------------------- # Сообщения и кнопки @@ -147,7 +120,7 @@ messages = { class ModuleComments(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(table, messages, button_names, fsm, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) def GetName(self): return module_name diff --git a/bot_modules/languages.py b/bot_modules/languages.py index 259bb59..350a433 100644 --- a/bot_modules/languages.py +++ b/bot_modules/languages.py @@ -7,25 +7,6 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_modules import mod_table_operate, mod_simple_message, access_utils from template import bd_item -from aiogram.dispatcher import FSMContext -from aiogram.dispatcher.filters.state import State, StatesGroup - -class FSMCreateLanguage(StatesGroup): - name = State() - desc = State() - photo = State() - -class FSMEditLanguagePhotoItem(StatesGroup): - item_field = State() - -class FSMEditLanguageNameItem(StatesGroup): - item_field = State() - -class FSMEditLanguageDescItem(StatesGroup): - item_field = State() - -class FSMEditLanguageAccessItem(StatesGroup): - item_field = State() # --------------------------------------------------------- # БД module_name = 'languages' @@ -55,14 +36,6 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_all}=-' -fsm = { - mod_table_operate.FSMs.CREATE: FSMCreateLanguage, - mod_table_operate.FSMs.EDIT_NAME: FSMEditLanguageNameItem, - mod_table_operate.FSMs.EDIT_DESC: FSMEditLanguageDescItem, - mod_table_operate.FSMs.EDIT_PHOTO: FSMEditLanguagePhotoItem, - mod_table_operate.FSMs.EDIT_ACCESS: FSMEditLanguageAccessItem, - } - # --------------------------------------------------------- # Сообщения и кнопки @@ -153,7 +126,7 @@ messages = { class ModuleLanguages(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(table, messages, button_names, fsm, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) self.m_LanguageIDs = {} def GetName(self): diff --git a/bot_modules/messages.py b/bot_modules/messages.py index 2585c8b..e87c8dc 100644 --- a/bot_modules/messages.py +++ b/bot_modules/messages.py @@ -7,29 +7,6 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table, bot_messages from bot_modules import mod_table_operate, mod_simple_message, access_utils from template import bd_item -from aiogram.dispatcher import FSMContext -from aiogram.dispatcher.filters.state import State, StatesGroup - -class FSMCreateMessage(StatesGroup): - name = State() - desc = State() - photo = State() - -class FSMEditMessagePhotoItem(StatesGroup): - item_id = State() - item_field = State() - -class FSMEditMessageNameItem(StatesGroup): - item_id = State() - item_field = State() - -class FSMEditMessageDescItem(StatesGroup): - item_id = State() - item_field = State() - -class FSMEditMessageAccessItem(StatesGroup): - item_id = State() - item_field = State() # --------------------------------------------------------- # БД module_name = 'messages' @@ -62,14 +39,6 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_all}=-' -fsm = { - mod_table_operate.FSMs.CREATE: FSMCreateMessage, - mod_table_operate.FSMs.EDIT_NAME: FSMEditMessageNameItem, - mod_table_operate.FSMs.EDIT_DESC: FSMEditMessageDescItem, - mod_table_operate.FSMs.EDIT_PHOTO: FSMEditMessagePhotoItem, - mod_table_operate.FSMs.EDIT_ACCESS: FSMEditMessageAccessItem, - } - # --------------------------------------------------------- # Сообщения и кнопки @@ -159,7 +128,7 @@ messages = { class ModuleMessages(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(table, messages, button_names, fsm, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) def GetName(self): return module_name diff --git a/bot_modules/mod_simple_message.py b/bot_modules/mod_simple_message.py index 19d5ff4..40c78fd 100644 --- a/bot_modules/mod_simple_message.py +++ b/bot_modules/mod_simple_message.py @@ -65,14 +65,14 @@ class SimpleMessageModule(mod_interface.IModule): return self.m_Messages.get(a_MessageNames, None) def CreateMessage(self, a_MessageName, a_MessageDesc): - msg = self.m_BotMessages.CreateMessage(f'{self.GetName()} {a_MessageName}', a_MessageDesc, self.m_Log.GetTimeNow()) + msg = self.m_BotMessages.CreateMessage(f'{self.GetName()} {str(a_MessageName).replace("Messages.", "")}', a_MessageDesc, self.m_Log.GetTimeNow()) return msg def CreateButton(self, a_ButtonName, a_ButtonDesc): assert len(a_ButtonDesc) < 41 # Телеграм не поддерживает больше assert a_ButtonDesc[0] != ' ' # Телеграм не поддерживает пробелы в начале assert a_ButtonDesc[-1:] != ' ' # Телеграм не поддерживает пробелы в конце - btn = self.m_BotButtons.CreateMessage(f'{self.GetName()} {a_ButtonName}', a_ButtonDesc, self.m_Log.GetTimeNow()) + btn = self.m_BotButtons.CreateMessage(f'{self.GetName()} {str(a_ButtonName).replace("ButtonNames.", "")}', a_ButtonDesc, self.m_Log.GetTimeNow()) return btn def GetModule(self, a_ModName): diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 0c62eaa..8726ef6 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -7,6 +7,9 @@ from bot_sys import keyboard, user_access, bd_table, bot_bd from bot_modules import access_utils, mod_simple_message from template import simple_message, bd_item, bd_item_select, bd_item_view, bd_item_delete, bd_item_add, bd_item_edit +from aiogram.dispatcher import FSMContext +from aiogram.dispatcher.filters.state import State, StatesGroup + from enum import Enum from enum import auto @@ -48,11 +51,49 @@ class FSMs(Enum): EDIT_ACCESS = auto() EDIT_DEFAULT_ACCESS = auto() +create_fsms_cmd = ''' +class FSMCreate{a_ModName}(StatesGroup): + name = State() + desc = State() + photo = State() + +class FSMEdit{a_ModName}PhotoItem(StatesGroup): + item_field = State() + +class FSMEdit{a_ModName}NameItem(StatesGroup): + item_field = State() + +class FSMEdit{a_ModName}DescItem(StatesGroup): + item_field = State() + +class FSMEdit{a_ModName}AccessItem(StatesGroup): + item_field = State() + +class FSMEdit{a_ModName}DefaultAccessItem(StatesGroup): + item_field = State() + +fsm = { + FSMs.CREATE: FSMCreate{a_ModName}, + FSMs.EDIT_NAME: FSMEdit{a_ModName}NameItem, + FSMs.EDIT_DESC: FSMEdit{a_ModName}DescItem, + FSMs.EDIT_PHOTO: FSMEdit{a_ModName}PhotoItem, + FSMs.EDIT_ACCESS: FSMEdit{a_ModName}AccessItem, + FSMs.EDIT_DEFAULT_ACCESS: FSMEdit{a_ModName}DefaultAccessItem, +} +''' + +def MakeFSMs(a_ModName): + cmd = create_fsms_cmd.replace("{a_ModName}", a_ModName) + _locals = locals() + exec(cmd, globals(), _locals) + return _locals['fsm'] + + class TableOperateModule(mod_simple_message.SimpleMessageModule): - def __init__(self, a_Table, a_Messages, a_Buttons, a_FSMs, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): + def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): super().__init__(a_Messages, a_Buttons, a_InitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) self.m_Table = a_Table - self.m_FSMs = a_FSMs + self.m_FSMs = MakeFSMs(self.GetName()) self.m_EditModuleNameList = a_EditModuleNameList self.m_ChildModName = a_ChildModName self.m_ParentModName = a_ParentModName diff --git a/bot_modules/needs.py b/bot_modules/needs.py index 15625a3..993fe88 100644 --- a/bot_modules/needs.py +++ b/bot_modules/needs.py @@ -6,25 +6,6 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_modules import mod_table_operate, mod_simple_message -from aiogram.dispatcher import FSMContext -from aiogram.dispatcher.filters.state import State, StatesGroup - -class FSMCreateNeed(StatesGroup): - name = State() - desc = State() - photo = State() - -class FSMEditNeedPhotoItem(StatesGroup): - item_field = State() - -class FSMEditNeedNameItem(StatesGroup): - item_field = State() - -class FSMEditNeedDescItem(StatesGroup): - item_field = State() - -class FSMEditNeedAccessItem(StatesGroup): - item_field = State() # --------------------------------------------------------- # БД module_name = 'needs' @@ -50,14 +31,6 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_new}=va' -fsm = { - mod_table_operate.FSMs.CREATE: FSMCreateNeed, - mod_table_operate.FSMs.EDIT_NAME: FSMEditNeedNameItem, - mod_table_operate.FSMs.EDIT_DESC: FSMEditNeedDescItem, - mod_table_operate.FSMs.EDIT_PHOTO: FSMEditNeedPhotoItem, - mod_table_operate.FSMs.EDIT_ACCESS: FSMEditNeedAccessItem, - } - # --------------------------------------------------------- # Сообщения и кнопки @@ -148,7 +121,7 @@ messages = { class ModuleNeeds(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(table, messages, button_names, fsm, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) def GetName(self): return module_name diff --git a/bot_modules/profile.py b/bot_modules/profile.py index 4062b38..7c3a986 100644 --- a/bot_modules/profile.py +++ b/bot_modules/profile.py @@ -4,7 +4,7 @@ # Профиль пользователя from bot_sys import user_access, bot_bd, bd_table -from bot_modules import mod_simple_message, groups, access, access_utils, groups_utils +from bot_modules import mod_simple_message, access, access_utils, groups_utils, users_groups_agregator from template import bd_item, simple_message # --------------------------------------------------------- @@ -85,10 +85,10 @@ def AddUser(a_Bot, a_UserID, a_UserName, a_UserName1, a_UserName2, a_UserIsBot, user_groups = groups_utils.GetUserGroupData(a_Bot, a_UserID) # Если пользователь не состоит ни в одной группе, то добавляем его в группу user_access.user_access_group_new if len(user_groups.group_names_list) == 0: - new_group_id = a_Bot.SQLRequest(f'SELECT {groups.key_table_groups_name} FROM {groups.table_groups_name} WHERE {groups.name_table_groups_field} = ?', + new_group_id = a_Bot.SQLRequest(f'SELECT {users_groups_agregator.key_table_groups_name} FROM {users_groups_agregator.table_groups_name} WHERE {users_groups_agregator.name_table_groups_field} = ?', param = [user_access.user_access_group_new]) if new_group_id and new_group_id[0]: - a_Bot.SQLRequest(f"INSERT OR IGNORE INTO {groups.table_user_in_groups_name} ({groups.user_id_field}, {groups.key_table_groups_name}, {groups.access_field}, {groups.create_datetime_field}) VALUES (?, ?, ?, {bot_bd.GetBDDateTimeNow()});", + a_Bot.SQLRequest(f"INSERT OR IGNORE INTO {users_groups_agregator.table_user_in_groups_name} ({users_groups_agregator.user_id_field}, {users_groups_agregator.key_table_groups_name}, {users_groups_agregator.access_field}, {users_groups_agregator.create_datetime_field}) VALUES (?, ?, ?, {bot_bd.GetBDDateTimeNow()});", commit=True, param = (a_UserID, new_group_id[0][0], access_utils.GetItemDefaultAccessForModule(a_Bot, module_name))) def GetUserInfo(a_Bot, a_UserID): diff --git a/bot_modules/projects.py b/bot_modules/projects.py index 6b82cfa..ef5d54e 100644 --- a/bot_modules/projects.py +++ b/bot_modules/projects.py @@ -6,25 +6,6 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_modules import mod_table_operate, mod_simple_message -from aiogram.dispatcher import FSMContext -from aiogram.dispatcher.filters.state import State, StatesGroup - -class FSMCreateProject(StatesGroup): - name = State() - desc = State() - photo = State() - -class FSMEditProjectPhotoItem(StatesGroup): - item_field = State() - -class FSMEditProjectNameItem(StatesGroup): - item_field = State() - -class FSMEditProjectDescItem(StatesGroup): - item_field = State() - -class FSMEditProjectAccessItem(StatesGroup): - item_field = State() # --------------------------------------------------------- # БД module_name = 'projects' @@ -48,14 +29,6 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_new}=va' -fsm = { - mod_table_operate.FSMs.CREATE: FSMCreateProject, - mod_table_operate.FSMs.EDIT_NAME: FSMEditProjectNameItem, - mod_table_operate.FSMs.EDIT_DESC: FSMEditProjectDescItem, - mod_table_operate.FSMs.EDIT_PHOTO: FSMEditProjectPhotoItem, - mod_table_operate.FSMs.EDIT_ACCESS: FSMEditProjectAccessItem, - } - # --------------------------------------------------------- # Сообщения и кнопки @@ -146,7 +119,7 @@ messages = { class ModuleProjects(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(table, messages, button_names, fsm, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) def GetName(self): return module_name diff --git a/bot_modules/tasks.py b/bot_modules/tasks.py index b591ce3..56b4c49 100644 --- a/bot_modules/tasks.py +++ b/bot_modules/tasks.py @@ -6,25 +6,6 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_modules import mod_table_operate, mod_simple_message -from aiogram.dispatcher import FSMContext -from aiogram.dispatcher.filters.state import State, StatesGroup - -class FSMCreateTask(StatesGroup): - name = State() - desc = State() - photo = State() - -class FSMEditTaskPhotoItem(StatesGroup): - item_field = State() - -class FSMEditTaskNameItem(StatesGroup): - item_field = State() - -class FSMEditTaskDescItem(StatesGroup): - item_field = State() - -class FSMEditTaskAccessItem(StatesGroup): - item_field = State() # --------------------------------------------------------- # БД module_name = 'tasks' @@ -50,14 +31,6 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_new}=va' -fsm = { - mod_table_operate.FSMs.CREATE: FSMCreateTask, - mod_table_operate.FSMs.EDIT_NAME: FSMEditTaskNameItem, - mod_table_operate.FSMs.EDIT_DESC: FSMEditTaskDescItem, - mod_table_operate.FSMs.EDIT_PHOTO: FSMEditTaskPhotoItem, - mod_table_operate.FSMs.EDIT_ACCESS: FSMEditTaskAccessItem, - } - # --------------------------------------------------------- # Сообщения и кнопки @@ -148,7 +121,7 @@ messages = { class ModuleTasks(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(table, messages, button_names, fsm, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) + super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) def GetName(self): return module_name diff --git a/bot_modules/groups.py b/bot_modules/users_groups_agregator.py similarity index 96% rename from bot_modules/groups.py rename to bot_modules/users_groups_agregator.py index 7d02fa6..a6c2fce 100644 --- a/bot_modules/groups.py +++ b/bot_modules/users_groups_agregator.py @@ -15,7 +15,7 @@ class FSMRequestToBD(StatesGroup): # --------------------------------------------------------- # БД -module_name = 'groups' +module_name = 'users_groups_agregator' table_groups_name = 'user_groups' table_user_in_groups_name = 'user_in_groups' @@ -64,7 +64,7 @@ messages = { init_access = f'{user_access.user_access_group_new}=-' -class ModuleGroups(mod_simple_message.SimpleMessageModule): +class ModuleUsersGroupsAgregator(mod_simple_message.SimpleMessageModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): super().__init__(messages, button_names, init_access, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) self.m_SqlRequestButtonName = self.CreateButton('sql request', sql_request_button_name) @@ -110,7 +110,7 @@ class ModuleGroups(mod_simple_message.SimpleMessageModule): keyboard.ButtonWithAccess(self.m_SqlRequestButtonName, user_access.AccessMode.EDIT, self.GetAccess()), keyboard.ButtonWithAccess(self.m_HelpButtonName , user_access.AccessMode.VIEW, self.GetAccess()) ] - return mod_buttons + keyboard.MakeButtons(cur_buttons, a_UserGroups) + return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) def RegisterHandlers(self): super().RegisterHandlers() diff --git a/main.py b/main.py index f48c1ad..eff38b7 100644 --- a/main.py +++ b/main.py @@ -1,22 +1,22 @@ # -*- coding: utf8 -*- # Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) -log_start_message = 'Бот успешно запущен!' - import os from bot_sys import config, log, aiogram_bot, bot_messages, bd_table, user_access -from bot_modules import mod_agregator, start, profile, backup, groups, access, projects, tasks, needs, comments, languages, messages, buttons +from bot_modules import mod_agregator, start, profile, backup, users_groups_agregator, access, projects, tasks, needs, comments, languages, messages, buttons + +log_start_message = 'Бот успешно запущен!' bd_file_name = 'bot.db' log_file_name = 'log.txt' +default_language = 'ru' + g_Log = log.Log(log_file_name) g_Bot = aiogram_bot.AiogramBot(config.GetTelegramBotApiToken(), bd_file_name, config.GetRootIDs(), g_Log) -default_language = 'ru' - g_BotMessages = bot_messages.BotMessages(default_language) g_BotButtons = bot_messages.BotMessages(default_language) @@ -32,13 +32,14 @@ mod_messages_name = messages.module_name mod_buttons_name = buttons.module_name start_mod_list = [mod_start_name] - mod_access = access.ModuleAccess(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) g_ModuleAgregator.AddModule(mod_access) -mod_groups = groups.ModuleGroups(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) +start_mod_name_list = [mod_start_name] +mod_groups = users_groups_agregator.ModuleUsersGroupsAgregator(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) g_ModuleAgregator.AddModule(mod_groups) +start_mod_list = [mod_start_name] mod_profile = profile.ModuleProfile(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) g_ModuleAgregator.AddModule(mod_profile)