Browse Source

Удалены FSM машины состояний. Теперь они создаются автоматически

Изменены названия сообщений и кнопок
admin_backend
Alexei 2 years ago
parent
commit
3c5b3a8b1e
  1. 12
      bot_modules/access.py
  2. 33
      bot_modules/buttons.py
  3. 29
      bot_modules/comments.py
  4. 29
      bot_modules/languages.py
  5. 33
      bot_modules/messages.py
  6. 4
      bot_modules/mod_simple_message.py
  7. 45
      bot_modules/mod_table_operate.py
  8. 29
      bot_modules/needs.py
  9. 6
      bot_modules/profile.py
  10. 29
      bot_modules/projects.py
  11. 29
      bot_modules/tasks.py
  12. 6
      bot_modules/users_groups_agregator.py
  13. 15
      main.py

12
bot_modules/access.py

@ -13,11 +13,6 @@ from aiogram.dispatcher.filters.state import State, StatesGroup
class FSMRequestToBDAccess(StatesGroup): class FSMRequestToBDAccess(StatesGroup):
sqlRequest = State() sqlRequest = State()
class FSMEditAccessItem(StatesGroup):
item_field = State()
class FSMEditDefaultAccessItem(StatesGroup):
item_field = State()
# --------------------------------------------------------- # ---------------------------------------------------------
# БД # БД
module_name = 'access' module_name = 'access'
@ -107,16 +102,11 @@ messages = {
mod_table_operate.Messages.SUCCESS_EDIT: moduleaccess_success_edit_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_table_operate.TableOperateModule): 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__(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_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)

33
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 bot_modules import mod_table_operate, mod_simple_message, access_utils
from template import bd_item 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' module_name = 'buttons'
@ -62,14 +39,6 @@ table = bd_table.Table(table_name, [
init_access = f'{user_access.user_access_group_all}=-' 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): 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): 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): def GetName(self):
return module_name return module_name

29
bot_modules/comments.py

@ -6,25 +6,6 @@
from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_sys import bot_bd, keyboard, user_access, bd_table
from bot_modules import mod_table_operate, mod_simple_message 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' module_name = 'comments'
@ -50,14 +31,6 @@ 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.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): 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): 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): def GetName(self):
return module_name return module_name

29
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 bot_modules import mod_table_operate, mod_simple_message, access_utils
from template import bd_item 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' module_name = 'languages'
@ -55,14 +36,6 @@ table = bd_table.Table(table_name, [
init_access = f'{user_access.user_access_group_all}=-' 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): 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): 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 = {} self.m_LanguageIDs = {}
def GetName(self): def GetName(self):

33
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 bot_modules import mod_table_operate, mod_simple_message, access_utils
from template import bd_item 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' module_name = 'messages'
@ -62,14 +39,6 @@ table = bd_table.Table(table_name, [
init_access = f'{user_access.user_access_group_all}=-' 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): 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): 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): def GetName(self):
return module_name return module_name

4
bot_modules/mod_simple_message.py

@ -65,14 +65,14 @@ class SimpleMessageModule(mod_interface.IModule):
return self.m_Messages.get(a_MessageNames, None) 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()} {str(a_MessageName).replace("Messages.", "")}', a_MessageDesc, self.m_Log.GetTimeNow())
return msg return msg
def CreateButton(self, a_ButtonName, a_ButtonDesc): def CreateButton(self, a_ButtonName, a_ButtonDesc):
assert len(a_ButtonDesc) < 41 # Телеграм не поддерживает больше assert len(a_ButtonDesc) < 41 # Телеграм не поддерживает больше
assert a_ButtonDesc[0] != ' ' # Телеграм не поддерживает пробелы в начале assert a_ButtonDesc[0] != ' ' # Телеграм не поддерживает пробелы в начале
assert a_ButtonDesc[-1:] != ' ' # Телеграм не поддерживает пробелы в конце 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 return btn
def GetModule(self, a_ModName): def GetModule(self, a_ModName):

45
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 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 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 Enum
from enum import auto from enum import auto
@ -48,11 +51,49 @@ class FSMs(Enum):
EDIT_ACCESS = auto() EDIT_ACCESS = auto()
EDIT_DEFAULT_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): 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) 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 = MakeFSMs(self.GetName())
self.m_EditModuleNameList = a_EditModuleNameList self.m_EditModuleNameList = a_EditModuleNameList
self.m_ChildModName = a_ChildModName self.m_ChildModName = a_ChildModName
self.m_ParentModName = a_ParentModName self.m_ParentModName = a_ParentModName

29
bot_modules/needs.py

@ -6,25 +6,6 @@
from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_sys import bot_bd, keyboard, user_access, bd_table
from bot_modules import mod_table_operate, mod_simple_message 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' module_name = 'needs'
@ -50,14 +31,6 @@ 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.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): 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): 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): def GetName(self):
return module_name return module_name

6
bot_modules/profile.py

@ -4,7 +4,7 @@
# Профиль пользователя # Профиль пользователя
from bot_sys import user_access, bot_bd, bd_table 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 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_groups = groups_utils.GetUserGroupData(a_Bot, a_UserID)
# Если пользователь не состоит ни в одной группе, то добавляем его в группу user_access.user_access_group_new # Если пользователь не состоит ни в одной группе, то добавляем его в группу user_access.user_access_group_new
if len(user_groups.group_names_list) == 0: 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]) param = [user_access.user_access_group_new])
if new_group_id and new_group_id[0]: 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))) commit=True, param = (a_UserID, new_group_id[0][0], access_utils.GetItemDefaultAccessForModule(a_Bot, module_name)))
def GetUserInfo(a_Bot, a_UserID): def GetUserInfo(a_Bot, a_UserID):

29
bot_modules/projects.py

@ -6,25 +6,6 @@
from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_sys import bot_bd, keyboard, user_access, bd_table
from bot_modules import mod_table_operate, mod_simple_message 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' module_name = 'projects'
@ -48,14 +29,6 @@ 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.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): 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): 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): def GetName(self):
return module_name return module_name

29
bot_modules/tasks.py

@ -6,25 +6,6 @@
from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_sys import bot_bd, keyboard, user_access, bd_table
from bot_modules import mod_table_operate, mod_simple_message 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' module_name = 'tasks'
@ -50,14 +31,6 @@ 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.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): 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): 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): def GetName(self):
return module_name return module_name

6
bot_modules/groups.py → 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_groups_name = 'user_groups'
table_user_in_groups_name = 'user_in_groups' table_user_in_groups_name = 'user_in_groups'
@ -64,7 +64,7 @@ messages = {
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 ModuleUsersGroupsAgregator(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__(messages, button_names, 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)
@ -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_SqlRequestButtonName, user_access.AccessMode.EDIT, self.GetAccess()),
keyboard.ButtonWithAccess(self.m_HelpButtonName , user_access.AccessMode.VIEW, 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): def RegisterHandlers(self):
super().RegisterHandlers() super().RegisterHandlers()

15
main.py

@ -1,22 +1,22 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru> # Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru>
log_start_message = 'Бот успешно запущен!'
import os import os
from bot_sys import config, log, aiogram_bot, bot_messages, bd_table, user_access 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' bd_file_name = 'bot.db'
log_file_name = 'log.txt' log_file_name = 'log.txt'
default_language = 'ru'
g_Log = log.Log(log_file_name) g_Log = log.Log(log_file_name)
g_Bot = aiogram_bot.AiogramBot(config.GetTelegramBotApiToken(), bd_file_name, config.GetRootIDs(), g_Log) 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_BotMessages = bot_messages.BotMessages(default_language)
g_BotButtons = 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 mod_buttons_name = buttons.module_name
start_mod_list = [mod_start_name] start_mod_list = [mod_start_name]
mod_access = access.ModuleAccess(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) mod_access = access.ModuleAccess(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
g_ModuleAgregator.AddModule(mod_access) 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) 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) mod_profile = profile.ModuleProfile(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
g_ModuleAgregator.AddModule(mod_profile) g_ModuleAgregator.AddModule(mod_profile)

Loading…
Cancel
Save