From 6b130ef0e4491c71cb41b0bb335f311403029899 Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 17 May 2023 15:54:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=20?= =?UTF-8?q?=D0=BA=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/access.py | 42 ++++++++++++++++++++--------- bot_modules/backup.py | 10 ++++++- bot_modules/comments.py | 16 +++++++---- bot_modules/groups.py | 21 +++++++++------ bot_modules/mod_simple_message.py | 32 +++++++++++++++++----- bot_modules/mod_table_operate.py | 56 ++++++++++++++++----------------------- bot_modules/needs.py | 26 +++++++++++------- bot_modules/profile.py | 16 ++++++----- bot_modules/projects.py | 16 +++++++---- bot_modules/start.py | 14 ++++++---- bot_modules/tasks.py | 26 +++++++++++------- bot_sys/bd_table.py | 1 + 12 files changed, 175 insertions(+), 101 deletions(-) diff --git a/bot_modules/access.py b/bot_modules/access.py index a0c331d..9d2416e 100644 --- a/bot_modules/access.py +++ b/bot_modules/access.py @@ -3,8 +3,8 @@ # Права пользователей -from bot_sys import keyboard, user_access, bot_bd -from bot_modules import mod_simple_message, access_utils +from bot_sys import keyboard, user_access, bot_bd, bd_table +from bot_modules import mod_simple_message, access_utils, mod_table_operate from template import simple_message, sql_request, bd_item from aiogram.dispatcher import FSMContext @@ -29,8 +29,11 @@ mod_name_field = access_utils.mod_name_field moduleaccess_field = access_utils.moduleaccess_field mod_default_access_field = access_utils.mod_default_access_field -#TODO: Автоматическое создание init_bd_cmds, необходимо table_name, mod_name_field ... объединить в объект - +table = bd_table.Table(table_name, [ + bd_table.TableField(mod_name_field, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.STR), + bd_table.TableField(moduleaccess_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), + bd_table.TableField(mod_default_access_field, bd_table.TableFieldDestiny.DEFAULT_ACCESS, bd_table.TableFieldType.STR), + ]) # --------------------------------------------------------- # Сообщения @@ -86,14 +89,31 @@ moduleaccess_edit_default_access_message = f''' Введите новую строку доступа: ''' - -moduleaccess_success_edit_message = '''✅ Проект успешно отредактирован!''' +moduleaccess_success_edit_message = '''✅ Доступ к модулю успешно отредактирован!''' + +button_names = { + mod_simple_message.ButtonNames.START: start_button_name, + mod_table_operate.ButtonNames.EDIT_ACCESS: "◇ Изменить доступ к модулю", + mod_table_operate.ButtonNames.EDIT_DEFAULT_ACCESS: "◈ Изменить доступ по умолчанию к модулю ", + } + +messages = { + mod_simple_message.Messages.START: start_message, + mod_table_operate.Messages.EDIT_ACCESS: moduleaccess_edit_access_message, + mod_table_operate.Messages.EDIT_DEFAULT_ACCESS: moduleaccess_edit_default_access_message, + 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_simple_message.SimpleMessageModule): +class ModuleAccess(mod_table_operate.TableOperateModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(start_message, start_button_name, init_access, 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) self.m_SqlRequestButtonName = self.CreateButton('sql request', sql_request_button_name) self.m_RequestStartMessage = self.CreateMessage('equest start', request_start_message) @@ -107,7 +127,7 @@ class ModuleAccess(mod_simple_message.SimpleMessageModule): None, self.m_GetAccessFunc ) - + ''' def GetInitBDCommands(self): return [ f"""CREATE TABLE IF NOT EXISTS {table_name}( @@ -117,7 +137,7 @@ class ModuleAccess(mod_simple_message.SimpleMessageModule): UNIQUE({mod_name_field}) );""", ] + super().GetInitBDCommands() - + ''' def GetName(self): return module_name @@ -146,8 +166,6 @@ class ModuleAccess(mod_simple_message.SimpleMessageModule): ) - - # --------------------------------------------------------- # Работа с кнопками ''' diff --git a/bot_modules/backup.py b/bot_modules/backup.py index 75fb9b9..291ca5b 100644 --- a/bot_modules/backup.py +++ b/bot_modules/backup.py @@ -36,11 +36,19 @@ error_backup_message = ''' backup_bd_button_name = "📀 Резервные копия базы" backup_log_button_name = "📃 Логи" +button_names = { + mod_simple_message.ButtonNames.START: start_button_name, +} + +messages = { + mod_simple_message.Messages.START: start_message, +} + init_access = f'{user_access.user_access_group_new}=-' class ModuleBackup(mod_simple_message.SimpleMessageModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(start_message, start_button_name, init_access, 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_BackupBDButtonName = self.CreateButton('backup bd', backup_bd_button_name) self.m_BackupBDMessage = self.CreateMessage('backup bd', backup_bd_message) diff --git a/bot_modules/comments.py b/bot_modules/comments.py index 941705b..e09a78b 100644 --- a/bot_modules/comments.py +++ b/bot_modules/comments.py @@ -4,7 +4,7 @@ # Комментарии from bot_sys import bot_bd, keyboard, user_access, user_messages, bd_table -from bot_modules import mod_table_operate +from bot_modules import mod_table_operate, mod_simple_message from aiogram.dispatcher import FSMContext from aiogram.dispatcher.filters.state import State, StatesGroup @@ -50,13 +50,19 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_new}=va' -fsm = mod_table_operate.FSMs(FSMCreateComment, FSMEditCommentNameItem, FSMEditCommentDescItem, FSMEditCommentPhotoItem, FSMEditCommentAccessItem) +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, + } # --------------------------------------------------------- # Сообщения и кнопки button_names = { - mod_table_operate.ButtonNames.START: "⚏ Комментарии", + mod_simple_message.ButtonNames.START: "⚏ Комментарии", mod_table_operate.ButtonNames.LIST: "📃 Список комментариев", mod_table_operate.ButtonNames.ADD: "☑ Добавить комментарий", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать комментарий", @@ -68,8 +74,8 @@ button_names = { } messages = { - mod_table_operate.Messages.START: f''' -{button_names[mod_table_operate.ButtonNames.START]} + mod_simple_message.Messages.START: f''' +{button_names[mod_simple_message.ButtonNames.START]} ''', mod_table_operate.Messages.SELECT: ''' diff --git a/bot_modules/groups.py b/bot_modules/groups.py index 01b702c..7d02fa6 100644 --- a/bot_modules/groups.py +++ b/bot_modules/groups.py @@ -29,12 +29,6 @@ create_datetime_field = 'createDateTime' # --------------------------------------------------------- # Сообщения -start_message = ''' -Группы пользователей находятся в стадии разработки - -Пока можете воспользоваться хардкорным способом через запросы к БД -''' - request_start_message = ''' **Задайте запрос к БД** @@ -53,15 +47,26 @@ help_message = ''' `user_in_groups(user_id, group_id)` - содержит соответсвия ID пользователей и групп ''' -start_button_name = "‍️️▦ Группы пользователей" sql_request_button_name = "⛃ Запрос к БД для редактирования групп" help_button_name = "📄 Информация по группам" +button_names = { + mod_simple_message.ButtonNames.START: "‍️️▦ Группы пользователей", +} + +messages = { + mod_simple_message.Messages.START: ''' +Группы пользователей находятся в стадии разработки + +Пока можете воспользоваться хардкорным способом через запросы к БД +''', +} + init_access = f'{user_access.user_access_group_new}=-' class ModuleGroups(mod_simple_message.SimpleMessageModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(start_message, start_button_name, init_access, 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) self.m_RequestStartMessage = self.CreateMessage('equest start', request_start_message) diff --git a/bot_modules/mod_simple_message.py b/bot_modules/mod_simple_message.py index 6c56b3f..fffa8c8 100644 --- a/bot_modules/mod_simple_message.py +++ b/bot_modules/mod_simple_message.py @@ -7,8 +7,17 @@ from bot_sys import keyboard, user_access from bot_modules import access_utils, mod_interface from template import simple_message, bd_item +from enum import Enum +from enum import auto + +class ButtonNames(Enum): + START = auto() + +class Messages(Enum): + START = auto() + class SimpleMessageModule(mod_interface.IModule): - def __init__(self, a_StartMessage, a_StartButtonName, a_InitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): + def __init__(self, a_Messages, a_Buttons, a_InitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): self.m_ChildModuleNameList = a_ChildModuleNameList self.m_InitAccess = a_InitAccess self.m_Bot = a_Bot @@ -17,8 +26,13 @@ class SimpleMessageModule(mod_interface.IModule): self.m_BotButtons = a_BotButtons self.m_Log = a_Log - self.m_StartButtonName = self.CreateButton('start', a_StartButtonName) - self.m_StartMessage = self.CreateMessage('start', a_StartMessage) + self.m_Buttons = {} + for name, button_name in a_Buttons.items(): + self.m_Buttons[name] = self.CreateButton(name, button_name) + + self.m_Messages = {} + for name, message in a_Messages.items(): + self.m_Messages[name] = self.CreateMessage(name, message) async def StartMessageHandler(a_Message, state = None): return await self.StartMessageHandler(a_Message, state) @@ -42,7 +56,13 @@ class SimpleMessageModule(mod_interface.IModule): # Основной обработчик главного сообщения async def StartMessageHandler(self, a_Message, state = None): - return simple_message.WorkFuncResult(self.m_StartMessage) + return simple_message.WorkFuncResult(self.GetMessage(Messages.START)) + + def GetButton(self, a_ButtonName): + return self.m_Buttons.get(a_ButtonName, None) + + def GetMessage(self, a_MessageNames): + 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()) @@ -78,12 +98,12 @@ class SimpleMessageModule(mod_interface.IModule): def GetModuleButtons(self): return [ - keyboard.ButtonWithAccess(self.m_StartButtonName, user_access.AccessMode.VIEW, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(ButtonNames.START), user_access.AccessMode.VIEW, self.GetAccess()), ] def RegisterHandlers(self): self.m_Bot.RegisterMessageHandler( self.m_StartMessageHandler, - bd_item.GetCheckForTextFunc(self.m_StartButtonName) + bd_item.GetCheckForTextFunc(self.GetButton(ButtonNames.START)) ) diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 8641898..1817686 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -11,7 +11,6 @@ from enum import Enum from enum import auto class ButtonNames(Enum): - START = auto() LIST = auto() ADD = auto() EDIT = auto() @@ -19,10 +18,10 @@ class ButtonNames(Enum): EDIT_NAME = auto() EDIT_DESC = auto() EDIT_ACCESS = auto() + EDIT_DEFAULT_ACCESS = auto() DEL = auto() class Messages(Enum): - START = auto() SELECT = auto() ERROR_FIND = auto() OPEN = auto() @@ -36,21 +35,22 @@ class Messages(Enum): EDIT_NAME = auto() EDIT_DESC = auto() EDIT_ACCESS = auto() + EDIT_DEFAULT_ACCESS = auto() SUCCESS_EDIT = auto() SELECT_TO_DELETE = auto() SUCCESS_DELETE = auto() -class FSMs: - def __init__(self, a_FSMCreate, a_FSMEditName, a_FSMEditDesc, a_FSMEditPhoto, a_FSMEditAccess): - self.m_FSMCreate = a_FSMCreate - self.m_FSMEditName = a_FSMEditName - self.m_FSMEditDesc = a_FSMEditDesc - self.m_FSMEditPhoto = a_FSMEditPhoto - self.m_FSMEditAccess = a_FSMEditAccess +class FSMs(Enum): + CREATE = auto() + EDIT_PHOTO = auto() + EDIT_NAME = auto() + EDIT_DESC = auto() + EDIT_ACCESS = auto() + EDIT_DEFAULT_ACCESS = auto() 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): - super().__init__(a_Messages[Messages.START], a_Buttons[ButtonNames.START], a_InitAccess, a_ChildModuleNameList, 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_EditModuleNameList = a_EditModuleNameList @@ -58,14 +58,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): self.m_ParentModName = a_ParentModName self.m_SelectPrefix = '' - self.m_Buttons = {} - for name, button_name in a_Buttons.items(): - self.m_Buttons[name] = self.CreateButton(name, button_name) - - self.m_Messages = {} - for name, message in a_Messages.items(): - self.m_Messages[name] = self.CreateMessage(name, message) - def GetEditKeyboardButtons(a_Message, a_UserGroups): return self.GetEditKeyboardButtons(a_Message, a_UserGroups) self.m_GetEditKeyboardButtonsFunc = GetEditKeyboardButtons @@ -86,12 +78,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return self.AddBDItemFunc(a_ItemData, a_UserID) self.m_AddBDItemFunc = AddBDItemFunc - - def GetButton(self, a_ButtonName): - return self.m_Buttons.get(a_ButtonName, None) - - def GetMessage(self, a_MessageNames): - return self.m_Messages.get(a_MessageNames, None) + def GetFSM(self, a_FSMName): + return self.m_FSMs.get(a_FSMName, None) def GetInitBDCommands(self): return super(). GetInitBDCommands() + [ @@ -242,6 +230,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC) photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO) access_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ACCESS) + def_access_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DEFAULT_ACCESS) parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) parent_table_name = None @@ -287,7 +276,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): GetAccess, \ defaul_keyboard_func\ ) - self.m_SelectPrefix = a_Prefix + self.m_SelectPrefix = a_Prefix # Удаление a_ButtonName = self.GetButton(ButtonNames.DEL) @@ -314,10 +303,10 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): bd_item_add.AddBDItem3RegisterHandlers(self.m_Bot, \ check_func, \ - self.m_FSMs.m_FSMCreate, \ - self.m_FSMs.m_FSMCreate.name,\ - self.m_FSMs.m_FSMCreate.desc, \ - self.m_FSMs.m_FSMCreate.photo,\ + self.GetFSM(FSMs.CREATE), \ + self.GetFSM(FSMs.CREATE).name,\ + self.GetFSM(FSMs.CREATE).desc, \ + self.GetFSM(FSMs.CREATE).photo,\ self.m_AddBDItemFunc, \ self.ShowMessageTemplate(self.GetMessage(Messages.CREATE_NAME)), \ self.ShowMessageTemplate(self.GetMessage(Messages.CREATE_DESC)), \ @@ -376,8 +365,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): bd_item.GetCheckForTextFunc(a_ButtonName)\ ) - RegisterEdit(self.GetButton(ButtonNames.EDIT_NAME), self.m_FSMs.m_FSMEditName, self.GetMessage(Messages.EDIT_NAME), name_field, bd_item.FieldType.text) - RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.m_FSMs.m_FSMEditDesc, self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text) - RegisterEdit(self.GetButton(ButtonNames.EDIT_PHOTO), self.m_FSMs.m_FSMEditPhoto, self.GetMessage(Messages.EDIT_PHOTO), photo_field, bd_item.FieldType.photo) - RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.m_FSMs.m_FSMEditAccess, self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text) + RegisterEdit(self.GetButton(ButtonNames.EDIT_NAME), self.GetFSM(FSMs.EDIT_NAME), self.GetMessage(Messages.EDIT_NAME), name_field, bd_item.FieldType.text) + RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.GetFSM(FSMs.EDIT_DESC), self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text) + RegisterEdit(self.GetButton(ButtonNames.EDIT_PHOTO), self.GetFSM(FSMs.EDIT_PHOTO), self.GetMessage(Messages.EDIT_PHOTO), photo_field, bd_item.FieldType.photo) + RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.GetFSM(FSMs.EDIT_ACCESS), self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text) + RegisterEdit(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), self.GetFSM(FSMs.EDIT_DEFAULT_ACCESS), self.GetMessage(Messages.EDIT_DEFAULT_ACCESS), def_access_field, bd_item.FieldType.text) diff --git a/bot_modules/needs.py b/bot_modules/needs.py index 42f67e5..b58ca8d 100644 --- a/bot_modules/needs.py +++ b/bot_modules/needs.py @@ -4,26 +4,26 @@ # Потребности from bot_sys import bot_bd, keyboard, user_access, user_messages, bd_table -from bot_modules import mod_table_operate +from bot_modules import mod_table_operate, mod_simple_message from aiogram.dispatcher import FSMContext from aiogram.dispatcher.filters.state import State, StatesGroup -class FSMCreateNeeds(StatesGroup): +class FSMCreateNeed(StatesGroup): name = State() desc = State() photo = State() -class FSMEditNeedsPhotoItem(StatesGroup): +class FSMEditNeedPhotoItem(StatesGroup): item_field = State() -class FSMEditNeedsNameItem(StatesGroup): +class FSMEditNeedNameItem(StatesGroup): item_field = State() -class FSMEditNeedsDescItem(StatesGroup): +class FSMEditNeedDescItem(StatesGroup): item_field = State() -class FSMEditNeedsAccessItem(StatesGroup): +class FSMEditNeedAccessItem(StatesGroup): item_field = State() # --------------------------------------------------------- # БД @@ -50,13 +50,19 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_new}=va' -fsm = mod_table_operate.FSMs(FSMCreateNeeds, FSMEditNeedsNameItem, FSMEditNeedsDescItem, FSMEditNeedsPhotoItem, FSMEditNeedsAccessItem) +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, + } # --------------------------------------------------------- # Сообщения и кнопки button_names = { - mod_table_operate.ButtonNames.START: "👉 Потребности", + mod_simple_message.ButtonNames.START: "👉 Потребности", mod_table_operate.ButtonNames.LIST: "📃 Список потребностей", mod_table_operate.ButtonNames.ADD: "☑ Добавить потребность", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать потребность", @@ -68,8 +74,8 @@ button_names = { } messages = { - mod_table_operate.Messages.START: f''' -{button_names[mod_table_operate.ButtonNames.START]} + mod_simple_message.Messages.START: f''' +{button_names[mod_simple_message.ButtonNames.START]} ''', mod_table_operate.Messages.SELECT: ''' diff --git a/bot_modules/profile.py b/bot_modules/profile.py index 183656e..b7e887a 100644 --- a/bot_modules/profile.py +++ b/bot_modules/profile.py @@ -32,7 +32,12 @@ table = bd_table.Table(table_name, [ bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), ]) -start_message = f''' +button_names = { + mod_simple_message.ButtonNames.START: "📰 Профиль", +} + +messages = { + mod_simple_message.Messages.START: f''' 📰 Профиль: ID: #{key_name} @@ -41,15 +46,14 @@ start_message = f''' Имя2: #{name2_field} Код языка: #{language_code_field} Дата добавления: #{create_datetime_field} -''' - -start_button_name = "📰 Профиль" +''', +} init_access = f'{user_access.user_access_group_new}=+' class ModuleProfile(mod_simple_message.SimpleMessageModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(start_message, start_button_name, init_access, 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) def GetInitBDCommands(self): return super(). GetInitBDCommands() + [ @@ -64,7 +68,7 @@ class ModuleProfile(mod_simple_message.SimpleMessageModule): user_info = GetUserInfo(self.m_Bot, a_Message.from_user.id) lang = str(a_Message.from_user.language_code) if not user_info is None: - msg = self.m_StartMessage + msg = self.GetButton(mod_simple_message.ButtonNames.START) msg = msg.GetMessageForLang(lang).StaticCopy() msg.UpdateDesc(table.ReplaceAllFieldTags(msg.GetDesc(), user_info)) return simple_message.WorkFuncResult(msg, item_access = str(user_info[table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)])) diff --git a/bot_modules/projects.py b/bot_modules/projects.py index e7f721a..08d181d 100644 --- a/bot_modules/projects.py +++ b/bot_modules/projects.py @@ -4,7 +4,7 @@ # Проекты from bot_sys import bot_bd, keyboard, user_access, user_messages, bd_table -from bot_modules import mod_table_operate +from bot_modules import mod_table_operate, mod_simple_message from aiogram.dispatcher import FSMContext from aiogram.dispatcher.filters.state import State, StatesGroup @@ -48,13 +48,19 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_new}=va' -fsm = mod_table_operate.FSMs(FSMCreateProject, FSMEditProjectNameItem, FSMEditProjectDescItem, FSMEditProjectPhotoItem, FSMEditProjectAccessItem) +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, + } # --------------------------------------------------------- # Сообщения и кнопки button_names = { - mod_table_operate.ButtonNames.START: "🟥 Проекты", + mod_simple_message.ButtonNames.START: "🟥 Проекты", mod_table_operate.ButtonNames.LIST: "📃 Список проектов", mod_table_operate.ButtonNames.ADD: "✅ Добавить проект", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать проект", @@ -66,8 +72,8 @@ button_names = { } messages = { - mod_table_operate.Messages.START: f''' -{button_names[mod_table_operate.ButtonNames.START]} + mod_simple_message.Messages.START: f''' +{button_names[mod_simple_message.ButtonNames.START]} ''', mod_table_operate.Messages.SELECT: ''' diff --git a/bot_modules/start.py b/bot_modules/start.py index 5c3f945..ec203e5 100644 --- a/bot_modules/start.py +++ b/bot_modules/start.py @@ -7,18 +7,22 @@ from bot_sys import user_access from bot_modules import mod_simple_message, profile from template import bd_item -start_message = ''' -Добро пожаловать! +button_names = { + mod_simple_message.ButtonNames.START: "☰ Главное меню", +} -Выберите возможные действия на кнопках ниже ⌨''' +messages = { + mod_simple_message.Messages.START: f''' +Добро пожаловать! -start_button_name = "☰ Главное меню" +Выберите возможные действия на кнопках ниже ⌨''', +} init_access = f'{user_access.user_access_group_all}=+' class ModuleStart(mod_simple_message.SimpleMessageModule): def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): - super().__init__(start_message, start_button_name, init_access, 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) def GetName(self): return 'start' diff --git a/bot_modules/tasks.py b/bot_modules/tasks.py index ca69097..5632a18 100644 --- a/bot_modules/tasks.py +++ b/bot_modules/tasks.py @@ -4,26 +4,26 @@ # Задачи from bot_sys import bot_bd, keyboard, user_access, user_messages, bd_table -from bot_modules import mod_table_operate +from bot_modules import mod_table_operate, mod_simple_message from aiogram.dispatcher import FSMContext from aiogram.dispatcher.filters.state import State, StatesGroup -class FSMCreateTasks(StatesGroup): +class FSMCreateTask(StatesGroup): name = State() desc = State() photo = State() -class FSMEditTasksPhotoItem(StatesGroup): +class FSMEditTaskPhotoItem(StatesGroup): item_field = State() -class FSMEditTasksNameItem(StatesGroup): +class FSMEditTaskNameItem(StatesGroup): item_field = State() -class FSMEditTasksDescItem(StatesGroup): +class FSMEditTaskDescItem(StatesGroup): item_field = State() -class FSMEditTasksAccessItem(StatesGroup): +class FSMEditTaskAccessItem(StatesGroup): item_field = State() # --------------------------------------------------------- # БД @@ -50,13 +50,19 @@ table = bd_table.Table(table_name, [ init_access = f'{user_access.user_access_group_new}=va' -fsm = mod_table_operate.FSMs(FSMCreateTasks, FSMEditTasksNameItem, FSMEditTasksDescItem, FSMEditTasksPhotoItem, FSMEditTasksAccessItem) +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, + } # --------------------------------------------------------- # Сообщения и кнопки button_names = { - mod_table_operate.ButtonNames.START: "✎ Задачи", + mod_simple_message.ButtonNames.START: "✎ Задачи", mod_table_operate.ButtonNames.LIST: "📃 Список задач", mod_table_operate.ButtonNames.ADD: "☑ Добавить задачу", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать задачу", @@ -68,8 +74,8 @@ button_names = { } messages = { - mod_table_operate.Messages.START: f''' -{button_names[mod_table_operate.ButtonNames.START]} + mod_simple_message.Messages.START: f''' +{button_names[mod_simple_message.ButtonNames.START]} ''', mod_table_operate.Messages.SELECT: ''' diff --git a/bot_sys/bd_table.py b/bot_sys/bd_table.py index 233a806..e2dc628 100644 --- a/bot_sys/bd_table.py +++ b/bot_sys/bd_table.py @@ -16,6 +16,7 @@ class TableFieldDestiny(Enum): DESC = auto() PHOTO = auto() ACCESS = auto() + DEFAULT_ACCESS = auto() CREATE_DATE = auto() PARENT_ID = auto() OTHER = auto()