Compare commits

..

No commits in common. 'master' and 'adminpanel_backend' have entirely different histories.

  1. 213
      bot_modules/all_orders.py
  2. 31
      bot_modules/messages.py
  3. 9
      bot_modules/mod_simple_message.py
  4. 168
      bot_modules/mod_table_operate.py
  5. 80
      bot_modules/orders.py
  6. 2
      bot_modules/orders_cat.py
  7. 143
      bot_modules/user_message.py
  8. 13
      bot_modules/users.py
  9. 10
      bot_sys/bd_table.py
  10. 1
      bot_sys/bot_bd.py
  11. 42
      bot_sys/bot_messages.py
  12. 8
      bot_sys/interfaces.py
  13. 7
      main.py
  14. 1
      requirements.txt
  15. 31
      template/bd_item_edit.py
  16. 2
      template/simple_message.py
  17. 4
      template/sql_request.py

213
bot_modules/all_orders.py

@ -5,11 +5,7 @@
from bot_sys import bot_bd, keyboard, user_access, bd_table
from bot_modules import mod_table_operate, mod_simple_message, orders, access_utils
from bot_modules import users, user_message
from template import bd_item_select, bd_item_view, bd_item, bd_item_edit
from enum import Enum
from enum import auto
from template import bd_item_select, bd_item_view, bd_item
# ---------------------------------------------------------
# БД
@ -22,23 +18,14 @@ init_access = f'{user_access.user_access_group_new}=-'
# ---------------------------------------------------------
# Сообщения и кнопки
class ButtonNames(Enum):
SHOW_USER_INFO = auto()
SEND_USER_MESSAGE = auto()
ADD_TO_DESC = auto()
button_names = {}
button_names.update(orders.button_names)
button_names.pop(mod_table_operate.ButtonNames.ADD)
cur_button_names = {
mod_simple_message.ButtonNames.START: "🛒 Все заказы",
mod_table_operate.ButtonNames.SHOW: "☐ Открыть заказ",
mod_table_operate.ButtonNames.LIST: "📃 Список текущих заказов",
orders.ButtonNames.LIST_ALL: "📃 Список всех заказов",
ButtonNames.SHOW_USER_INFO: "👤 Информация о пользователе",
ButtonNames.SEND_USER_MESSAGE: "📨 Отправить сообщение пользователю",
ButtonNames.ADD_TO_DESC: "𝌴 Добавить к описанию",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать заказ",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO_PAY): "☐ Загрузить чек по оплате заказа",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в заказе",
@ -69,8 +56,6 @@ cur_messages = {
Введите новый статус заказа:
''',
mod_table_operate.Messages.OPEN: f'''
<b>Номер заказа: #{orders.key_name} </b>
<b>Заказ: #{orders.name_field}</b>
<b>Описание и состав заказа:</b> #{orders.desc_field}
@ -83,29 +68,16 @@ cur_messages = {
<b>Время создания:</b> #{orders.create_datetime_field}
''',
mod_table_operate.InlineMessage(ButtonNames.ADD_TO_DESC): f'''
Текущее описание заказа:
<code>#{orders.desc_field}</code>
Введите дополение к описанию заказа:
''',
}
messages_notification = {
mod_table_operate.NotificationMessage(orders.OrderStatus.NEW): f'''Статус заказа "#{orders.name_field}" изменён на - ожидает модерации''',
mod_table_operate.NotificationMessage(orders.OrderStatus.PAY): f'''Статус заказа "#{orders.name_field}" изменён на - Заказ ожидает оплаты.
<b>Описание заказа:</b>
#{orders.desc_field}
Оплатите заказ и прикрепите чек об оплате к заказу. Для этого проследуйте по пути "Главное меню"->"Заказы"->"Загрузить чек по оплате моего заказа"
Или воспользуйтесь кнопкой:''',
Оплатите заказ и прикрепите чек об оплате к заказу. Для этого проследуйте по пути "Заказы"->"Редактировать мой заказ"->"Загрузить чек по оплате моего заказа"''',
mod_table_operate.NotificationMessage(orders.OrderStatus.ADDRESS): f'''Статус заказа "#{orders.name_field}" изменён на - Заказ ожидает указания адреса доставки.
<b>Описание заказа:</b>
#{orders.desc_field}
Для этого проследуйте по пути "Главное меню"->"Заказы"->"Редактировать мой заказ"->"Изменить адрес в моём заказе"''',
Для этого проследуйте по пути "Заказы"->"Редактировать мой заказ"->"Изменить адрес в моём заказе"''',
mod_table_operate.NotificationMessage(orders.OrderStatus.FINISH): f'''Статус заказа "#{orders.name_field}" изменён на - Заказ выполнен''',
}
@ -157,32 +129,12 @@ class ModuleAllOrders(orders.ModuleOrders):
return DBItemForUserSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName)
def GetButtonNameAndKeyValueAndAccess(self, a_Item):
user_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.USER_ID)
parent_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
n, k, a = super().GetButtonNameAndKeyValueAndAccess(a_Item)
return n + "," + str(a_Item[user_field_id]), k, a
def GetPayInlineKeyboardFunc(self, a_ItemID, a_Destiny):
def PayInlineKeyboard(a_Message, a_UserGroups):
#print('PayInlineKeyboard', a_Message, a_UserGroups, a_ItemID)
cur_buttons = []
orders_mod = self.GetModule(orders.module_name)
dst = a_Destiny
if orders_mod:
prefix = orders_mod.m_EditPrefix.get(dst, None)
if prefix:
access = orders_mod.GetAccessForEditKeyboardButtons(orders_mod.m_Table.GetFieldByDestiny(dst))
cur_buttons += [
keyboard.InlineButtonWithAccess(orders_mod.GetButton(mod_table_operate.EditButton(dst)), prefix, a_ItemID, orders_mod.GetAccess(), access),
]
#print('cur_buttons', cur_buttons, a_Message, a_UserGroups, a_ItemID)
return keyboard.MakeInlineKeyboardButtons(self.m_Bot, cur_buttons, a_UserGroups)
return PayInlineKeyboard
return n + ":" + str(a_Item[parent_field_id]), k, a
async def OnChangeField(self, a_Field, a_ItemID, a_ItemData, a_EditUserID):
await super().OnChangeField(a_Field, a_ItemID, a_ItemData, a_EditUserID)
super().OnChangeField(a_Field, a_ItemID, a_ItemData, a_EditUserID)
if a_Field.m_Destiny == bd_table.TableFieldDestiny.STATUS:
key_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY)
item = bd_item.GetBDItemsTemplate(self.m_Bot, self.m_Table.GetName(), key_field)(a_ItemID)
@ -192,159 +144,20 @@ class ModuleAllOrders(orders.ModuleOrders):
item = item[0]
user_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.USER_ID)
parent_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
status_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.STATUS)
#print('OnChangeField', item, user_field_id, status_field_id)
print('OnChangeField', item, user_field_id, status_field_id)
owner_id = item[user_field_id]
new_status = item[status_field_id]
parent_id = item[parent_field_id]
msg = self.GetMessage(mod_table_operate.NotificationMessage(new_status))
parent_id_msg = None
if msg:
name = self.GetMessageNameWithTableFieldDestinyAndValue(mod_table_operate.NotificationMessage(new_status), bd_table.TableFieldDestiny.PARENT_ID, parent_id)
#print('name', name, msg.GetLanguage())
parent_id_msg = msg.FindMessageForLang(name, msg.GetLanguage())
if parent_id_msg:
msg = parent_id_msg
if not msg:
self.m_Log.Error(f'Не удалось оповестить по заказу №{a_ItemID}. Пустое сообщение для нового статуса {new_status}')
return
msg = self.UpdateMessage(msg, None, item)
inline_keyboard = None
#print('new_status', str(orders.OrderStatus.PAY), new_status)
if new_status == str(orders.OrderStatus.PAY):
inline_keyboard = self.GetPayInlineKeyboardFunc(a_ItemID, bd_table.TableFieldDestiny.PHOTO_PAY)
elif new_status == str(orders.OrderStatus.ADDRESS):
inline_keyboard = self.GetPayInlineKeyboardFunc(a_ItemID, bd_table.TableFieldDestiny.ADDRESS)
await self.SendMessageToUser(msg, owner_id, a_GetInlineButtonsFunc = inline_keyboard)
def GetStartButtons(self, a_Message, a_UserGroups):
return [
[mod_table_operate.ButtonNames.LIST, user_access.AccessMode.VIEW],
[mod_table_operate.ButtonNames.EDIT, user_access.AccessMode.EDIT],
[mod_table_operate.ButtonNames.ADD, user_access.AccessMode.ADD],
[mod_table_operate.ButtonNames.DEL, user_access.AccessMode.DELETE],
]
def GetViewItemInlineKeyboard(self, a_Message, a_UserGroups, a_ItemID):
table_name = self.m_Table.GetName()
key_name = self.GetKeyFieldName()
cur_item = mod_table_operate.GetCurItem(self.m_Bot, table_name, key_name, a_ItemID)
user_id = None
user_id_field_index = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.USER_ID)
key_field_index = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)
if user_id_field_index and cur_item and cur_item[user_id_field_index]:
user_id = cur_item[user_id_field_index]
if not user_id:
return keyboard.MakeInlineKeyboardButtons(self.m_Bot, [], a_UserGroups)
cur_buttons = []
for dst in bd_table.TableFieldDestiny.DESC, bd_table.TableFieldDestiny.STATUS:
access = self.GetAccessForEditKeyboardButtons(self.m_Table.GetFieldByDestiny(dst))
btn = mod_table_operate.EditButton(dst)
prefix = self.m_EditPrefix.get(dst, None)
if prefix:
cur_buttons += [
keyboard.InlineButtonWithAccess(self.GetButton(btn), prefix, cur_item[key_field_index], self.GetAccess(), access),
]
access = self.GetAccessForEditKeyboardButtons(self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.DESC))
a_Button = ButtonNames.ADD_TO_DESC
prefix = self.m_EditPrefix.get(a_Button, None)
cur_buttons += [
keyboard.InlineButtonWithAccess(self.GetButton(a_Button), prefix, cur_item[key_field_index], self.GetAccess(), access),
]
user_message_mod = self.GetModule(user_message.module_name)
if user_message_mod:
cur_buttons += [
keyboard.InlineButtonWithAccess(self.GetButton(ButtonNames.SEND_USER_MESSAGE), user_message_mod.GetAddPrefix(), user_id, user_message_mod.GetAccess(), user_access.AccessMode.ADD),
]
users_mod = self.GetModule(users.module_name)
if users_mod:
cur_buttons += [
keyboard.InlineButtonWithAccess(self.GetButton(ButtonNames.SHOW_USER_INFO), users_mod.GetShowPrefix(), user_id, users_mod.GetAccess(), user_access.AccessMode.VIEW),
]
return keyboard.MakeInlineKeyboardButtons(self.m_Bot, cur_buttons, a_UserGroups)
def RegisterAddToDesc(self):
a_AccessMode = user_access.AccessMode.EDIT
a_Button = ButtonNames.ADD_TO_DESC
a_ButtonName = self.GetButton(a_Button)
a_EditMessage = self.GetMessage(mod_table_operate.InlineMessage(a_Button))
a_Field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.DESC)
a_FieldName = a_Field.m_Name
a_FieldType = bd_item.FieldType.text
if a_Field.m_Type == bd_table.TableFieldType.PHOTO:
a_FieldType = bd_item.FieldType.photo
if not a_ButtonName or not a_EditMessage:
return
async def OnChange(a_ItemID, a_ItemData, a_EditUserID):
await self.OnChangeField(a_Field, a_ItemID, a_ItemData, a_EditUserID)
return self.OnChange()
table_name = self.m_Table.GetName()
key_name = self.GetKeyFieldName()
edit_keyboard_func = self.m_GetEditKeyboardButtonsFunc
GetButtonNameAndKeyValueAndAccess = self.m_GetButtonNameAndKeyValueAndAccessFunc
GetAccess = self.m_GetAccessFunc
async def EditBDItemFunc(a_ItemData, a_UserID):
a_KeyName = key_name
a_TableName = table_name
item_id = a_ItemData[a_KeyName]
field_value = a_ItemData[a_FieldName]
cur_item = mod_table_operate.GetCurItem(self.m_Bot, table_name, key_name, item_id)
desc = ""
desc_field_index = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.DESC)
if desc_field_index and cur_item and cur_item[desc_field_index]:
desc = cur_item[desc_field_index]
new_value = desc + "\n" + field_value
res, error = bd_item.EditBDItemInTableTemplate(self.m_Bot, a_TableName, a_KeyName, a_FieldName)(item_id, new_value)
if error:
self.m_Bot.GetLog().Error(f'Пользователю {a_UserID} не удалось изменить поле в таблице {a_TableName} ключу {a_KeyName}={item_id}. Новое значение поля {a_FieldName}={field_value}. Ошибка: {error}')
else:
self.m_Bot.GetLog().Success(f'Пользователь {a_UserID} добавил в поле в таблице {a_TableName} ключу {a_KeyName}={item_id}. Новое значение поля {a_FieldName}={new_value}. Старое {desc}.')
await OnChange(item_id, a_ItemData, a_UserID)
return res, error
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True)
a_Prefix = bd_item_edit.CustomEditBDItemRegisterHandlers(self.m_Bot, \
EditBDItemFunc,
self.SelectSourceTemplate(a_Prefix, a_ButtonName), \
mod_table_operate.MakeFSMForAddAndEdit(self.GetName(), a_FieldName), \
self.GetMessage(mod_table_operate.Messages.SELECT_TO_EDIT), \
self.ShowMessageTemplate(a_EditMessage), \
self.ShowMessageTemplate(self.GetMessage(mod_table_operate.Messages.SUCCESS_EDIT)), \
table_name, \
key_name, \
a_FieldName, \
self.PostProccessingForFieldForEditTemplate(a_Field),\
GetButtonNameAndKeyValueAndAccess, \
GetAccess, \
self.AdditionalKeyboardForEditTemplate(a_Field),\
edit_keyboard_func, \
access_mode = a_AccessMode, \
field_type = a_FieldType\
await self.m_Bot.SendMessage(
owner_id,
msg.GetDesc(),
msg.GetPhotoID(),
None,
None
)
self.m_EditPrefix.update({a_Button: a_Prefix})
def RegisterHandlers(self):
super().RegisterHandlers()
self.RegisterAddToDesc()

31
bot_modules/messages.py

@ -46,10 +46,10 @@ button_names = {
mod_simple_message.ButtonNames.START: "✉ Сообщения",
mod_table_operate.ButtonNames.LIST: "📃 Список сообщений",
mod_table_operate.ButtonNames.ADD: "☑ Добавить сообщение",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать сообщение бота",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать сообщение",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение у сообщения",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): " Изменить название сообщения",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание сообщения",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название у сообщения",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание у сообщения",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к сообщению",
mod_table_operate.ButtonNames.DEL: "❌ Удалить сообщение",
}
@ -72,12 +72,9 @@ messages = {
Время создания: #{create_datetime_field}
''',
mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): f'''
mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): '''
Создание сообщения. Шаг 1
Вы можете добавить номер родителя ID в таком формате: ИмяСообщения{'<code>?' + str(bd_table.TableFieldDestiny.PARENT_ID) + '=</code>ID'}
, чтобы сообщение было только для него
Введите название сообщения:
''',
mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): '''
@ -149,7 +146,12 @@ class ModuleMessages(mod_table_operate.TableOperateModule):
return self.m_Bot.SQLRequest(f'INSERT OR IGNORE INTO {table_name}({photo_field}, {name_field}, {desc_field}, {access_field}, {parent_id_field}, {create_datetime_field}) VALUES(?, ?, ?, ?, ?, {bot_bd.GetBDDateTimeNow()})',
commit = True, return_error = True, param = (a_Message.m_PhotoID, a_Message.m_MessageName, a_Message.m_MessageDesc, access_utils.GetItemDefaultAccessForModule(self.m_Bot, module_name), lang_id))
def LoadAllMessages(self):
def FlushMessages(self):
msg = self.m_BotMessages.GetMessages()
for lang, msg_dict in msg.items():
for msg_name, message in msg_dict.items():
self.AddOrIgnoreMessage(message)
table_name = self.m_Table.GetName()
msgs_bd = bd_item.GetAllItemsTemplate(self.m_Bot, table_name)()
if msgs_bd:
@ -161,20 +163,7 @@ class ModuleMessages(mod_table_operate.TableOperateModule):
lang_name = self.GetModule(self.m_ParentModName).GetLangName(lang_id)
self.m_BotMessages.CreateMessage(name, desc, self.m_Log.GetTimeNow(), a_MessagePhotoID = photo_id, a_MessageLang = lang_name)
def FlushMessages(self):
msg = self.m_BotMessages.GetMessages()
for lang, msg_dict in msg.items():
for msg_name, message in msg_dict.items():
self.AddOrIgnoreMessage(message)
self.LoadAllMessages()
self.m_BotMessages.UpdateSignal(self.m_Log.GetTimeNow())
def OnChange(self):
self.FlushMessages()
async def PostDelete(self, a_CallbackQuery, a_ItemID):
self.LoadAllMessages() # Сначала загружаем, т.к. одно сообщение удалилось
await super().PostDelete(a_CallbackQuery, a_ItemID)

9
bot_modules/mod_simple_message.py

@ -74,11 +74,10 @@ class SimpleMessageModule(mod_interface.IModule):
if len(a_ButtonDesc) >= 41:
print('ButtonDesc:', a_ButtonDesc)
assert False # Телеграм не поддерживает больше
assert a_ButtonDesc[0] != ' ', f'ButtonDesc:{a_ButtonDesc}, Телеграм не поддерживает пробелы в начале'
assert a_ButtonDesc[-1:] != ' ', f'ButtonDesc:{a_ButtonDesc}, Телеграм не поддерживает пробелы в конце'
btn_name = f'{self.GetName()} {str(a_ButtonName).replace("ButtonNames.", "")}'
assert not self.m_BotButtons.CheckDescExist(a_ButtonDesc), f'ButtonDesc:{a_ButtonDesc}, повтор имени кнопки, все кнопки должны быть разными'
btn = self.m_BotButtons.CreateMessage(btn_name, a_ButtonDesc, self.m_Log.GetTimeNow())
assert a_ButtonDesc[0] != ' ' # Телеграм не поддерживает пробелы в начале
assert a_ButtonDesc[-1:] != ' ' # Телеграм не поддерживает пробелы в конце
# TODO добавить проверку, что все кнопки (a_ButtonDesc) разные
btn = self.m_BotButtons.CreateMessage(f'{self.GetName()} {str(a_ButtonName).replace("ButtonNames.", "")}', a_ButtonDesc, self.m_Log.GetTimeNow())
return btn
def GetModule(self, a_ModName):

168
bot_modules/mod_table_operate.py

@ -4,7 +4,7 @@
# Модуль для редактирования и просмотра таблицы в БД
from bot_sys import keyboard, user_access, bd_table, bot_bd, bot_subscribes
from bot_modules import access_utils, mod_simple_message, groups_utils
from bot_modules import access_utils, mod_simple_message
from template import simple_message, bd_item, bd_item_select, bd_item_view, bd_item_delete, bd_item_add, bd_item_edit
from aiogram.dispatcher import FSMContext
@ -22,9 +22,6 @@ def EnumButton(a_EnumItem):
def EditMessage(a_BDTableDestiny):
return 'edit ' + str(a_BDTableDestiny)
def InlineMessage(a_ButtonName):
return 'inline ' + str(a_ButtonName)
def CreateMessage(a_BDTableDestiny):
return 'create ' + str(a_BDTableDestiny)
@ -38,7 +35,6 @@ def SubscribeMessage(a_EnumItem):
return 'subscribe ' + str(a_EnumItem)
class ButtonNames(Enum):
SHOW = auto()
LIST = auto()
ADD = auto()
EDIT = auto()
@ -92,20 +88,6 @@ def MakeFSMForEdit(a_ModName, a_FieldName):
exec(cmd, globals(), _locals)
return _locals['fsm']
add_and_edit_fsm_cmd = '''
class FSMAddAndEdit{a_ModName}_{a_FieldName}_Item(StatesGroup):
item_field = State()
fsm = FSMAddAndEdit{a_ModName}_{a_FieldName}_Item
'''
def MakeFSMForAddAndEdit(a_ModName, a_FieldName):
cmd = add_and_edit_fsm_cmd.replace("{a_ModName}", a_ModName).replace("{a_FieldName}", a_FieldName)
_locals = locals()
exec(cmd, globals(), _locals)
return _locals['fsm']
class TableOperateModule(mod_simple_message.SimpleMessageModule):
def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log):
super().__init__(a_Messages, a_Buttons, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log)
@ -114,7 +96,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
self.m_ChildModName = a_ChildModName
self.m_ParentModName = a_ParentModName
self.m_SelectPrefix = ''
self.m_EditPrefix = {}
def GetEditKeyboardButtons(a_Message, a_UserGroups):
return self.GetEditKeyboardButtons(a_Message, a_UserGroups)
@ -171,11 +152,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(EditButton(f.m_Destiny)), access, self.GetAccess()),]
return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups)
def GetShowItemInlineKeyboardTemplate(self, a_ItemID):
def GetShowItemInlineKeyboard(a_Message, a_UserGroups):
return self.GetShowItemInlineKeyboard(a_Message, a_UserGroups, a_ItemID)
return GetShowItemInlineKeyboard
def GetViewItemInlineKeyboardTemplate(self, a_ItemID):
def GetViewItemInlineKeyboard(a_Message, a_UserGroups):
return self.GetViewItemInlineKeyboard(a_Message, a_UserGroups, a_ItemID)
@ -184,27 +160,12 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
def GetSelectPrefix(self):
return self.m_SelectPrefix
def GetDelPrefix(self):
return self.m_DelPrefix
def GetAddPrefix(self):
return self.m_AddPrefix
def GetShowPrefix(self):
return self.m_ShowPrefix
def GetShowItemInlineKeyboard(self, a_Message, a_UserGroups, a_ItemID):
cur_buttons = [
keyboard.InlineButtonWithAccess(self.GetButton(ButtonNames.SHOW), self.GetShowPrefix(), a_ItemID, self.GetAccess(), user_access.AccessMode.VIEW),
]
return keyboard.MakeInlineKeyboardButtons(self.m_Bot, cur_buttons, a_UserGroups)
def GetViewItemInlineKeyboard(self, a_Message, a_UserGroups, a_ItemID):
if not self.m_ChildModName:
return None
child_mod = self.GetModule(self.m_ChildModName)
cur_buttons = [
keyboard.InlineButtonWithAccess(child_mod.GetButton(ButtonNames.LIST), child_mod.GetSelectPrefix(), a_ItemID, child_mod.GetAccess(), user_access.AccessMode.VIEW),
keyboard.InlineButtonWithAccess(child_mod.GetButton(ButtonNames.LIST), child_mod.GetSelectPrefix(), a_ItemID, self.GetAccess(), user_access.AccessMode.VIEW),
]
return keyboard.MakeInlineKeyboardButtons(self.m_Bot, cur_buttons, a_UserGroups)
@ -253,49 +214,23 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_Msg.UpdatePhotoID(','.join(photos))
return a_Msg
def GetParentID(self, a_Item, a_ItemDict, a_TableName):
parent_id = None
parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
if parent_id_field and a_ItemDict and parent_id_field in a_ItemDict:
parent_id = str(a_ItemDict[parent_id_field])
parent_id_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
if not parent_id and parent_id_field_id != None and a_Item and len(a_Item) == self.m_Table.GetFieldsCount() and self.m_Table.GetName() == a_TableName:
parent_id = str(a_Item[parent_id_field_id])
if self.m_ParentModName:
parent_mod = self.GetModule(self.m_ParentModName)
if parent_mod:
key_field_id = parent_mod.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)
if not parent_id and key_field_id != None and a_Item and len(a_Item) == parent_mod.m_Table.GetFieldsCount() and parent_mod.m_Table.GetName() == a_TableName:
parent_id = str(a_Item[key_field_id])
return parent_id
def GetMessageNameWithTableFieldDestinyAndValue(self, a_NameWithoutDestiny, a_Destiny, a_Value):
return a_NameWithoutDestiny + '?' + str(a_Destiny) + '=' + str(a_Value)
def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None, a_EnablePhoto = False):
async def ShowMessage(a_CallbackQuery, a_Item, a_ItemDict, table_name = self.m_Table.GetName()):
lang = str(a_CallbackQuery.from_user.language_code)
msg = a_Message
# Подменяем сообщение, если оно уже есть для PARENT_ID
parent_id = self.GetParentID(a_Item, a_ItemDict, table_name)
if parent_id:
name = self.GetMessageNameWithTableFieldDestinyAndValue(msg.GetName(), bd_table.TableFieldDestiny.PARENT_ID, parent_id)
parent_id_msg = a_Message.FindMessageForLang(name, lang)
if parent_id_msg:
msg = parent_id_msg
msg = msg.GetMessageForLang(lang).StaticCopy()
msg = a_Message.StaticCopy()
# TODO: добавить поддержку языков в a_MessageName
Inline_keyboard_func = None
item_access = None
if a_ItemDict:
lang = str(a_CallbackQuery.from_user.language_code)
msg = msg.GetMessageForLang(lang).StaticCopy()
msg = self.UpdateMessageByDict(msg, lang, a_ItemDict, a_EnablePhoto = a_EnablePhoto)
if a_Item and self.m_Table.GetName() == table_name:
if len(a_Item) < self.m_Table.GetFieldsCount() - 1: # Для проектов это нужно. Там на 1 меньше поле. TODO разделить отправку сообщений item_access и Inline_keyboard_func
return simple_message.WorkFuncResult(self.GetMessage(Messages.ERROR_FIND))
elif len(a_Item) == self.m_Table.GetFieldsCount():
lang = str(a_CallbackQuery.from_user.language_code)
msg = msg.GetMessageForLang(lang).StaticCopy()
msg = self.UpdateMessage(msg, lang, a_Item, a_EnablePhoto = a_EnablePhoto)
item_access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)]
if Inline_keyboard_template_func:
@ -312,34 +247,34 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
async def PostDelete(self, a_CallbackQuery, a_ItemID):
user_id = a_CallbackQuery.from_user.id
self.m_Log.Success(f'Элемент{a_ItemID} была удалена пользователем {user_id}.')
self.m_Log.Success(f'Задача{a_ItemID} была удалена пользователем {user_id}.')
#TODO: удалить вложенные
self.OnChange()
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_DEL
item_id = -1
await self.SendSubscribe(subscribe_type, item_id, user_id, item_id)
await self.SendSubscribe(subscribe_type, item_id, user_id)
subscribe_type = bot_subscribes.SubscribeType.ITEM_DEL
item_id = a_ItemID
await self.SendSubscribe(subscribe_type, item_id, user_id, item_id)
await self.SendSubscribe(subscribe_type, item_id, user_id)
table_name = self.m_Table.GetName()
key_name = self.GetKeyFieldName()
cur_item = GetCurItem(self.m_Bot, table_name, key_name, a_ItemID)
print(cur_item)
parent_id_field_index = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
if parent_id_field_index and cur_item and cur_item[parent_id_field_index]:
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_DEL_WITH_PARENT
item_id = cur_item[parent_id_field_index]
await self.SendSubscribe(subscribe_type, item_id, user_id, item_id)
await self.SendSubscribe(subscribe_type, item_id, user_id)
return simple_message.WorkFuncResult(self.GetMessage(Messages.SUCCESS_DELETE))
async def AddBDItemFunc(self, a_ItemData, a_UserID):
table_name = self.m_Table.GetName()
key_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY)
name_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.NAME)
photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO)
desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC)
@ -369,8 +304,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
values += ['?']
param += (a_ItemData[n], )
request = f'INSERT INTO {table_name}({",".join(fields)}) VALUES({",".join(values)})' # RETURNING {key_field}
#print('request', request, param)
request = f'INSERT INTO {table_name}({",".join(fields)}) VALUES({",".join(values)})'
print('request', request, param)
res, error = self.m_Bot.SQLRequest(request, commit = True, return_error = True, param = param)
self.OnChange()
@ -379,56 +314,36 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
else:
self.m_Log.Success(f'Пользователь {a_UserID}. Добавлена запись в таблицу {request} {param}.')
res_id, error_id = self.m_Bot.SQLRequest(f'SELECT rowid from {table_name} order by ROWID DESC limit 1', commit = False, return_error = True)
table_item_id = -1
if not error_id and res_id and len(res_id) == 1 and len(res_id[0]) == 1:
table_item_id = str(res_id[0][0])
#print('res_id', res, error, table_item_id)
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_ADD
item_id = -1
await self.SendSubscribe(subscribe_type, item_id, a_UserID, table_item_id)
await self.SendSubscribe(subscribe_type, item_id, a_UserID)
if parent_id_field and a_ItemData[parent_id_field]:
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_ADD_WITH_PARENT
item_id = a_ItemData[parent_id_field]
await self.SendSubscribe(subscribe_type, item_id, a_UserID, table_item_id)
await self.SendSubscribe(subscribe_type, item_id, a_UserID)
return res, error
async def SendMessageToUser(self, a_Message, a_UserID, a_GetButtonsFunc = None, a_GetInlineButtonsFunc = None, parse_mode = None):
a_Message = a_Message.StaticCopy()
a_MessageFromUSer = None
user_groups = groups_utils.GetUserGroupData(self.m_Bot, a_UserID)
try:
#print('SendMessage', self.m_Bot, a_Message, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_UserID, a_MessageFromUSer, user_groups, parse_mode)
await simple_message.SendMessage(self.m_Bot, a_Message, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_UserID, a_MessageFromUSer, user_groups, parse_mode=parse_mode)
return True
except:
return False
async def SendSubscribe(self, a_Type, a_ItemID, a_OwnerUserID, a_TableItem):
table_name = self.m_Table.GetName()
key_name = self.GetKeyFieldName()
cur_item = GetCurItem(self.m_Bot, table_name, key_name, a_TableItem)
async def SendSubscribe(self, a_Type, a_ItemID, a_OwnerUserID):
for s_user_id in self.m_BotSubscribes.GetUserIDs(self.GetName(), a_Type, a_ItemID = a_ItemID):
a_BotMessage = self.GetMessage(SubscribeMessage(a_Type))
#print('s_user_id', s_user_id, a_BotMessage, a_OwnerUserID, a_TableItem, cur_item)
if not a_BotMessage:
continue
if s_user_id == a_OwnerUserID:
continue
a_UserID = s_user_id
a_BotMessage = a_BotMessage.StaticCopy()
a_BotMessage.UpdateDesc(a_BotMessage.GetDesc().replace("#item_id", str(a_TableItem)))
inline_keyboard_func = None
if cur_item:
a_BotMessage.UpdateDesc(self.m_Table.ReplaceAllFieldTags(a_BotMessage.GetDesc(), cur_item))
inline_keyboard_func = self.GetShowItemInlineKeyboardTemplate(a_TableItem)
await self.SendMessageToUser(a_BotMessage, a_UserID, a_GetInlineButtonsFunc = inline_keyboard_func)
a_BotMessage.UpdateDesc(a_BotMessage.GetDesc().replace("#item_id", str(a_ItemID)))
a_GetButtonsFunc = None
a_GetInlineButtonsFunc = None
a_UserID = s_user_id
a_Message = None
user_groups = None
parse_mode = None
try:
await simple_message.SendMessage(self.m_Bot, a_BotMessage, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_UserID, a_Message, user_groups, parse_mode=parse_mode)
except:
return
def SelectSourceTemplate(self, a_PrevPrefix, a_ButtonName):
parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
@ -474,23 +389,24 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
async def OnChangeField(self, a_Field, a_ItemID, a_ItemData, a_EditUserID):
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_EDIT
item_id = -1
await self.SendSubscribe(subscribe_type, item_id, a_EditUserID, a_ItemID)
await self.SendSubscribe(subscribe_type, item_id, a_EditUserID)
subscribe_type = bot_subscribes.SubscribeType.ITEM_EDIT
item_id = a_ItemID
await self.SendSubscribe(subscribe_type, item_id, a_EditUserID, a_ItemID)
await self.SendSubscribe(subscribe_type, item_id, a_EditUserID)
table_name = self.m_Table.GetName()
key_name = self.GetKeyFieldName()
cur_item = GetCurItem(self.m_Bot, table_name, key_name, a_ItemID)
#print(cur_item)
print(cur_item)
parent_id_field_index = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
if parent_id_field_index and cur_item and cur_item[parent_id_field_index]:
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_EDIT_WITH_PARENT
item_id = cur_item[parent_id_field_index]
await self.SendSubscribe(subscribe_type, item_id, a_EditUserID, a_ItemID)
await self.SendSubscribe(subscribe_type, item_id, a_EditUserID)
def RegisterEdit(self, a_Field, a_AccessMode = user_access.AccessMode.EDIT):
a_ButtonName = self.GetButton(EditButton(a_Field.m_Destiny))
@ -516,7 +432,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True)
a_Prefix = bd_item_edit.EditBDItemRegisterHandlers(self.m_Bot, \
bd_item_edit.EditBDItemRegisterHandlers(self.m_Bot, \
self.SelectSourceTemplate(a_Prefix, a_ButtonName), \
MakeFSMForEdit(self.GetName(), a_FieldName), \
self.GetMessage(Messages.SELECT_TO_EDIT), \
@ -535,10 +451,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
field_type = a_FieldType\
)
self.m_EditPrefix.update({a_Field.m_Destiny: a_Prefix})
def GetAddFieldDestinys(self):
return (
def GetAddFields(self):
add_destiny = (
bd_table.TableFieldDestiny.NAME,
bd_table.TableFieldDestiny.DESC,
bd_table.TableFieldDestiny.PHOTO,
@ -552,9 +466,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
bd_table.TableFieldDestiny.USER_CONTACTS,
bd_table.TableFieldDestiny.USER_CONFIRM,
)
def GetAddFields(self):
add_destiny = self.GetAddFieldDestinys()
fields = []
for f in self.m_Table.GetFields():
if f.m_Destiny in add_destiny:
@ -651,7 +562,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
GetAccess,\
access_mode = user_access.AccessMode.VIEW\
)
self.m_ShowPrefix = a_Prefix
bd_item_view.ShowBDItemRegisterHandlers(self.m_Bot,\
a_Prefix,\
table_name,\
@ -666,8 +576,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_ButtonName = self.GetButton(ButtonNames.DEL)
if a_ButtonName:
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW)
self.m_DelPrefix = a_Prefix
bd_item_delete.DeleteBDItemRegisterHandlers(self.m_Bot, \
a_Prefix, \
table_name, \
@ -682,7 +590,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_ButtonName = self.GetButton(ButtonNames.ADD)
if a_ButtonName:
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True)
self.m_AddPrefix = a_Prefix
check_func = bd_item.GetCheckForTextFunc(a_ButtonName)
if a_Prefix:
@ -714,6 +621,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
bd_item.GetCheckForTextFunc(a_ButtonName)\
)
address_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ADDRESS)
status_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.STATUS)
for f in self.m_Table.GetFields():
self.RegisterEdit(f)

80
bot_modules/orders.py

@ -33,15 +33,13 @@ access_field = 'orderAccess'
create_datetime_field = 'orderCreateDateTime'
parent_id_field = 'catID'
pay_field = bd_table.TableField(photo_pay_field, bd_table.TableFieldDestiny.PHOTO_PAY, bd_table.TableFieldType.PHOTO)
table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
bd_table.TableField(user_id_field, bd_table.TableFieldDestiny.USER_ID, bd_table.TableFieldType.INT),
bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR),
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO),
pay_field,
bd_table.TableField(photo_pay_field, bd_table.TableFieldDestiny.PHOTO_PAY, bd_table.TableFieldType.PHOTO),
bd_table.TableField(status_field, bd_table.TableFieldDestiny.STATUS, bd_table.TableFieldType.ENUM, a_Enum = OrderStatus),
bd_table.TableField(address_field, bd_table.TableFieldDestiny.ADDRESS, bd_table.TableFieldType.STR),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
@ -59,12 +57,11 @@ class ButtonNames(Enum):
button_names = {
mod_simple_message.ButtonNames.START: "🛒 Заказы",
mod_table_operate.ButtonNames.SHOW: "☐ Открыть заказ",
mod_table_operate.ButtonNames.LIST: "📃 Список моих текущих заказов",
ButtonNames.LIST_ALL: "📃 Список всех моих заказов",
mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать мой заказ",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO_PAY): "🧾 Загрузить чек по оплате моего заказа",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO_PAY): " Загрузить чек по оплате моего заказа",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в моём заказе",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в моём заказе",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в моём заказе",
@ -85,9 +82,7 @@ messages = {
Ошибка, заказ не найден
''',
mod_table_operate.Messages.OPEN: f'''
<b>Номер заказа: #{key_name} </b>
<b>Имя заказа: #{name_field}</b>
<b>Заказ: #{name_field}</b>
<b>Описание и состав заказа:</b> #{desc_field}
@ -110,8 +105,8 @@ messages = {
mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): '''
Создание заказа. Шаг 3
Загрузите фотографию для заказа. Фото будет отображаться в его описании.
(Если фотографии нет, то нажмите "⏩ Пропустить")
Загрузите обложку для заказа (Фото):
Она будет отображаться в его описании.
''',
mod_table_operate.Messages.SUCCESS_CREATE: '''✅ Заказ успешно добавлен!''',
mod_table_operate.Messages.START_EDIT: '''
@ -135,7 +130,7 @@ messages = {
''',
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f'''
Текущее описание заказа:
<code>#{desc_field}</code>
#{desc_field}
Введите новое описание заказа:
''',
@ -176,18 +171,8 @@ messages_subscribes = {
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_DEL):f'''Заказ удалён''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ITEM_EDIT):f'''Заказ отредактирован #item_id''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ITEM_DEL):f'''Заказ удалён #item_id''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_ADD_WITH_PARENT):f'''Заказ создан
<b>Номер заказа: #{key_name} </b>
<b>Имя заказа: #{name_field}</b>
<b>Описание и состав заказа:</b> #{desc_field}''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_EDIT_WITH_PARENT):f'''Заказ отредактирован
<b>Номер заказа: #{key_name} </b>
<b>Имя заказа: #{name_field}</b>
<b>Описание и состав заказа:</b> #{desc_field}''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_ADD_WITH_PARENT):f'''Заказ создан''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_EDIT_WITH_PARENT):f'''Заказ отредактирован''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_DEL_WITH_PARENT):f'''Заказ удалён''',
}
@ -232,52 +217,12 @@ class ModuleOrders(mod_table_operate.TableOperateModule):
def AddBDItemFunc(self, a_ItemData, a_UserID):
parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
a_ItemData[name_field] = ''
a_ItemData[photo_field] = ''
a_ItemData[user_id_field] = a_UserID
a_ItemData[status_field] = str(OrderStatus.NEW)
a_ItemData[address_field] = ''
a_ItemData[photo_pay_field] = '0'
return super().AddBDItemFunc(a_ItemData, a_UserID)
def GetModuleButtons(self):
buttons = super().GetModuleButtons();
add_order_button = [
keyboard.ButtonWithAccess(self.GetButton(mod_table_operate.ButtonNames.ADD), user_access.AccessMode.ADD, self.GetAccess()),
]
return add_order_button + buttons
def GetNameFromDesc(self, a_Desc):
name = ''
lines = str(a_Desc).splitlines()
for l in lines:
name = l.strip();
if len(name) > 0:
break;
return name[0:16]
def GetButtonNameAndKeyValueAndAccess(self, a_Item):
user_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.USER_ID)
key_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)
desc_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.DESC)
n, k, a = super().GetButtonNameAndKeyValueAndAccess(a_Item)
return str(a_Item[key_field_id]) + ":" + str(self.GetNameFromDesc(a_Item[desc_field_id])), k, a
def GetAddFieldDestinys(self):
return (
bd_table.TableFieldDestiny.DESC,
)
def GetStartButtons(self, a_Message, a_UserGroups):
pay_access = self.GetAccessForEditKeyboardButtons(pay_field)
return [
[mod_table_operate.ButtonNames.ADD, user_access.AccessMode.ADD],
[mod_table_operate.EditButton(pay_field.m_Destiny), pay_access],
[mod_table_operate.ButtonNames.EDIT, user_access.AccessMode.EDIT],
[mod_table_operate.ButtonNames.LIST, user_access.AccessMode.VIEW],
[mod_table_operate.ButtonNames.DEL, user_access.AccessMode.DELETE],
]
def GetStartKeyboardButtons(self, a_Message, a_UserGroups):
parent_buttons = super().GetStartKeyboardButtons(a_Message, a_UserGroups)
cur_buttons = [
@ -325,12 +270,3 @@ class ModuleUserOrders(ModuleOrders):
def GetName(self):
return module_name
def GetShowItemInlineKeyboard(self, a_Message, a_UserGroups, a_ItemID):
all_orders_mod = self.GetModule('all_orders')
if not all_orders_mod:
return None
cur_buttons = [
keyboard.InlineButtonWithAccess(all_orders_mod.GetButton(mod_table_operate.ButtonNames.SHOW), all_orders_mod.GetShowPrefix(), a_ItemID, all_orders_mod.GetAccess(), user_access.AccessMode.VIEW),
]
return keyboard.MakeInlineKeyboardButtons(self.m_Bot, cur_buttons, a_UserGroups)

2
bot_modules/orders_cat.py

@ -1,7 +1,7 @@
# -*- coding: utf8 -*-
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru>
# Категории для заказов
# Проекты
from bot_sys import bot_bd, keyboard, user_access, bd_table, bot_subscribes
from bot_modules import mod_table_operate, mod_simple_message

143
bot_modules/user_message.py

@ -1,143 +0,0 @@
# -*- coding: utf8 -*-
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru>
# Сообщения пользователю
from bot_sys import bot_bd, keyboard, user_access, bd_table, bot_subscribes, bot_messages, interfaces
from bot_modules import mod_table_operate, mod_simple_message, users
# ---------------------------------------------------------
# БД
module_name = 'user_messge'
table_name = module_name
key_name = 'userMessageID'
desc_field = 'messageText'
access_field = 'catAccess'
create_datetime_field = 'catCreateDateTime'
parent_id_field = users.key_name
table = bd_table.Table(table_name, [
bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT),
bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR),
bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR),
bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR),
bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT),
])
init_access = f'{user_access.user_access_group_new}=-'
# ---------------------------------------------------------
# Сообщения и кнопки
button_names = {
mod_simple_message.ButtonNames.START: "📩 Сообщения для польователей",
mod_table_operate.ButtonNames.LIST: "📃 Список отправленных сообщений",
mod_table_operate.ButtonNames.ADD: "📨 Отправить сообщение",
mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать сообщение",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание у сообщения",
mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к сообщению",
mod_table_operate.ButtonNames.DEL: "❌ Удалить отправленное сообщение",
}
messages = {
mod_simple_message.Messages.START: f'''
<b>{button_names[mod_simple_message.ButtonNames.START]}</b>
''',
mod_table_operate.Messages.SELECT: '''
Пожалуйста, выберите сообщение:
''',
mod_table_operate.Messages.ERROR_FIND: '''
Ошибка, сообщение не найдено
''',
mod_table_operate.Messages.OPEN: f'''
<b>Категория: </b>
Пользоватеель: #{parent_id_field}
Текст сообщения: #{desc_field}
Время создания: #{create_datetime_field}
''',
mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): '''
Отправка сообщения
Введите текст сообщения:
''',
mod_table_operate.Messages.SUCCESS_CREATE: f'''✅ Сообщение успешно отправлено пользователю!''',
mod_table_operate.Messages.START_EDIT: '''
Пожалуйста, выберите действие:
''',
mod_table_operate.Messages.SELECT_TO_EDIT: '''
Выберите проект, который вы хотите отредактировать.
''',
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f'''
Текущий текст сообщения:
#{desc_field}
Введите новый текст:
''',
mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f'''
Текущий доступ к сообщению:
#{access_field}
{user_access.user_access_readme}
Введите новую строку доступа:
''',
mod_table_operate.Messages.SUCCESS_EDIT: '''✅ Сообщение успешно отредактировано!''',
mod_table_operate.Messages.SELECT_TO_DELETE: '''
Выберите категорию, которую вы хотите удалить.
''',
mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Сообщение успешно удалёно!''',
}
messages_subscribes = {
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_ADD):f'''Сообщение создано''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_EDIT):f'''Сообщение отредактировано''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_DEL):f'''Сообщение удалено''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ITEM_EDIT):f'''Сообщение отредактировано #item_id''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ITEM_DEL):f'''Сообщение удалено #item_id''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_ADD_WITH_PARENT):f'''Сообщение создано''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_EDIT_WITH_PARENT):f'''Сообщение отредактировано''',
mod_table_operate.SubscribeMessage(bot_subscribes.SubscribeType.ANY_ITEM_DEL_WITH_PARENT):f'''Сообщение удалено''',
}
messages.update(messages_subscribes)
class ModuleUserMessage(mod_table_operate.TableOperateModule):
def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log):
super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log)
def GetName(self):
return module_name
async def AddBDItemFunc(self, a_ItemData, a_UserID):
res, error = await super().AddBDItemFunc(a_ItemData, a_UserID)
desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC)
user_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
if not await self.SendMessageToUser(bot_messages.MakeBotMessage(a_ItemData[desc_field]), a_ItemData[user_id_field], parse_mode=interfaces.ParseMode.HTML.value):
return None, '❌ Ошибка отправки сообщения'
return res, error
def GetStartButtons(self, a_Message, a_UserGroups):
return [
[mod_table_operate.ButtonNames.ADD, user_access.AccessMode.ADD],
[mod_table_operate.ButtonNames.LIST, user_access.AccessMode.VIEW],
[mod_table_operate.ButtonNames.EDIT, user_access.AccessMode.EDIT],
[mod_table_operate.ButtonNames.DEL, user_access.AccessMode.DELETE],
]
def GetButtonNameAndKeyValueAndAccess(self, a_Item):
key_name_id = self.GetKeyFieldID()
date_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.CREATE_DATE)
access_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)
assert key_name_id != None
assert date_field_id != None
assert access_field_id != None
return \
a_Item[date_field_id],\
a_Item[key_name_id],\
a_Item[access_field_id]

13
bot_modules/users.py

@ -66,7 +66,7 @@ messages = {
<b>Пользователь: #{name_field}</b>
<b>ID:</b> #{key_name}
<b>Имя:</b> @#{name_field}
<b>Имя:</b> #{name_field}
<b>Имя1:</b> #{name1_field}
<b>Имя2:</b> #{name2_field}
<b>Код языка:</b> #{language_code_field}
@ -133,17 +133,6 @@ class ModuleUsers(mod_table_operate.TableOperateModule):
def GetName(self):
return module_name
def GetButtonNameAndKeyValueAndAccess(self, a_Item):
key_name_id = self.GetKeyFieldID()
name_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.NAME)
access_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)
assert key_name_id != None
assert name_field_id != None
assert access_field_id != None
return \
a_Item[name_field_id] + '(' + str(a_Item[key_name_id]) + ')',\
a_Item[key_name_id],\
a_Item[access_field_id]
# Работа с базой данных пользователей

10
bot_sys/bd_table.py

@ -109,9 +109,7 @@ class Table:
result = a_String
for i in range(len(self.m_Fields)):
f = self.m_Fields[i]
name = f'#{f.m_Name}'
result = result.replace('<code>' + name + '</code>', '<code>' + str(a_BDItem[i]).replace('\n', '</code>\n<code>') + '</code>')
result = result.replace(name, str(a_BDItem[i]))
result = result.replace(f'#{f.m_Name}', str(a_BDItem[i]))
return result
def ReplaceAllFieldTagsByDict(self, a_String, a_BDItemDict):
@ -170,7 +168,5 @@ def Test():
print(table.GetInitTableRequest())
assert table.GetInitTableRequest() == 'CREATE TABLE IF NOT EXISTS tname(f1 INTEGER PRIMARY KEY, f2 TEXT, f3 TEXT, f4 TEXT, UNIQUE(f1), UNIQUE(f2, f3));'
item = [10, 'i2\ni2.1', 'i3', 'i4']
assert table.ReplaceAllFieldTags('#f1 #f2 #f3 #f4', item) == '10 i2\ni2.1 i3 i4'
assert table.ReplaceAllFieldTags('#f1 <code>#f2</code> <code>#f3</code> #f4', item) == '10 <code>i2</code>\n<code>i2.1</code> <code>i3</code> i4', table.ReplaceAllFieldTags('f1 <code>#f2</code> <code>#f3</code> #f4', item)
item = [10, 'i2', 'i3', 'i4']
assert table.ReplaceAllFieldTags('#f1 #f2 #f3 #f4', item) == '10 i2 i3 i4'

1
bot_sys/bot_bd.py

@ -21,7 +21,6 @@ def RequestSelectTemplate(a_Bot, a_TableName):
return SelectBD
def SQLRequest(a_Log, a_BDFileName, a_Request : str, commit = False, return_error = False, param = None):
#print('SQLRequest', a_Request, commit)
db = sqlite3.connect(a_BDFileName)
cursor = db.cursor()
result = []

42
bot_sys/bot_messages.py

@ -37,40 +37,23 @@ class BotMessage:
msg = self.GetMessageForLang(self.m_Language)
return msg.GetDesc()
def GetCurLang(self, a_Language):
msg = self.m_BotMessages.GetMessages()
if not msg.get(a_Language, None):
a_Language = self.m_Language
if not msg.get(a_Language, None):
a_Language = self.m_BotMessages.a_DefaultLanguage
return a_Language
def FindMessageForLang(self, a_Name, a_Language):
if not self.m_BotMessages:
return None
msg = self.m_BotMessages.GetMessages()
a_Language = self.GetCurLang(a_Language)
if not msg.get(a_Language, None):
return None
new_msg = msg[a_Language].get(a_Name, None)
return new_msg
def GetMessageForLang(self, a_Language):
if not self.m_BotMessages:
return self
last_update = self.m_BotMessages.m_LastUpdate
new_msg = self
if self.m_DateTime < last_update:
a_Language = self.GetCurLang(a_Language)
new_msg = self.FindMessageForLang(self.m_MessageName, a_Language)
if not new_msg:
new_msg = self
elif a_Language == self.m_Language:
msg = self.m_BotMessages.GetMessages()
if not msg.get(a_Language, None):
a_Language = self.m_Language
if not msg.get(a_Language, None):
a_Language = self.m_BotMessages.a_DefaultLanguage
new_msg = msg[a_Language].get(self.m_MessageName, self)
if a_Language == self.m_Language:
self.m_MessageDesc = new_msg.m_MessageDesc
self.m_Language = new_msg.m_Language
self.m_PhotoID = new_msg.m_PhotoID
self.m_DateTime = last_update
self.m_DateTime = new_msg.m_DateTime
return new_msg
def MakeBotMessage(a_MessageDesc):
@ -85,15 +68,6 @@ class BotMessages:
def GetMessages(self):
return self.m_Messages
def CheckDescExist(self, a_MessageDesc):
msg = self.GetMessages()
for l, m in msg.items():
for name, cur_msg in m.items():
if cur_msg.GetDesc() == a_MessageDesc:
return True
return False
def UpdateSignal(self, a_DateTime):
self.m_LastUpdate = a_DateTime

8
bot_sys/interfaces.py

@ -3,14 +3,6 @@
from abc import ABC, abstractmethod
from enum import Enum
from enum import auto
# Способ форматирования
class ParseMode(Enum):
HTML = "HTML"
Markdown ='Markdown'
class IBot(ABC):
@abstractmethod
def GetRootIDs(self):

7
main.py

@ -7,7 +7,6 @@ from bot_sys import config, log, aiogram_bot, bot_messages, bd_table, user_acces
from bot_modules import mod_agregator, start, profile, backup, users_groups_agregator, access, projects, tasks, needs, comments
from bot_modules import languages, messages, buttons, users, groups, user_in_groups
from bot_modules import orders_cat, orders, all_orders, authorize
from bot_modules import user_message
from bot_modules import bd_version
from bot_sys import bot_subscribes
@ -44,7 +43,6 @@ mod_user_in_groups_name = user_in_groups.module_name
mod_orders_cat_name = orders_cat.module_name
mod_orders_name = orders.module_name
mod_all_orders_name = all_orders.module_name
mod_user_message_name = user_message.module_name
start_mod_list = [mod_start_name]
mod_access = access.ModuleAccess(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_BotSubscribes, g_Log)
@ -53,9 +51,6 @@ g_ModuleAgregator.AddModule(mod_access)
mod_users = users.ModuleUsers(None, None, start_mod_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_BotSubscribes, g_Log)
g_ModuleAgregator.AddModule(mod_users)
mod_user_message = user_message.ModuleUserMessage(mod_users_name, None, start_mod_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_BotSubscribes, g_Log)
g_ModuleAgregator.AddModule(mod_user_message)
child_mod_name_list = [mod_start_name, mod_users_name, mod_user_in_groups_name]
mod_groups = groups.ModuleGroups(None, mod_user_in_groups_name, child_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_BotSubscribes, g_Log)
g_ModuleAgregator.AddModule(mod_groups)
@ -63,7 +58,7 @@ g_ModuleAgregator.AddModule(mod_groups)
mod_user_in_groups = user_in_groups.ModuleUserInGroups(mod_groups_name, None, start_mod_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_BotSubscribes, g_Log)
g_ModuleAgregator.AddModule(mod_user_in_groups)
child_mod_name_list = [mod_start_name, mod_users_name, mod_groups_name, mod_user_in_groups_name, mod_user_message_name]
child_mod_name_list = [mod_start_name, mod_users_name, mod_groups_name, mod_user_in_groups_name]
mod_users_groups_agregator = users_groups_agregator.ModuleUsersGroupsAgregator(child_mod_name_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_BotSubscribes, g_Log)
g_ModuleAgregator.AddModule(mod_users_groups_agregator)

1
requirements.txt

@ -5,4 +5,3 @@ Django==2.2.1
python-dotenv==0.21.1
requests==2.31.0
urllib3==1.25.11

31
template/bd_item_edit.py

@ -18,23 +18,7 @@ error_photo_type_message = '''
def StartEditBDItemTemplate(a_Bot, a_FSM, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.EDIT):
return bd_item_add.StartAddBDItemTemplate(a_Bot, a_FSM, a_FSM.item_field, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = access_mode)
def FinishEditBDItemTemplate(a_Bot, a_EditBDItemFunc, a_FSM, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
return bd_item_add.FinishAddBDItemTemplate(a_Bot, a_FSM, a_EditBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, field_type = field_type)
def CustomEditBDItemRegisterHandlers(a_Bot, a_EditBDItemFunc, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName, a_KeyName, a_FieldName, a_PostProcessFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_AdditionalButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
keyboard = bd_item.MixKeyboardFuncTemplate(a_AdditionalButtonFunc, bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode))
a_Prefix = bd_item_select.SelectRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode)
a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard, a_FinishButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix))
if field_type == bd_item.FieldType.photo:
a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_EditBDItemFunc, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_PostProcessFunc, a_AccessFunc, a_FinishButtonFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field)
else:
a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_EditBDItemFunc, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_PostProcessFunc, a_AccessFunc, a_FinishButtonFunc, access_mode, field_type = field_type), state = a_FSM.item_field)
return a_Prefix
def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName, a_KeyName, a_FieldName, a_PostProcessFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_AdditionalButtonFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
async def EditBDItemFunc(a_ItemData, a_UserID):
item_id = a_ItemData[a_KeyName]
field_value = a_ItemData[a_FieldName]
@ -47,4 +31,15 @@ def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_E
await a_OnChangeFunc(item_id, a_ItemData, a_UserID)
return res, error
return CustomEditBDItemRegisterHandlers(a_Bot, EditBDItemFunc, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName, a_KeyName, a_FieldName, a_PostProcessFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_AdditionalButtonFunc, a_FinishButtonFunc, access_mode = access_mode, field_type = field_type)
return bd_item_add.FinishAddBDItemTemplate(a_Bot, a_FSM, EditBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, field_type = field_type)
def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName, a_KeyName, a_FieldName, a_PostProcessFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_AdditionalButtonFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
keyboard = bd_item.MixKeyboardFuncTemplate(a_AdditionalButtonFunc, bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode))
a_Prefix = bd_item_select.SelectRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode)
a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard, a_FinishButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix))
if field_type == bd_item.FieldType.photo:
a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_PostProcessFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field)
else:
a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_PostProcessFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), state = a_FSM.item_field)

2
template/simple_message.py

@ -53,8 +53,6 @@ def SimpleMessageTemplate(a_Bot, a_WorkFunc, a_GetButtonsFunc, a_GetInlineButton
if res is None:
return
user_groups = groups_utils.GetUserGroupData(a_Bot, user_id) # При самом первом запуске a_WorkFunc добавляет пользователя
Inline_keyboard_func = a_GetInlineButtonsFunc
if res.Inline_keyboard_func:
Inline_keyboard_func = res.Inline_keyboard_func

4
template/sql_request.py

@ -3,7 +3,7 @@
# Сообщения для работы с sql запросами
from bot_sys import user_access, keyboard, bot_messages, interfaces
from bot_sys import user_access, keyboard, bot_messages
from bot_modules import groups_utils
from template import bd_item, simple_message
@ -31,7 +31,7 @@ def RequestToBDTemplate(a_Bot, a_StartMessage, a_GetButtonsFunc, a_AccessFunc, a
await a_FSM.sqlRequest.set()
print ('a_FSM.sqlRequest.set()', a_StartMessage)
await simple_message.SendMessage(a_Bot, a_StartMessage, GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, a_AccessMode), None, user_id, a_Message, user_groups, parse_mode=interfaces.ParseMode.Markdown.value)
await simple_message.SendMessage(a_Bot, a_StartMessage, GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, a_AccessMode), None, user_id, a_Message, user_groups, parse_mode='Markdown')
return RequestToBDStart
def RequestToBDFinishTemplate(a_Bot, a_GetButtonsFunc, a_AccessFunc, a_AccessMode):

Loading…
Cancel
Save