Browse Source

Подправлен доступ к модулям

pull/2/head
Alexei 2 years ago
parent
commit
6b130ef0e4
  1. 42
      bot_modules/access.py
  2. 10
      bot_modules/backup.py
  3. 16
      bot_modules/comments.py
  4. 21
      bot_modules/groups.py
  5. 32
      bot_modules/mod_simple_message.py
  6. 56
      bot_modules/mod_table_operate.py
  7. 26
      bot_modules/needs.py
  8. 16
      bot_modules/profile.py
  9. 16
      bot_modules/projects.py
  10. 14
      bot_modules/start.py
  11. 26
      bot_modules/tasks.py
  12. 1
      bot_sys/bd_table.py

42
bot_modules/access.py

@ -3,8 +3,8 @@
# Права пользователей # Права пользователей
from bot_sys import keyboard, user_access, bot_bd from bot_sys import keyboard, user_access, bot_bd, bd_table
from bot_modules import mod_simple_message, access_utils from bot_modules import mod_simple_message, access_utils, mod_table_operate
from template import simple_message, sql_request, bd_item from template import simple_message, sql_request, bd_item
from aiogram.dispatcher import FSMContext from aiogram.dispatcher import FSMContext
@ -29,8 +29,11 @@ mod_name_field = access_utils.mod_name_field
moduleaccess_field = access_utils.moduleaccess_field moduleaccess_field = access_utils.moduleaccess_field
mod_default_access_field = access_utils.mod_default_access_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}=-' 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): 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_SqlRequestButtonName = self.CreateButton('sql request', sql_request_button_name)
self.m_RequestStartMessage = self.CreateMessage('equest start', request_start_message) self.m_RequestStartMessage = self.CreateMessage('equest start', request_start_message)
@ -107,7 +127,7 @@ class ModuleAccess(mod_simple_message.SimpleMessageModule):
None, None,
self.m_GetAccessFunc self.m_GetAccessFunc
) )
'''
def GetInitBDCommands(self): def GetInitBDCommands(self):
return [ return [
f"""CREATE TABLE IF NOT EXISTS {table_name}( f"""CREATE TABLE IF NOT EXISTS {table_name}(
@ -117,7 +137,7 @@ class ModuleAccess(mod_simple_message.SimpleMessageModule):
UNIQUE({mod_name_field}) UNIQUE({mod_name_field})
);""", );""",
] + super().GetInitBDCommands() ] + super().GetInitBDCommands()
'''
def GetName(self): def GetName(self):
return module_name return module_name
@ -146,8 +166,6 @@ class ModuleAccess(mod_simple_message.SimpleMessageModule):
) )
# --------------------------------------------------------- # ---------------------------------------------------------
# Работа с кнопками # Работа с кнопками
''' '''

10
bot_modules/backup.py

@ -36,11 +36,19 @@ error_backup_message = '''
backup_bd_button_name = "📀 Резервные копия базы" backup_bd_button_name = "📀 Резервные копия базы"
backup_log_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}=-' init_access = f'{user_access.user_access_group_new}=-'
class ModuleBackup(mod_simple_message.SimpleMessageModule): class ModuleBackup(mod_simple_message.SimpleMessageModule):
def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): 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_BackupBDButtonName = self.CreateButton('backup bd', backup_bd_button_name)
self.m_BackupBDMessage = self.CreateMessage('backup bd', backup_bd_message) self.m_BackupBDMessage = self.CreateMessage('backup bd', backup_bd_message)

16
bot_modules/comments.py

@ -4,7 +4,7 @@
# Комментарии # Комментарии
from bot_sys import bot_bd, keyboard, user_access, user_messages, bd_table 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 import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup 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' 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 = { button_names = {
mod_table_operate.ButtonNames.START: "⚏ Комментарии", mod_simple_message.ButtonNames.START: "⚏ Комментарии",
mod_table_operate.ButtonNames.LIST: "📃 Список комментариев", mod_table_operate.ButtonNames.LIST: "📃 Список комментариев",
mod_table_operate.ButtonNames.ADD: "☑ Добавить комментарий", mod_table_operate.ButtonNames.ADD: "☑ Добавить комментарий",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать комментарий", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать комментарий",
@ -68,8 +74,8 @@ button_names = {
} }
messages = { messages = {
mod_table_operate.Messages.START: f''' mod_simple_message.Messages.START: f'''
<b>{button_names[mod_table_operate.ButtonNames.START]}</b> <b>{button_names[mod_simple_message.ButtonNames.START]}</b>
''', ''',
mod_table_operate.Messages.SELECT: ''' mod_table_operate.Messages.SELECT: '''

21
bot_modules/groups.py

@ -29,12 +29,6 @@ create_datetime_field = 'createDateTime'
# --------------------------------------------------------- # ---------------------------------------------------------
# Сообщения # Сообщения
start_message = '''
<b>Группы пользователей находятся в стадии разработки</b>
Пока можете воспользоваться хардкорным способом через запросы к БД
'''
request_start_message = ''' request_start_message = '''
**Задайте запрос к БД** **Задайте запрос к БД**
@ -53,15 +47,26 @@ help_message = '''
`user_in_groups(user_id, group_id)` - содержит соответсвия ID пользователей и групп `user_in_groups(user_id, group_id)` - содержит соответсвия ID пользователей и групп
''' '''
start_button_name = "▦ Группы пользователей"
sql_request_button_name = "⛃ Запрос к БД для редактирования групп" sql_request_button_name = "⛃ Запрос к БД для редактирования групп"
help_button_name = "📄 Информация по группам" help_button_name = "📄 Информация по группам"
button_names = {
mod_simple_message.ButtonNames.START: "▦ Группы пользователей",
}
messages = {
mod_simple_message.Messages.START: '''
<b>Группы пользователей находятся в стадии разработки</b>
Пока можете воспользоваться хардкорным способом через запросы к БД
''',
}
init_access = f'{user_access.user_access_group_new}=-' init_access = f'{user_access.user_access_group_new}=-'
class ModuleGroups(mod_simple_message.SimpleMessageModule): class ModuleGroups(mod_simple_message.SimpleMessageModule):
def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): 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_SqlRequestButtonName = self.CreateButton('sql request', sql_request_button_name)
self.m_RequestStartMessage = self.CreateMessage('equest start', request_start_message) self.m_RequestStartMessage = self.CreateMessage('equest start', request_start_message)

32
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 bot_modules import access_utils, mod_interface
from template import simple_message, bd_item 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): 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_ChildModuleNameList = a_ChildModuleNameList
self.m_InitAccess = a_InitAccess self.m_InitAccess = a_InitAccess
self.m_Bot = a_Bot self.m_Bot = a_Bot
@ -17,8 +26,13 @@ class SimpleMessageModule(mod_interface.IModule):
self.m_BotButtons = a_BotButtons self.m_BotButtons = a_BotButtons
self.m_Log = a_Log self.m_Log = a_Log
self.m_StartButtonName = self.CreateButton('start', a_StartButtonName) self.m_Buttons = {}
self.m_StartMessage = self.CreateMessage('start', a_StartMessage) 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): async def StartMessageHandler(a_Message, state = None):
return await self.StartMessageHandler(a_Message, state) return await self.StartMessageHandler(a_Message, state)
@ -42,7 +56,13 @@ class SimpleMessageModule(mod_interface.IModule):
# Основной обработчик главного сообщения # Основной обработчик главного сообщения
async def StartMessageHandler(self, a_Message, state = None): 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): 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()} {a_MessageName}', a_MessageDesc, self.m_Log.GetTimeNow())
@ -78,12 +98,12 @@ class SimpleMessageModule(mod_interface.IModule):
def GetModuleButtons(self): def GetModuleButtons(self):
return [ 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): def RegisterHandlers(self):
self.m_Bot.RegisterMessageHandler( self.m_Bot.RegisterMessageHandler(
self.m_StartMessageHandler, self.m_StartMessageHandler,
bd_item.GetCheckForTextFunc(self.m_StartButtonName) bd_item.GetCheckForTextFunc(self.GetButton(ButtonNames.START))
) )

56
bot_modules/mod_table_operate.py

@ -11,7 +11,6 @@ from enum import Enum
from enum import auto from enum import auto
class ButtonNames(Enum): class ButtonNames(Enum):
START = auto()
LIST = auto() LIST = auto()
ADD = auto() ADD = auto()
EDIT = auto() EDIT = auto()
@ -19,10 +18,10 @@ class ButtonNames(Enum):
EDIT_NAME = auto() EDIT_NAME = auto()
EDIT_DESC = auto() EDIT_DESC = auto()
EDIT_ACCESS = auto() EDIT_ACCESS = auto()
EDIT_DEFAULT_ACCESS = auto()
DEL = auto() DEL = auto()
class Messages(Enum): class Messages(Enum):
START = auto()
SELECT = auto() SELECT = auto()
ERROR_FIND = auto() ERROR_FIND = auto()
OPEN = auto() OPEN = auto()
@ -36,21 +35,22 @@ class Messages(Enum):
EDIT_NAME = auto() EDIT_NAME = auto()
EDIT_DESC = auto() EDIT_DESC = auto()
EDIT_ACCESS = auto() EDIT_ACCESS = auto()
EDIT_DEFAULT_ACCESS = auto()
SUCCESS_EDIT = auto() SUCCESS_EDIT = auto()
SELECT_TO_DELETE = auto() SELECT_TO_DELETE = auto()
SUCCESS_DELETE = auto() SUCCESS_DELETE = auto()
class FSMs: class FSMs(Enum):
def __init__(self, a_FSMCreate, a_FSMEditName, a_FSMEditDesc, a_FSMEditPhoto, a_FSMEditAccess): CREATE = auto()
self.m_FSMCreate = a_FSMCreate EDIT_PHOTO = auto()
self.m_FSMEditName = a_FSMEditName EDIT_NAME = auto()
self.m_FSMEditDesc = a_FSMEditDesc EDIT_DESC = auto()
self.m_FSMEditPhoto = a_FSMEditPhoto EDIT_ACCESS = auto()
self.m_FSMEditAccess = a_FSMEditAccess EDIT_DEFAULT_ACCESS = auto()
class TableOperateModule(mod_simple_message.SimpleMessageModule): 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_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_Table = a_Table
self.m_FSMs = a_FSMs self.m_FSMs = a_FSMs
self.m_EditModuleNameList = a_EditModuleNameList self.m_EditModuleNameList = a_EditModuleNameList
@ -58,14 +58,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
self.m_ParentModName = a_ParentModName self.m_ParentModName = a_ParentModName
self.m_SelectPrefix = '' 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): def GetEditKeyboardButtons(a_Message, a_UserGroups):
return self.GetEditKeyboardButtons(a_Message, a_UserGroups) return self.GetEditKeyboardButtons(a_Message, a_UserGroups)
self.m_GetEditKeyboardButtonsFunc = GetEditKeyboardButtons self.m_GetEditKeyboardButtonsFunc = GetEditKeyboardButtons
@ -86,12 +78,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
return self.AddBDItemFunc(a_ItemData, a_UserID) return self.AddBDItemFunc(a_ItemData, a_UserID)
self.m_AddBDItemFunc = AddBDItemFunc self.m_AddBDItemFunc = AddBDItemFunc
def GetFSM(self, a_FSMName):
def GetButton(self, a_ButtonName): return self.m_FSMs.get(a_FSMName, None)
return self.m_Buttons.get(a_ButtonName, None)
def GetMessage(self, a_MessageNames):
return self.m_Messages.get(a_MessageNames, None)
def GetInitBDCommands(self): def GetInitBDCommands(self):
return super(). GetInitBDCommands() + [ return super(). GetInitBDCommands() + [
@ -242,6 +230,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC) desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC)
photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO) photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO)
access_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ACCESS) 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_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
parent_table_name = None parent_table_name = None
@ -287,7 +276,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
GetAccess, \ GetAccess, \
defaul_keyboard_func\ defaul_keyboard_func\
) )
self.m_SelectPrefix = a_Prefix self.m_SelectPrefix = a_Prefix
# Удаление # Удаление
a_ButtonName = self.GetButton(ButtonNames.DEL) a_ButtonName = self.GetButton(ButtonNames.DEL)
@ -314,10 +303,10 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
bd_item_add.AddBDItem3RegisterHandlers(self.m_Bot, \ bd_item_add.AddBDItem3RegisterHandlers(self.m_Bot, \
check_func, \ check_func, \
self.m_FSMs.m_FSMCreate, \ self.GetFSM(FSMs.CREATE), \
self.m_FSMs.m_FSMCreate.name,\ self.GetFSM(FSMs.CREATE).name,\
self.m_FSMs.m_FSMCreate.desc, \ self.GetFSM(FSMs.CREATE).desc, \
self.m_FSMs.m_FSMCreate.photo,\ self.GetFSM(FSMs.CREATE).photo,\
self.m_AddBDItemFunc, \ self.m_AddBDItemFunc, \
self.ShowMessageTemplate(self.GetMessage(Messages.CREATE_NAME)), \ self.ShowMessageTemplate(self.GetMessage(Messages.CREATE_NAME)), \
self.ShowMessageTemplate(self.GetMessage(Messages.CREATE_DESC)), \ self.ShowMessageTemplate(self.GetMessage(Messages.CREATE_DESC)), \
@ -376,8 +365,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
bd_item.GetCheckForTextFunc(a_ButtonName)\ 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_NAME), self.GetFSM(FSMs.EDIT_NAME), 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_DESC), self.GetFSM(FSMs.EDIT_DESC), 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_PHOTO), self.GetFSM(FSMs.EDIT_PHOTO), 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_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)

26
bot_modules/needs.py

@ -4,26 +4,26 @@
# Потребности # Потребности
from bot_sys import bot_bd, keyboard, user_access, user_messages, bd_table 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 import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup from aiogram.dispatcher.filters.state import State, StatesGroup
class FSMCreateNeeds(StatesGroup): class FSMCreateNeed(StatesGroup):
name = State() name = State()
desc = State() desc = State()
photo = State() photo = State()
class FSMEditNeedsPhotoItem(StatesGroup): class FSMEditNeedPhotoItem(StatesGroup):
item_field = State() item_field = State()
class FSMEditNeedsNameItem(StatesGroup): class FSMEditNeedNameItem(StatesGroup):
item_field = State() item_field = State()
class FSMEditNeedsDescItem(StatesGroup): class FSMEditNeedDescItem(StatesGroup):
item_field = State() item_field = State()
class FSMEditNeedsAccessItem(StatesGroup): class FSMEditNeedAccessItem(StatesGroup):
item_field = State() item_field = State()
# --------------------------------------------------------- # ---------------------------------------------------------
# БД # БД
@ -50,13 +50,19 @@ table = bd_table.Table(table_name, [
init_access = f'{user_access.user_access_group_new}=va' 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 = { button_names = {
mod_table_operate.ButtonNames.START: "👉 Потребности", mod_simple_message.ButtonNames.START: "👉 Потребности",
mod_table_operate.ButtonNames.LIST: "📃 Список потребностей", mod_table_operate.ButtonNames.LIST: "📃 Список потребностей",
mod_table_operate.ButtonNames.ADD: "☑ Добавить потребность", mod_table_operate.ButtonNames.ADD: "☑ Добавить потребность",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать потребность", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать потребность",
@ -68,8 +74,8 @@ button_names = {
} }
messages = { messages = {
mod_table_operate.Messages.START: f''' mod_simple_message.Messages.START: f'''
<b>{button_names[mod_table_operate.ButtonNames.START]}</b> <b>{button_names[mod_simple_message.ButtonNames.START]}</b>
''', ''',
mod_table_operate.Messages.SELECT: ''' mod_table_operate.Messages.SELECT: '''

16
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), 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'''
<b>📰 Профиль:</b> <b>📰 Профиль:</b>
<b>ID:</b> #{key_name} <b>ID:</b> #{key_name}
@ -41,15 +46,14 @@ start_message = f'''
<b>Имя2:</b> #{name2_field} <b>Имя2:</b> #{name2_field}
<b>Код языка:</b> #{language_code_field} <b>Код языка:</b> #{language_code_field}
<b>Дата добавления:</b> #{create_datetime_field} <b>Дата добавления:</b> #{create_datetime_field}
''' ''',
}
start_button_name = "📰 Профиль"
init_access = f'{user_access.user_access_group_new}=+' init_access = f'{user_access.user_access_group_new}=+'
class ModuleProfile(mod_simple_message.SimpleMessageModule): class ModuleProfile(mod_simple_message.SimpleMessageModule):
def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): 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): def GetInitBDCommands(self):
return super(). GetInitBDCommands() + [ return super(). GetInitBDCommands() + [
@ -64,7 +68,7 @@ class ModuleProfile(mod_simple_message.SimpleMessageModule):
user_info = GetUserInfo(self.m_Bot, a_Message.from_user.id) user_info = GetUserInfo(self.m_Bot, a_Message.from_user.id)
lang = str(a_Message.from_user.language_code) lang = str(a_Message.from_user.language_code)
if not user_info is None: if not user_info is None:
msg = self.m_StartMessage msg = self.GetButton(mod_simple_message.ButtonNames.START)
msg = msg.GetMessageForLang(lang).StaticCopy() msg = msg.GetMessageForLang(lang).StaticCopy()
msg.UpdateDesc(table.ReplaceAllFieldTags(msg.GetDesc(), user_info)) msg.UpdateDesc(table.ReplaceAllFieldTags(msg.GetDesc(), user_info))
return simple_message.WorkFuncResult(msg, item_access = str(user_info[table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)])) return simple_message.WorkFuncResult(msg, item_access = str(user_info[table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)]))

16
bot_modules/projects.py

@ -4,7 +4,7 @@
# Проекты # Проекты
from bot_sys import bot_bd, keyboard, user_access, user_messages, bd_table 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 import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup 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' 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 = { button_names = {
mod_table_operate.ButtonNames.START: "🟥 Проекты", mod_simple_message.ButtonNames.START: "🟥 Проекты",
mod_table_operate.ButtonNames.LIST: "📃 Список проектов", mod_table_operate.ButtonNames.LIST: "📃 Список проектов",
mod_table_operate.ButtonNames.ADD: "✅ Добавить проект", mod_table_operate.ButtonNames.ADD: "✅ Добавить проект",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать проект", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать проект",
@ -66,8 +72,8 @@ button_names = {
} }
messages = { messages = {
mod_table_operate.Messages.START: f''' mod_simple_message.Messages.START: f'''
<b>{button_names[mod_table_operate.ButtonNames.START]}</b> <b>{button_names[mod_simple_message.ButtonNames.START]}</b>
''', ''',
mod_table_operate.Messages.SELECT: ''' mod_table_operate.Messages.SELECT: '''

14
bot_modules/start.py

@ -7,18 +7,22 @@ from bot_sys import user_access
from bot_modules import mod_simple_message, profile from bot_modules import mod_simple_message, profile
from template import bd_item from template import bd_item
start_message = ''' button_names = {
<b>Добро пожаловать!</b> mod_simple_message.ButtonNames.START: "☰ Главное меню",
}
Выберите возможные действия на кнопках ниже ''' messages = {
mod_simple_message.Messages.START: f'''
<b>Добро пожаловать!</b>
start_button_name = "☰ Главное меню" Выберите возможные действия на кнопках ниже ''',
}
init_access = f'{user_access.user_access_group_all}=+' init_access = f'{user_access.user_access_group_all}=+'
class ModuleStart(mod_simple_message.SimpleMessageModule): class ModuleStart(mod_simple_message.SimpleMessageModule):
def __init__(self, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): 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): def GetName(self):
return 'start' return 'start'

26
bot_modules/tasks.py

@ -4,26 +4,26 @@
# Задачи # Задачи
from bot_sys import bot_bd, keyboard, user_access, user_messages, bd_table 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 import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup from aiogram.dispatcher.filters.state import State, StatesGroup
class FSMCreateTasks(StatesGroup): class FSMCreateTask(StatesGroup):
name = State() name = State()
desc = State() desc = State()
photo = State() photo = State()
class FSMEditTasksPhotoItem(StatesGroup): class FSMEditTaskPhotoItem(StatesGroup):
item_field = State() item_field = State()
class FSMEditTasksNameItem(StatesGroup): class FSMEditTaskNameItem(StatesGroup):
item_field = State() item_field = State()
class FSMEditTasksDescItem(StatesGroup): class FSMEditTaskDescItem(StatesGroup):
item_field = State() item_field = State()
class FSMEditTasksAccessItem(StatesGroup): class FSMEditTaskAccessItem(StatesGroup):
item_field = State() item_field = State()
# --------------------------------------------------------- # ---------------------------------------------------------
# БД # БД
@ -50,13 +50,19 @@ table = bd_table.Table(table_name, [
init_access = f'{user_access.user_access_group_new}=va' 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 = { button_names = {
mod_table_operate.ButtonNames.START: "✎ Задачи", mod_simple_message.ButtonNames.START: "✎ Задачи",
mod_table_operate.ButtonNames.LIST: "📃 Список задач", mod_table_operate.ButtonNames.LIST: "📃 Список задач",
mod_table_operate.ButtonNames.ADD: "☑ Добавить задачу", mod_table_operate.ButtonNames.ADD: "☑ Добавить задачу",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать задачу", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать задачу",
@ -68,8 +74,8 @@ button_names = {
} }
messages = { messages = {
mod_table_operate.Messages.START: f''' mod_simple_message.Messages.START: f'''
<b>{button_names[mod_table_operate.ButtonNames.START]}</b> <b>{button_names[mod_simple_message.ButtonNames.START]}</b>
''', ''',
mod_table_operate.Messages.SELECT: ''' mod_table_operate.Messages.SELECT: '''

1
bot_sys/bd_table.py

@ -16,6 +16,7 @@ class TableFieldDestiny(Enum):
DESC = auto() DESC = auto()
PHOTO = auto() PHOTO = auto()
ACCESS = auto() ACCESS = auto()
DEFAULT_ACCESS = auto()
CREATE_DATE = auto() CREATE_DATE = auto()
PARENT_ID = auto() PARENT_ID = auto()
OTHER = auto() OTHER = auto()

Loading…
Cancel
Save