From dbb12983fb6ca561dca34c3cd0e91c34581dc7ab Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 31 May 2023 14:36:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=BE=D1=82=D0=BE=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D1=87=D0=B5=D0=BA=D0=B0=20=D0=B2=20=D0=B7=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D0=B0=D1=85=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=BE=D1=81=D1=8C=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=BA=D0=B8=D1=85=20=D1=84=D0=BE=D1=82=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D1=84=D0=B8=D0=B9=20=D0=B7=D0=B0=20=D1=80=D0=B0=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/buttons.py | 2 +- bot_modules/comments.py | 2 +- bot_modules/groups.py | 2 +- bot_modules/languages.py | 2 +- bot_modules/messages.py | 2 +- bot_modules/mod_simple_message.py | 1 + bot_modules/mod_table_operate.py | 24 ++++++++++-------------- bot_modules/needs.py | 2 +- bot_modules/orders.py | 9 ++++++++- bot_modules/projects.py | 2 +- bot_modules/tasks.py | 2 +- bot_modules/users.py | 2 +- bot_sys/aiogram_bot.py | 24 +++++++++++++++++++++--- bot_sys/bd_table.py | 3 +++ 14 files changed, 52 insertions(+), 27 deletions(-) diff --git a/bot_modules/buttons.py b/bot_modules/buttons.py index a38cc71..a268b93 100644 --- a/bot_modules/buttons.py +++ b/bot_modules/buttons.py @@ -27,7 +27,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), table_name_field, 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.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), 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), table_parent_id_field, diff --git a/bot_modules/comments.py b/bot_modules/comments.py index 3359cd6..28eb8c7 100644 --- a/bot_modules/comments.py +++ b/bot_modules/comments.py @@ -23,7 +23,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, 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.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), 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), diff --git a/bot_modules/groups.py b/bot_modules/groups.py index 0a51cc5..7724eeb 100644 --- a/bot_modules/groups.py +++ b/bot_modules/groups.py @@ -25,7 +25,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), table_name_field, 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.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), 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), ], diff --git a/bot_modules/languages.py b/bot_modules/languages.py index c6a1b15..66af1b9 100644 --- a/bot_modules/languages.py +++ b/bot_modules/languages.py @@ -25,7 +25,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), table_name_field, 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.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), 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), ], diff --git a/bot_modules/messages.py b/bot_modules/messages.py index b8bae87..2506c2a 100644 --- a/bot_modules/messages.py +++ b/bot_modules/messages.py @@ -27,7 +27,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), table_name_field, 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.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), 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), table_parent_id_field, diff --git a/bot_modules/mod_simple_message.py b/bot_modules/mod_simple_message.py index 40c78fd..1cc9621 100644 --- a/bot_modules/mod_simple_message.py +++ b/bot_modules/mod_simple_message.py @@ -72,6 +72,7 @@ class SimpleMessageModule(mod_interface.IModule): assert len(a_ButtonDesc) < 41 # Телеграм не поддерживает больше 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 diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 8705d8d..dd109b6 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -131,15 +131,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): def GetEditKeyboardButtons(self, a_Message, a_UserGroups): mod_buttons = keyboard.MakeButtons(self.m_Bot, self.GetButtons(self.m_EditModuleNameList), a_UserGroups) - cur_buttons = [ - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.PHOTO)), user_access.AccessMode.VIEW, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.NAME)), user_access.AccessMode.ADD, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.DESC)), user_access.AccessMode.DELETE, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.ACCESS)), user_access.AccessMode.DELETE, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.DEFAULT_ACCESS)), user_access.AccessMode.EDIT, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.ADDRESS)), user_access.AccessMode.EDIT, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.STATUS)), user_access.AccessMode.EDIT, self.GetAccess()), - ] + cur_buttons = [] + for f in self.m_Table.GetFields(): + cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(EditButton(f.m_Destiny)), user_access.AccessMode.EDIT, self.GetAccess()),] return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) def GetViewItemInlineKeyboardTemplate(self, a_ItemID): @@ -173,18 +167,20 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): def UpdateMessage(self, a_Msg, a_Lang, a_Item): a_Msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(a_Msg.GetDesc(), a_Item)) - photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO) - if photo_field: - a_Msg.UpdatePhotoID(a_Item[photo_field]) + photos = [] + field_id = 0 for f in self.m_Table.GetFields(): if f.m_Type == bd_table.TableFieldType.ENUM: for s in f.m_Enum: msg = self.GetMessage(EnumMessageForView(s)) if msg: a_Msg.UpdateDesc(a_Msg.GetDesc().replace(str(s), str(msg.GetMessageForLang(a_Lang).StaticCopy()))) + elif f.m_Type == bd_table.TableFieldType.PHOTO: + photos += [str(a_Item[field_id])] + field_id += 1 + a_Msg.UpdatePhotoID(','.join(photos)) return a_Msg - def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None): async def ShowMessage(a_CallbackQuery, a_Item): msg = a_Message.StaticCopy() @@ -307,7 +303,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_FieldName = a_Field.m_Name a_FieldType = bd_item.FieldType.text - if a_Field.m_Destiny == bd_table.TableFieldDestiny.PHOTO: + if a_Field.m_Type == bd_table.TableFieldType.PHOTO: a_FieldType = bd_item.FieldType.photo if not a_ButtonName or not a_EditMessage: diff --git a/bot_modules/needs.py b/bot_modules/needs.py index d180438..449f413 100644 --- a/bot_modules/needs.py +++ b/bot_modules/needs.py @@ -23,7 +23,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, 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.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), 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), diff --git a/bot_modules/orders.py b/bot_modules/orders.py index 227ea9f..82184a9 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -25,6 +25,7 @@ key_name = 'orderID' name_field = 'orderName' desc_field = 'orderDesc' photo_field = 'orderPhoto' +photo_pay_field = 'orderPhotoPay' status_field = 'orderStatus' address_field = 'orderAddress' access_field = 'orderAccess' @@ -35,7 +36,8 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, 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.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), + 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), @@ -57,6 +59,7 @@ button_names = { ButtonNames.LIST_CURRENT: "📃 Список моих текущих заказов", 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): "☐ Изменить изображение в моём заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в моём заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в моём заказе", @@ -110,6 +113,9 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите заказ, который вы хотите отредактировать. ''', + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO_PAY): ''' +Загрузите чек по оплате заказа (фото): +''', mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для заказа (Фото): Она будет отображаться в его описании. @@ -200,6 +206,7 @@ class ModuleOrders(mod_table_operate.TableOperateModule): a_ItemData[parent_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 GetStartKeyboardButtons(self, a_Message, a_UserGroups): diff --git a/bot_modules/projects.py b/bot_modules/projects.py index fb28514..8a601ee 100644 --- a/bot_modules/projects.py +++ b/bot_modules/projects.py @@ -22,7 +22,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, 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.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), 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), ]) diff --git a/bot_modules/tasks.py b/bot_modules/tasks.py index 39a3dfa..4234622 100644 --- a/bot_modules/tasks.py +++ b/bot_modules/tasks.py @@ -23,7 +23,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, 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.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), 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), diff --git a/bot_modules/users.py b/bot_modules/users.py index 8b871ab..f56386c 100644 --- a/bot_modules/users.py +++ b/bot_modules/users.py @@ -29,7 +29,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(name2_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), bd_table.TableField(is_bot_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), bd_table.TableField(language_code_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), 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), ]) diff --git a/bot_sys/aiogram_bot.py b/bot_sys/aiogram_bot.py index 6b4ccca..692c0a1 100644 --- a/bot_sys/aiogram_bot.py +++ b/bot_sys/aiogram_bot.py @@ -9,6 +9,16 @@ from aiogram.dispatcher import Dispatcher from aiogram.contrib.fsm_storage.memory import MemoryStorage from aiogram.utils import executor +def GetPhotoList(a_PhotoIDs): + if not a_PhotoIDs or a_PhotoIDs == 0: + return [] + photos = a_PhotoIDs.split(",") + result = [] + for p in photos: + if p != '0' and p != '': + result += [p] + return result + class AiogramBot(interfaces.IBot): def __init__(self, a_TelegramBotApiToken, a_BDFileName, a_RootIDs, a_Log): self.m_TelegramBotApiToken = a_TelegramBotApiToken @@ -39,19 +49,27 @@ class AiogramBot(interfaces.IBot): base_keyboards = [keyboard.MakeAiogramKeyboard(a_KeyboardButtons)] if inline_keyboards: base_keyboards = inline_keyboards - if a_PhotoIDs and a_PhotoIDs != 0 and a_PhotoIDs != '0': + photos = GetPhotoList(a_PhotoIDs) + if len(photos) > 0: + for p in photos[:-1]: + await self.m_TBot.send_photo( + a_UserID, + p, + '' + ) + p = photos[-1] if base_keyboards: for k in base_keyboards: await self.m_TBot.send_photo( a_UserID, - a_PhotoIDs, + p, a_Message, reply_markup = k ) else: await self.m_TBot.send_photo( a_UserID, - a_PhotoIDs, + p, a_Message ) else: diff --git a/bot_sys/bd_table.py b/bot_sys/bd_table.py index e09f4b4..d9c6bb9 100644 --- a/bot_sys/bd_table.py +++ b/bot_sys/bd_table.py @@ -9,12 +9,14 @@ class TableFieldType(Enum): INT = auto() STR = auto() ENUM = auto() + PHOTO = auto() def InitTableType(a_TableFieldType): types = { TableFieldType.INT: 'INTEGER', TableFieldType.STR: 'TEXT', TableFieldType.ENUM: 'TEXT', + TableFieldType.PHOTO: 'TEXT', } return types.get(a_TableFieldType, None) @@ -24,6 +26,7 @@ class TableFieldDestiny(Enum): NAME = auto() DESC = auto() PHOTO = auto() + PHOTO_PAY = auto() ACCESS = auto() DEFAULT_ACCESS = auto() CREATE_DATE = auto()