Browse Source

Задачи в первом приближении. Пока не работают.

test_bot
Alexei 2 years ago
parent
commit
f5cb6f1c6a
  1. 7
      bot_modules/access.py
  2. 2
      bot_modules/backup.py
  3. 2
      bot_modules/groups.py
  4. 2
      bot_modules/profile.py
  5. 32
      bot_modules/projects.py
  6. 2
      bot_modules/start.py
  7. 284
      bot_modules/tasks.py
  8. 4
      template/bd_item.py
  9. 2
      template/bd_item_add.py
  10. 2
      template/bd_item_delete.py
  11. 2
      template/bd_item_edit.py
  12. 13
      template/bd_item_select.py
  13. 21
      template/bd_item_view.py
  14. 6
      template/file_message.py
  15. 8
      template/simple_message.py
  16. 12
      template/sql_request.py

7
bot_modules/access.py

@ -109,7 +109,7 @@ moduleaccess_success_edit_message = '''✅ Проект успешно отре
# --------------------------------------------------------- # ---------------------------------------------------------
# Работа с кнопками # Работа с кнопками
def GetEditAccessKeyboardButtons(a_UserGroups): def GetEditAccessKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = [ cur_buttons = [
keyboard.ButtonWithAccess(sql_request_button_name, user_access.AccessMode.ACCEES_EDIT, GetAccess()), keyboard.ButtonWithAccess(sql_request_button_name, user_access.AccessMode.ACCEES_EDIT, GetAccess()),
keyboard.ButtonWithAccess(edit_moduleaccess_access_button_name, user_access.AccessMode.ACCEES_EDIT, GetAccess()), keyboard.ButtonWithAccess(edit_moduleaccess_access_button_name, user_access.AccessMode.ACCEES_EDIT, GetAccess()),
@ -185,5 +185,6 @@ def RegisterHandlers(dp : Dispatcher):
sql_request.RequestToBDRegisterHandlers(dp, sql_request_button_name, request_start_message, FSMRequestToBDAccess, defaul_keyboard_func, user_access.AccessMode.ACCEES_EDIT, GetAccess) sql_request.RequestToBDRegisterHandlers(dp, sql_request_button_name, request_start_message, FSMRequestToBDAccess, defaul_keyboard_func, user_access.AccessMode.ACCEES_EDIT, GetAccess)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditAccessItem, edit_moduleaccess_access_button_name, moduleaccess_select_to_edit_message, ShowMessageTemplate(moduleaccess_edit_access_message), ShowMessageTemplate(moduleaccess_success_edit_message), table_name, mod_name_field, moduleaccess_field, GetButtonNameAndKeyValueAndAccess, GetAccess, defaul_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) edit_keyboard_func = defaul_keyboard_func
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditDefaultAccessItem, edit_moduleaccess_default_access_button_name, moduleaccess_select_to_edit_message, ShowMessageTemplate(moduleaccess_edit_default_access_message), ShowMessageTemplate(moduleaccess_success_edit_message), table_name, mod_name_field, mod_default_access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, defaul_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditAccessItem, edit_moduleaccess_access_button_name, moduleaccess_select_to_edit_message, ShowMessageTemplate(moduleaccess_edit_access_message), ShowMessageTemplate(moduleaccess_success_edit_message), table_name, mod_name_field, moduleaccess_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditDefaultAccessItem, edit_moduleaccess_default_access_button_name, moduleaccess_select_to_edit_message, ShowMessageTemplate(moduleaccess_edit_default_access_message), ShowMessageTemplate(moduleaccess_success_edit_message), table_name, mod_name_field, mod_default_access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text)

2
bot_modules/backup.py

@ -51,7 +51,7 @@ backup_log_button_name = "📃 Логи"
# --------------------------------------------------------- # ---------------------------------------------------------
# Работа с кнопками # Работа с кнопками
def GetBackupKeyboardButtons(a_UserGroups): def GetBackupKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = [ cur_buttons = [
keyboard.ButtonWithAccess(backup_bd_button_name, user_access.AccessMode.EDIT, GetAccess()), keyboard.ButtonWithAccess(backup_bd_button_name, user_access.AccessMode.EDIT, GetAccess()),
keyboard.ButtonWithAccess(backup_log_button_name, user_access.AccessMode.EDIT, GetAccess()) keyboard.ButtonWithAccess(backup_log_button_name, user_access.AccessMode.EDIT, GetAccess())

2
bot_modules/groups.py

@ -80,7 +80,7 @@ help_button_name = "📄 Информация по группам"
# --------------------------------------------------------- # ---------------------------------------------------------
# Работа с кнопками # Работа с кнопками
def GetEditGroupKeyboardButtons(a_UserGroups): def GetEditGroupKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = [ cur_buttons = [
keyboard.ButtonWithAccess(sql_request_button_name, user_access.AccessMode.EDIT, GetAccess()), keyboard.ButtonWithAccess(sql_request_button_name, user_access.AccessMode.EDIT, GetAccess()),
keyboard.ButtonWithAccess(help_button_name, user_access.AccessMode.VIEW, GetAccess()) keyboard.ButtonWithAccess(help_button_name, user_access.AccessMode.VIEW, GetAccess())

2
bot_modules/profile.py

@ -57,7 +57,7 @@ user_profile_button_name = "📰 Профиль"
# --------------------------------------------------------- # ---------------------------------------------------------
# Работа с кнопками # Работа с кнопками
def GetStartKeyboardButtons(a_UserGroups): def GetStartKeyboardButtons(a_Message, a_UserGroups):
mods = [start] mods = [start]
return keyboard.MakeKeyboardForMods(mods, a_UserGroups) return keyboard.MakeKeyboardForMods(mods, a_UserGroups)

32
bot_modules/projects.py

@ -118,13 +118,13 @@ project_select_to_edit_message = '''
Выберите проект, который вы хотите отредактировать. Выберите проект, который вы хотите отредактировать.
''' '''
edit_project_photo_button_name = "☐ Изменить изображение" edit_project_photo_button_name = "☐ Изменить изображение в проекте"
project_edit_photo_message = ''' project_edit_photo_message = '''
Загрузите новую обложку для проекта (Фото): Загрузите новую обложку для проекта (Фото):
Она будет отображаться в его описании. Она будет отображаться в его описании.
''' '''
edit_project_name_button_name = "≂ Изменить название" edit_project_name_button_name = "≂ Изменить название в проекте"
project_edit_name_message = f''' project_edit_name_message = f'''
Текущее название проекта: Текущее название проекта:
#{name_field} #{name_field}
@ -132,7 +132,7 @@ project_edit_name_message = f'''
Введите новое название проекта: Введите новое название проекта:
''' '''
edit_project_desc_button_name = "𝌴 Изменить описание" edit_project_desc_button_name = "𝌴 Изменить описание в проекте"
project_edit_desc_message = f''' project_edit_desc_message = f'''
Текущее описание проекта: Текущее описание проекта:
#{desc_field} #{desc_field}
@ -140,7 +140,7 @@ project_edit_desc_message = f'''
Введите новое описание проекта: Введите новое описание проекта:
''' '''
edit_project_access_button_name = "✋ Изменить доступ" edit_project_access_button_name = "✋ Изменить доступ к проекту"
project_edit_access_message = f''' project_edit_access_message = f'''
Текущий доступ к проекту: Текущий доступ к проекту:
#{access_field} #{access_field}
@ -165,7 +165,7 @@ project_success_delete_message = '''✅ Проект успешно удалён
# --------------------------------------------------------- # ---------------------------------------------------------
# Работа с кнопками # Работа с кнопками
def GetEditProjectKeyboardButtons(a_UserGroups): def GetEditProjectKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = GetModuleButtons() + [ cur_buttons = GetModuleButtons() + [
keyboard.ButtonWithAccess(edit_project_photo_button_name, user_access.AccessMode.EDIT, GetAccess()), keyboard.ButtonWithAccess(edit_project_photo_button_name, user_access.AccessMode.EDIT, GetAccess()),
keyboard.ButtonWithAccess(edit_project_name_button_name, user_access.AccessMode.EDIT, GetAccess()), keyboard.ButtonWithAccess(edit_project_name_button_name, user_access.AccessMode.EDIT, GetAccess()),
@ -175,7 +175,7 @@ def GetEditProjectKeyboardButtons(a_UserGroups):
mods = [start] mods = [start]
return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups) return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups)
def GetStartProjectKeyboardButtons(a_UserGroups): def GetStartProjectKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = [ cur_buttons = [
keyboard.ButtonWithAccess(list_project_button_name, user_access.AccessMode.VIEW, GetAccess()), keyboard.ButtonWithAccess(list_project_button_name, user_access.AccessMode.VIEW, GetAccess()),
keyboard.ButtonWithAccess(add_project_button_name, user_access.AccessMode.ADD, GetAccess()), keyboard.ButtonWithAccess(add_project_button_name, user_access.AccessMode.ADD, GetAccess()),
@ -193,7 +193,7 @@ select_handler = 0
async def ProjectsOpen(a_Message : types.message, state = None): async def ProjectsOpen(a_Message : types.message, state = None):
user_id = str(a_Message.from_user.id) user_id = str(a_Message.from_user.id)
user_groups = groups.GetUserGroupData(user_id) user_groups = groups.GetUserGroupData(user_id)
await a_Message.answer(base_project_message, reply_markup = GetStartProjectKeyboardButtons(user_groups)) await a_Message.answer(base_project_message, reply_markup = GetStartProjectKeyboardButtons(a_Message, user_groups))
await select_handler(a_Message) await select_handler(a_Message)
return None return None
@ -261,22 +261,24 @@ def GetModuleButtons():
# Обработка кнопок # Обработка кнопок
def RegisterHandlers(dp : Dispatcher): def RegisterHandlers(dp : Dispatcher):
defaul_keyboard_func = GetStartProjectKeyboardButtons
# Список проектов # Список проектов
dp.register_message_handler(simple_message.SimpleMessageTemplate(ProjectsOpen, GetStartProjectKeyboardButtons, GetAccess), text = projects_button_name) dp.register_message_handler(simple_message.SimpleMessageTemplate(ProjectsOpen, defaul_keyboard_func, GetAccess), text = projects_button_name)
global select_handler global select_handler
select_handler = bd_item_view.SelectAndShowBDItemRegisterHandlers(dp, list_project_button_name, table_name, key_name, ShowMessageTemplate(project_open_message), GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, GetStartProjectKeyboardButtons) select_handler = bd_item_view.SelectAndShowBDItemRegisterHandlers(dp, list_project_button_name, table_name, key_name, ShowMessageTemplate(project_open_message), GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func)
# Удаление проекта # Удаление проекта
bd_item_delete.DeleteBDItemRegisterHandlers(dp, del_project_button_name, table_name, key_name, ProjectPreDelete, ProjectPostDelete, GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, GetStartProjectKeyboardButtons) bd_item_delete.DeleteBDItemRegisterHandlers(dp, del_project_button_name, table_name, key_name, ProjectPreDelete, ProjectPostDelete, GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func)
# Добавление проекта # Добавление проекта
bd_item_add.AddBDItem3RegisterHandlers(dp, FSMCreateProject, FSMCreateProject.name, FSMCreateProject.desc, FSMCreateProject.photo, add_project_button_name, AddBDItemFunc, SimpleMessageTemplate(project_create_name_message), SimpleMessageTemplate(project_create_desc_message), SimpleMessageTemplate(project_create_photo_message), SimpleMessageTemplate(project_success_create_message), table_name, key_name, name_field, desc_field, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, GetStartProjectKeyboardButtons) bd_item_add.AddBDItem3RegisterHandlers(dp, FSMCreateProject, FSMCreateProject.name, FSMCreateProject.desc, FSMCreateProject.photo, add_project_button_name, AddBDItemFunc, SimpleMessageTemplate(project_create_name_message), SimpleMessageTemplate(project_create_desc_message), SimpleMessageTemplate(project_create_photo_message), SimpleMessageTemplate(project_success_create_message), table_name, key_name, name_field, desc_field, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, GetStartProjectKeyboardButtons)
edit_keyboard_func = GetEditProjectKeyboardButtons
# Редактирование проекта # Редактирование проекта
dp.register_message_handler(simple_message.InfoMessageTemplate(project_start_edit_message, GetEditProjectKeyboardButtons, GetAccess, access_mode = user_access.AccessMode.EDIT), text = edit_project_button_name) dp.register_message_handler(simple_message.InfoMessageTemplate(project_start_edit_message, edit_keyboard_func, GetAccess, access_mode = user_access.AccessMode.EDIT), text = edit_project_button_name)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditPhotoItem, edit_project_photo_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_photo_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, GetEditProjectKeyboardButtons, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.photo) bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditPhotoItem, edit_project_photo_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_photo_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.photo)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditNameItem, edit_project_name_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_name_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, name_field, GetButtonNameAndKeyValueAndAccess, GetAccess, GetEditProjectKeyboardButtons, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditNameItem, edit_project_name_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_name_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, name_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditDeskItem, edit_project_desc_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_desc_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, desc_field, GetButtonNameAndKeyValueAndAccess, GetAccess, GetEditProjectKeyboardButtons, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditDeskItem, edit_project_desc_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_desc_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, desc_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditAccessItem, edit_project_access_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_access_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, GetEditProjectKeyboardButtons, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditAccessItem, edit_project_access_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_access_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text)

2
bot_modules/start.py

@ -30,7 +30,7 @@ start_menu_button_name = "☰ Главное меню"
# --------------------------------------------------------- # ---------------------------------------------------------
# Работа с кнопками # Работа с кнопками
def GetStartKeyboardButtons(a_UserGroups): def GetStartKeyboardButtons(a_Message, a_UserGroups):
mods = [profile, projects, groups, access, backup] mods = [profile, projects, groups, access, backup]
return keyboard.MakeKeyboardForMods(mods, a_UserGroups) return keyboard.MakeKeyboardForMods(mods, a_UserGroups)

284
bot_modules/tasks.py

@ -0,0 +1,284 @@
# -*- coding: utf8 -*-
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru>
# Задачи
from bot_sys import bot_bd, log, keyboard, user_access
from bot_modules import start, access, groups
from template import bd_item_view, simple_message, bd_item_delete, bd_item_edit, bd_item, bd_item_add
from aiogram import types
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.dispatcher import Dispatcher
import sqlite3
class FSMCreateTask(StatesGroup):
name = State()
desc = State()
photo = State()
class FSMEditPhotoItem(StatesGroup):
item_id = State()
item_field = State()
class FSMEditNameItem(StatesGroup):
item_id = State()
item_field = State()
class FSMEditDeskItem(StatesGroup):
item_id = State()
item_field = State()
class FSMEditAccessItem(StatesGroup):
item_id = State()
item_field = State()
# ---------------------------------------------------------
# БД
module_name = 'tasks'
table_name = module_name
key_name = 'taskID'
name_field = 'taskName'
desc_field = 'taskDesc'
photo_field = 'taskPhoto'
access_field = 'taskAccess'
create_datetime_field = 'taskCreateDateTime'
init_bd_cmds = [f'''CREATE TABLE IF NOT EXISTS {table_name}(
{key_name} INTEGER PRIMARY KEY,
{name_field} TEXT,
{desc_field} TEXT,
{photo_field} TEXT,
{access_field} TEXT,
{create_datetime_field} TEXT
)''',
f"INSERT OR IGNORE INTO module_access (modName, modAccess, itemDefaultAccess) VALUES ('{module_name}', '{user_access.user_access_group_new}=va', '{user_access.user_access_group_new}=va');"
]
# ---------------------------------------------------------
# Сообщения
tasks_button_name = "🟥 Задачи"
base_task_message = '''
<b>🟥 Задачи</b>
'''
list_task_button_name = "📃 Список задач"
select_task_message = '''
Пожалуйста, выберите задачу:
'''
error_find_proj_message = '''
Ошибка, задача не найдена
'''
task_open_message = f'''
<b>Задача: #{name_field}</b>
#{desc_field}
Время создания: #{create_datetime_field}
'''
# Создание задачи
add_task_button_name = "✅ Добавить задачу"
task_create_name_message = '''
Создание задачи. Шаг 1
Введите название задачи:
'''
task_create_desc_message = '''
Создание задачи. Шаг 2
Введите описание задачи:
'''
task_create_photo_message = '''
Создание задачи. Шаг 3
Загрузите обложку для задачи (Фото):
Она будет отображаться в его описании.
'''
task_success_create_message = '''✅ Задача успешно добавлена!'''
# Редактирование задачи.
edit_task_button_name = "🛠 Редактировать задачу"
task_start_edit_message= '''
Пожалуйста, выберите действие:
'''
task_select_to_edit_message = '''
Выберите задачу, которую вы хотите отредактировать.
'''
edit_task_photo_button_name = "☐ Изменить изображение у задачи"
task_edit_photo_message = '''
Загрузите новую обложку для задачи (Фото):
Она будет отображаться в её описании.
'''
edit_task_name_button_name = "≂ Изменить название у задачи"
task_edit_name_message = f'''
Текущее название задачи:
#{name_field}
Введите новое название задачи:
'''
edit_task_desc_button_name = "𝌴 Изменить описание у задачи"
task_edit_desc_message = f'''
Текущее описание задачи:
#{desc_field}
Введите новое описание задачи:
'''
edit_task_access_button_name = "✋ Изменить доступ к задаче"
task_edit_access_message = f'''
Текущий доступ к задаче:
#{access_field}
{user_access.user_access_readme}
Введите новую строку доступа:
'''
task_success_edit_message = '''✅ Задача успешно отредактирован!'''
# Удаление задачи
del_task_button_name = "❌ Удалить задачу"
task_select_to_delete_message = '''
Выберите задача, который вы хотите удалить.
Все потребности в этой задачае так же будут удалены!
'''
task_success_delete_message = '''✅ Задача успешно удалена!'''
# ---------------------------------------------------------
# Работа с кнопками
def GetEditTaskKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = GetModuleButtons() + [
keyboard.ButtonWithAccess(edit_task_photo_button_name, user_access.AccessMode.EDIT, GetAccess()),
keyboard.ButtonWithAccess(edit_task_name_button_name, user_access.AccessMode.EDIT, GetAccess()),
keyboard.ButtonWithAccess(edit_task_desc_button_name, user_access.AccessMode.EDIT, GetAccess()),
keyboard.ButtonWithAccess(edit_task_access_button_name, user_access.AccessMode.ACCEES_EDIT, GetAccess()),
]
mods = [start]
return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups)
def GetStartTaskKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = [
keyboard.ButtonWithAccess(list_task_button_name, user_access.AccessMode.VIEW, GetAccess()),
keyboard.ButtonWithAccess(add_task_button_name, user_access.AccessMode.ADD, GetAccess()),
keyboard.ButtonWithAccess(del_task_button_name, user_access.AccessMode.DELETE, GetAccess()),
keyboard.ButtonWithAccess(edit_task_button_name, user_access.AccessMode.EDIT, GetAccess())
]
mods = [start]
return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups)
# ---------------------------------------------------------
# Обработка сообщений
select_handler = 0
# стартовое сообщение
async def TasksOpen(a_Message : types.message, state = None):
user_id = str(a_Message.from_user.id)
user_groups = groups.GetUserGroupData(user_id)
await a_Message.answer(base_task_message, reply_markup = GetStartTaskKeyboardButtons(a_Message, user_groups))
await select_handler(a_Message)
return None
def GetButtonNameAndKeyValueAndAccess(a_Item):
# taskName taskID taskAccess
return a_Item[1], a_Item[0], a_Item[4]
def ShowMessageTemplate(a_StringMessage):
async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item):
if (len(a_Item) < 6):
return simple_message.WorkFuncResult(error_find_proj_message)
msg = a_StringMessage.\
replace(f'#{name_field}', a_Item[1]).\
replace(f'#{desc_field}', a_Item[2]).\
replace(f'#{create_datetime_field}', a_Item[5]).\
replace(f'#{access_field}', a_Item[4])
return simple_message.WorkFuncResult(msg, photo_id = a_Item[3], item_access = a_Item[4])
return ShowMessage
def SimpleMessageTemplate(a_StringMessage):
async def ShowMessage(a_CallbackQuery : types.CallbackQuery):
return simple_message.WorkFuncResult(a_StringMessage)
return ShowMessage
# Удаление задачи
async def TaskPreDelete(a_CallbackQuery : types.CallbackQuery, a_Item):
if (len(a_Item) < 6):
return simple_message.WorkFuncResult(error_find_proj_message)
access = a_Item[4]
return simple_message.WorkFuncResult('', None, item_access = access)
async def TaskPostDelete(a_CallbackQuery : types.CallbackQuery, a_ItemID):
log.Success(f'Задача №{a_ItemID} была удалена пользователем {a_CallbackQuery.from_user.id}.')
return simple_message.WorkFuncResult(task_success_delete_message)
# ---------------------------------------------------------
# Работа с базой данных задач
def AddBDItemFunc(a_ItemData):
res, error = bot_bd.SQLRequestToBD(f'INSERT INTO {table_name}({photo_field}, {name_field}, {desc_field}, {access_field}, {create_datetime_field}) VALUES(?, ?, ?, ?, {bot_bd.GetBDDateTimeNow()})',
commit = True, return_error = True, param = (a_ItemData[photo_field], a_ItemData[name_field], a_ItemData[desc_field], access.GetItemDefaultAccessForModule(module_name)))
if error:
log.Error(f'Ошибка добавления записи в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {access.GetItemDefaultAccessForModule(module_name)}).')
else:
log.Success(f'Добавлена запись в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {access.GetItemDefaultAccessForModule(module_name)}).')
return res, error
# ---------------------------------------------------------
# API
# Инициализация БД
def GetInitBDCommands():
return init_bd_cmds
def GetAccess():
return access.GetAccessForModule(module_name)
# Доступные кнопки
def GetModuleButtons():
return [keyboard.ButtonWithAccess(tasks_button_name, user_access.AccessMode.VIEW, GetAccess())]
# Обработка кнопок
def RegisterHandlers(dp : Dispatcher):
defaul_keyboard_func = GetStartTaskKeyboardButtons
# Список задач
dp.register_message_handler(simple_message.SimpleMessageTemplate(TasksOpen, defaul_keyboard_func, GetAccess), text = tasks_button_name)
global select_handler
select_handler = bd_item_view.SelectAndShowBDItemRegisterHandlers(dp, list_task_button_name, table_name, key_name, ShowMessageTemplate(task_open_message), GetButtonNameAndKeyValueAndAccess, select_task_message, GetAccess, defaul_keyboard_func)
# Удаление задачи
bd_item_delete.DeleteBDItemRegisterHandlers(dp, del_task_button_name, table_name, key_name, TaskPreDelete, TaskPostDelete, GetButtonNameAndKeyValueAndAccess, select_task_message, GetAccess, defaul_keyboard_func)
# Добавление задачи
bd_item_add.AddBDItem3RegisterHandlers(dp, FSMCreateTask, FSMCreateTask.name, FSMCreateTask.desc, FSMCreateTask.photo, add_task_button_name, AddBDItemFunc, SimpleMessageTemplate(task_create_name_message), SimpleMessageTemplate(task_create_desc_message), SimpleMessageTemplate(task_create_photo_message), SimpleMessageTemplate(task_success_create_message), table_name, key_name, name_field, desc_field, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, defaul_keyboard_func)
edit_keyboard_func = GetEditTaskKeyboardButtons
# Редактирование задачи
dp.register_message_handler(simple_message.InfoMessageTemplate(task_start_edit_message, edit_keyboard_func, GetAccess, access_mode = user_access.AccessMode.EDIT), text = edit_task_button_name)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditPhotoItem, edit_task_photo_button_name, task_select_to_edit_message, ShowMessageTemplate(task_edit_photo_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.photo)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditNameItem, edit_task_name_button_name, task_select_to_edit_message, ShowMessageTemplate(task_edit_name_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, name_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditDeskItem, edit_task_desc_button_name, task_select_to_edit_message, ShowMessageTemplate(task_edit_desc_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, desc_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditAccessItem, edit_task_access_button_name, task_select_to_edit_message, ShowMessageTemplate(task_edit_access_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text)

4
template/bd_item.py

@ -27,7 +27,7 @@ class FieldType(Enum):
photo = 'photo' photo = 'photo'
def GetCancelKeyboardButtonsTemplate(a_AccessFunc, a_AccessMode): def GetCancelKeyboardButtonsTemplate(a_AccessFunc, a_AccessMode):
def GetCancelKeyboardButtons(a_UserGroups): def GetCancelKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = [ cur_buttons = [
keyboard.ButtonWithAccess(canсel_button_name, a_AccessMode, a_AccessFunc()), keyboard.ButtonWithAccess(canсel_button_name, a_AccessMode, a_AccessFunc()),
] ]
@ -35,7 +35,7 @@ def GetCancelKeyboardButtonsTemplate(a_AccessFunc, a_AccessMode):
return GetCancelKeyboardButtons return GetCancelKeyboardButtons
def GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, a_AccessMode): def GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, a_AccessMode):
def GetSkipAndCancelKeyboardButtons(a_UserGroups): def GetSkipAndCancelKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = [ cur_buttons = [
keyboard.ButtonWithAccess(skip_button_name, a_AccessMode, a_AccessFunc()), keyboard.ButtonWithAccess(skip_button_name, a_AccessMode, a_AccessFunc()),
keyboard.ButtonWithAccess(canсel_button_name, a_AccessMode, a_AccessFunc()), keyboard.ButtonWithAccess(canсel_button_name, a_AccessMode, a_AccessFunc()),

2
template/bd_item_add.py

@ -101,7 +101,7 @@ def AddBDItem3RegisterHandlers(dp, a_FSM, a_FSMName, a_FSMDesc, a_FSMPhoto, a_Bu
keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode) keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode)
keyboard_skip_and_cancel = bd_item.GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode) keyboard_skip_and_cancel = bd_item.GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode)
a_Prefix = f'add_{a_TableName}_{a_KeyName}_{a_NameField}_{a_DescField}_{a_PhotoField}:' a_Prefix = f'add_{a_TableName}_{a_KeyName}_{a_NameField}_{a_DescField}_{a_PhotoField}:'
# sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_Prefix, access_mode) # sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode)
# dp.register_message_handler(sel_handler, text = a_ButtonName) # dp.register_message_handler(sel_handler, text = a_ButtonName)
dp.register_message_handler(StartAddBDItemTemplate(a_FSM, a_FSMName, a_AddNameMessageFunc, a_TableName, a_KeyName, a_NameField, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), text = a_ButtonName) dp.register_message_handler(StartAddBDItemTemplate(a_FSM, a_FSMName, a_AddNameMessageFunc, a_TableName, a_KeyName, a_NameField, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), text = a_ButtonName)
dp.register_message_handler(NextAddBDItemTemplate(a_FSM, None, a_TableName, a_KeyName, a_NameField, a_AddDescMessageFunc, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMName) dp.register_message_handler(NextAddBDItemTemplate(a_FSM, None, a_TableName, a_KeyName, a_NameField, a_AddDescMessageFunc, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMName)

2
template/bd_item_delete.py

@ -33,7 +33,7 @@ def DeleteBDItemTemplate(a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDele
def DeleteBDItemRegisterHandlers(dp, a_ButtonName, a_TableName : str, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.DELETE): def DeleteBDItemRegisterHandlers(dp, a_ButtonName, a_TableName : str, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.DELETE):
a_Prefix = f'delete_{a_TableName}_{a_KeyName}:' a_Prefix = f'delete_{a_TableName}_{a_KeyName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_Prefix, access_mode) sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName) dp.register_message_handler(sel_handler, text = a_ButtonName)
dp.register_callback_query_handler(DeleteBDItemTemplate(a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode), lambda x: x.data.startswith(a_Prefix)) dp.register_callback_query_handler(DeleteBDItemTemplate(a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode), lambda x: x.data.startswith(a_Prefix))

2
template/bd_item_edit.py

@ -78,7 +78,7 @@ def FinishEditBDItemTemplate(a_FSM, a_TableName, a_KeyName, a_FieldName, a_Messa
def EditBDItemRegisterHandlers(dp, a_FSM, a_ButtonName, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): def EditBDItemRegisterHandlers(dp, a_FSM, a_ButtonName, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode) keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode)
a_Prefix = f'edit_{a_TableName}_{a_KeyName}_{a_FieldName}:' a_Prefix = f'edit_{a_TableName}_{a_KeyName}_{a_FieldName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_Prefix, access_mode) sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName) dp.register_message_handler(sel_handler, text = a_ButtonName)
dp.register_callback_query_handler(StartEditBDItemTemplate(a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_FieldName, a_Prefix, a_AccessFunc, keyboard_cancel, access_mode), lambda x: x.data.startswith(a_Prefix)) dp.register_callback_query_handler(StartEditBDItemTemplate(a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_FieldName, a_Prefix, a_AccessFunc, keyboard_cancel, access_mode), lambda x: x.data.startswith(a_Prefix))
if field_type == bd_item.FieldType.photo: if field_type == bd_item.FieldType.photo:

13
template/bd_item_select.py

@ -9,8 +9,11 @@ from template import simple_message, bd_item
from aiogram import types from aiogram import types
def GetBDItemsListKeyboardButtonsTemplate(a_TableName : str, a_Prefix : str, a_GetButtonNameAndKeyValueAndAccessFunc, access_mode = user_access.AccessMode.VIEW): def GetBDItemsListKeyboardButtonsTemplate(a_TableName : str, a_PrevPrefix, a_NextPrefix : str, a_GetButtonNameAndKeyValueAndAccessFunc, access_mode = user_access.AccessMode.VIEW):
def GetBDItemsListKeyboardButtons(a_UserGroups): def GetBDItemsListKeyboardButtons(a_Message, a_UserGroups):
#if a_PrevPrefix:
items = bd_item.GetAllItemsTemplate(a_TableName)() items = bd_item.GetAllItemsTemplate(a_TableName)()
items_button_list = [] items_button_list = []
for t in items: for t in items:
@ -19,10 +22,10 @@ def GetBDItemsListKeyboardButtonsTemplate(a_TableName : str, a_Prefix : str, a_G
access = '' access = ''
if not bname is None and user_access.CheckAccessString(access, a_UserGroups, access_mode): if not bname is None and user_access.CheckAccessString(access, a_UserGroups, access_mode):
items_button_list += [keyboard.Button(bname, key_value)] items_button_list += [keyboard.Button(bname, key_value)]
return keyboard.MakeInlineKeyboard(items_button_list, a_Prefix) return keyboard.MakeInlineKeyboard(items_button_list, a_NextPrefix)
return GetBDItemsListKeyboardButtons return GetBDItemsListKeyboardButtons
def SelectDBItemTemplate(a_TableName : str, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_Prefix, access_mode = user_access.AccessMode.VIEW): def SelectDBItemTemplate(a_TableName : str, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_NextPrefix, access_mode = user_access.AccessMode.VIEW):
keyborad_func = GetBDItemsListKeyboardButtonsTemplate(a_TableName, a_Prefix, a_GetButtonNameAndKeyValueAndAccessFunc) keyborad_func = GetBDItemsListKeyboardButtonsTemplate(a_TableName, a_PrevPrefix, a_NextPrefix, a_GetButtonNameAndKeyValueAndAccessFunc)
return simple_message.InfoMessageTemplate(a_StartMessage, keyborad_func, a_AccessFunc, access_mode) return simple_message.InfoMessageTemplate(a_StartMessage, keyborad_func, a_AccessFunc, access_mode)

21
template/bd_item_view.py

@ -14,8 +14,27 @@ def ShowBDItemTemplate(a_TableName, a_KeyName, a_WorkFunc, a_Prefix, a_AccessFun
def SelectAndShowBDItemRegisterHandlers(dp, a_ButtonName, a_TableName : str, a_KeyName, a_ShowItemWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW): def SelectAndShowBDItemRegisterHandlers(dp, a_ButtonName, a_TableName : str, a_KeyName, a_ShowItemWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW):
a_Prefix = f'select_{a_TableName}_{a_KeyName}:' a_Prefix = f'select_{a_TableName}_{a_KeyName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_Prefix, access_mode) sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode = access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName) dp.register_message_handler(sel_handler, text = a_ButtonName)
dp.register_callback_query_handler(ShowBDItemTemplate(a_TableName, a_KeyName, a_ShowItemWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode), lambda x: x.data.startswith(a_Prefix)) dp.register_callback_query_handler(ShowBDItemTemplate(a_TableName, a_KeyName, a_ShowItemWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode), lambda x: x.data.startswith(a_Prefix))
return sel_handler return sel_handler
def StartSelectBDItemRegisterHandlers(dp, a_PrefixBase, a_ButtonName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW):
a_Prefix = f'{a_PrefixBase}select_{a_TableName}_{a_KeyName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode = access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName)
return a_Prefix
def NextSelectBDItemRegisterHandlers(dp, a_PrevPrefix, a_ButtonName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW):
a_Prefix = f'{a_PrevPrefix}select_{a_TableName}_{a_KeyName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode = access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName)
return a_Prefix
def ShowBDItemRegisterHandlers(dp, a_PrevPrefix, a_TableName : str, a_KeyName, a_ShowItemWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW):
dp.register_callback_query_handler(ShowBDItemTemplate(a_TableName, a_KeyName, a_ShowItemWorkFunc, a_PrevPrefix, a_AccessFunc, a_ButtonFunc, access_mode = access_mode), lambda x: x.data.startswith(a_PrevPrefix))

6
template/file_message.py

@ -16,13 +16,13 @@ def BackupFileTemplate(a_Path, a_CaptionMessage, a_AccessFunc, a_ButtonFunc, a_E
user_id = str(a_Message.from_user.id) user_id = str(a_Message.from_user.id)
user_groups= groups.GetUserGroupData(user_id) user_groups= groups.GetUserGroupData(user_id)
if not user_access.CheckAccessString(a_AccessFunc(), user_groups, user_access.AccessMode.EDIT): if not user_access.CheckAccessString(a_AccessFunc(), user_groups, user_access.AccessMode.EDIT):
return await a_Message.answer(access.access_denied_message, reply_markup = a_ButtonFunc(user_groups)) return await a_Message.answer(access.access_denied_message, reply_markup = a_ButtonFunc(a_Message, user_groups))
document = await GetFile(a_Path) document = await GetFile(a_Path)
if document is None: if document is None:
return await a_Message.answer(user_id, error_backup_message, reply_markup = a_ButtonFunc(user_groups)) return await a_Message.answer(user_id, error_backup_message, reply_markup = a_ButtonFunc(a_Message, user_groups))
await bot.send_document(user_id, document, caption = a_CaptionMessage.replace('@time', log.GetTime()), reply_markup = a_ButtonFunc(user_groups)) await bot.send_document(user_id, document, caption = a_CaptionMessage.replace('@time', log.GetTime()), reply_markup = a_ButtonFunc(a_Message, user_groups))
return BackupFile return BackupFile
async def GetFile(a_Path): async def GetFile(a_Path):

8
template/simple_message.py

@ -29,7 +29,7 @@ def SimpleMessageTemplate(a_WorkFunc, a_GetButtonsFunc, a_AccessFunc, access_mod
user_id = str(a_Message.from_user.id) user_id = str(a_Message.from_user.id)
user_groups = groups.GetUserGroupData(user_id) user_groups = groups.GetUserGroupData(user_id)
if not user_access.CheckAccessString(a_AccessFunc(), user_groups, access_mode): if not user_access.CheckAccessString(a_AccessFunc(), user_groups, access_mode):
return await bot.send_message(a_Message.from_user.id, access.access_denied_message, reply_markup = a_GetButtonsFunc(user_groups)) return await bot.send_message(a_Message.from_user.id, access.access_denied_message, reply_markup = a_GetButtonsFunc(a_Message, user_groups))
res = await a_WorkFunc(a_Message, state = state) res = await a_WorkFunc(a_Message, state = state)
if res is None: if res is None:
@ -46,10 +46,10 @@ def SimpleMessageTemplate(a_WorkFunc, a_GetButtonsFunc, a_AccessFunc, access_mod
photo_id = res.photo_id photo_id = res.photo_id
if not res.item_access is None and not user_access.CheckAccessString(res.item_access, user_groups, access_mode): if not res.item_access is None and not user_access.CheckAccessString(res.item_access, user_groups, access_mode):
return await bot.send_message(a_Message.from_user.id, access.access_denied_message, reply_markup = keyborad_func(user_groups)) return await bot.send_message(a_Message.from_user.id, access.access_denied_message, reply_markup = keyborad_func(a_Message, user_groups))
if photo_id is None or photo_id == 0 or photo_id == '0': if photo_id is None or photo_id == 0 or photo_id == '0':
return await bot.send_message(a_Message.from_user.id, msg, reply_markup = keyborad_func(user_groups)) return await bot.send_message(a_Message.from_user.id, msg, reply_markup = keyborad_func(a_Message, user_groups))
await bot.send_photo(user_id, photo_id, msg, reply_markup = keyborad_func(user_groups)) await bot.send_photo(user_id, photo_id, msg, reply_markup = keyborad_func(a_Message, user_groups))
return SimpleMessage return SimpleMessage

12
template/sql_request.py

@ -15,7 +15,7 @@ cancel_message = '''
🚫 Запрос к БД отменён 🚫 Запрос к БД отменён
''' '''
def GetCancelKeyboardButtons(a_UserGroups, a_AccessFunc, a_AccessMode): def GetCancelKeyboardButtons(a_Message, a_UserGroups, a_AccessFunc, a_AccessMode):
cur_buttons = [ cur_buttons = [
keyboard.ButtonWithAccess(canсel_button_name, a_AccessMode, a_AccessFunc()) keyboard.ButtonWithAccess(canсel_button_name, a_AccessMode, a_AccessFunc())
] ]
@ -26,9 +26,9 @@ def RequestToBDTemplate(a_StartMessage, a_AccessFunc, a_FSM, a_AccessMode):
user_id = str(a_Message.from_user.id) user_id = str(a_Message.from_user.id)
user_groups = groups.GetUserGroupData(user_id) user_groups = groups.GetUserGroupData(user_id)
if not user_access.CheckAccessString(a_AccessFunc(), user_groups, a_AccessMode): if not user_access.CheckAccessString(a_AccessFunc(), user_groups, a_AccessMode):
return await a_Message.answer(access.access_denied_message, reply_markup = GetCancelKeyboardButtons(user_groups, a_AccessFunc, a_AccessMode)) return await a_Message.answer(access.access_denied_message, reply_markup = GetCancelKeyboardButtons(a_Message, user_groups, a_AccessFunc, a_AccessMode))
await a_FSM.sqlRequest.set() await a_FSM.sqlRequest.set()
await a_Message.answer(a_StartMessage, reply_markup = GetCancelKeyboardButtons(user_groups, a_AccessFunc, a_AccessMode), parse_mode='Markdown') await a_Message.answer(a_StartMessage, reply_markup = GetCancelKeyboardButtons(a_Message, user_groups, a_AccessFunc, a_AccessMode), parse_mode='Markdown')
return RequestToBDStart return RequestToBDStart
def RequestToBDFinishTemplate(a_GetButtonsFunc, a_AccessFunc, a_AccessMode): def RequestToBDFinishTemplate(a_GetButtonsFunc, a_AccessFunc, a_AccessMode):
@ -36,12 +36,12 @@ def RequestToBDFinishTemplate(a_GetButtonsFunc, a_AccessFunc, a_AccessMode):
user_id = str(a_Message.from_user.id) user_id = str(a_Message.from_user.id)
user_groups = groups.GetUserGroupData(user_id) user_groups = groups.GetUserGroupData(user_id)
if not user_access.CheckAccessString(a_AccessFunc(), user_groups, a_AccessMode): if not user_access.CheckAccessString(a_AccessFunc(), user_groups, a_AccessMode):
return await a_Message.answer(access.access_denied_message, reply_markup = a_GetButtonsFunc(user_groups)) return await a_Message.answer(access.access_denied_message, reply_markup = a_GetButtonsFunc(a_Message, user_groups))
result = '' result = ''
async with state.proxy() as prjData: async with state.proxy() as prjData:
if a_Message.text == canсel_button_name: if a_Message.text == canсel_button_name:
await state.finish() await state.finish()
return await a_Message.answer(cancel_message, reply_markup = a_GetButtonsFunc(user_groups)) return await a_Message.answer(cancel_message, reply_markup = a_GetButtonsFunc(a_Message, user_groups))
sql_request = a_Message.text sql_request = a_Message.text
log.Success(f'Сделан запрос [{sql_request}] пользователем {a_Message.from_user.id}.') log.Success(f'Сделан запрос [{sql_request}] пользователем {a_Message.from_user.id}.')
@ -52,7 +52,7 @@ def RequestToBDFinishTemplate(a_GetButtonsFunc, a_AccessFunc, a_AccessMode):
else: else:
log.Success(f'Результат запроса [{sql_request}] от пользователя {a_Message.from_user.id} следующий [{result}].') log.Success(f'Результат запроса [{sql_request}] от пользователя {a_Message.from_user.id} следующий [{result}].')
await state.finish() await state.finish()
await a_Message.answer(str(result), reply_markup = a_GetButtonsFunc(user_groups)) await a_Message.answer(str(result), reply_markup = a_GetButtonsFunc(a_Message, user_groups))
return RequestToBDFinish return RequestToBDFinish
def RequestToBDRegisterHandlers(dp, a_RequestButtonName, a_RequestStartMessage, a_FSM, a_GetButtonsFunc, a_AccessMode, a_AccessFunc): def RequestToBDRegisterHandlers(dp, a_RequestButtonName, a_RequestStartMessage, a_FSM, a_GetButtonsFunc, a_AccessMode, a_AccessFunc):

Loading…
Cancel
Save