Browse Source

Сообщения и языки работают

pull/2/head
Alexei 2 years ago
parent
commit
a02164eca3
  1. 1
      bot_modules/messages.py
  2. 2
      bot_modules/mod_table_operate.py
  3. 2
      bot_modules/profile.py
  4. 18
      bot_sys/aiogram_bot.py
  5. 7
      bot_sys/bot_messages.py
  6. 30
      bot_sys/keyboard.py

1
bot_modules/messages.py

@ -184,6 +184,7 @@ class ModuleMessages(mod_table_operate.TableOperateModule):
for msg_name, message in msg_dict.items(): for msg_name, message in msg_dict.items():
self.AddOrIgnoreMessage(message) self.AddOrIgnoreMessage(message)
table_name = self.m_Table.GetName()
msgs_bd = bd_item.GetAllItemsTemplate(self.m_Bot, table_name)() msgs_bd = bd_item.GetAllItemsTemplate(self.m_Bot, table_name)()
if msgs_bd: if msgs_bd:
for m in msgs_bd: for m in msgs_bd:

2
bot_modules/mod_table_operate.py

@ -140,6 +140,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
if len(a_Item) < self.m_Table.GetFieldsCount() - 1: # Для проектов это нужно. Там на 1 меньше поле. TODO разделить отправку сообщений item_access и Inline_keyboard_func 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)) return simple_message.WorkFuncResult(self.GetMessage(Messages.ERROR_FIND))
elif len(a_Item) == self.m_Table.GetFieldsCount(): elif len(a_Item) == self.m_Table.GetFieldsCount():
lang = str(a_CallbackQuery.from_user.language_code)
msg = msg.GetMessageForLang(lang).StaticCopy()
msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(msg.GetDesc(), a_Item)) msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(msg.GetDesc(), a_Item))
photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO) photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO)
if photo_field: if photo_field:

2
bot_modules/profile.py

@ -68,7 +68,7 @@ class ModuleProfile(mod_simple_message.SimpleMessageModule):
user_info = GetUserInfo(self.m_Bot, a_Message.from_user.id) user_info = GetUserInfo(self.m_Bot, a_Message.from_user.id)
lang = str(a_Message.from_user.language_code) lang = str(a_Message.from_user.language_code)
if not user_info is None: if not user_info is None:
msg = self.GetButton(mod_simple_message.ButtonNames.START) msg = self.GetMessage(mod_simple_message.Messages.START)
msg = msg.GetMessageForLang(lang).StaticCopy() msg = msg.GetMessageForLang(lang).StaticCopy()
msg.UpdateDesc(table.ReplaceAllFieldTags(msg.GetDesc(), user_info)) msg.UpdateDesc(table.ReplaceAllFieldTags(msg.GetDesc(), user_info))
return simple_message.WorkFuncResult(msg, item_access = str(user_info[table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)])) return simple_message.WorkFuncResult(msg, item_access = str(user_info[table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)]))

18
bot_sys/aiogram_bot.py

@ -9,24 +9,6 @@ from aiogram.dispatcher import Dispatcher
from aiogram.contrib.fsm_storage.memory import MemoryStorage from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.utils import executor from aiogram.utils import executor
def MakeAiogramInlineKeyboards(a_ButtonList : [InlineButton]):
buttons = []
for row in a_ButtonList:
r = []
for b in row:
r += [types.InlineKeyboardButton(text = str(b.label), callback_data = b.callback_data)]
buttons += [r]
button_list_chunks = keyboard.Chunks(buttons, 20)
result = []
for c in button_list_chunks:
result += [InlineKeyboardMarkup(inline_keyboard=c)]
return result
def MakeAiogramKeyboard(a_ButtonList : [[str]]):
return types.ReplyKeyboardMarkup(keyboard=a_ButtonList, resize_keyboard = True)
class AiogramBot(interfaces.IBot): class AiogramBot(interfaces.IBot):
def __init__(self, a_TelegramBotApiToken, a_BDFileName, a_RootIDs, a_Log): def __init__(self, a_TelegramBotApiToken, a_BDFileName, a_RootIDs, a_Log):
self.m_TelegramBotApiToken = a_TelegramBotApiToken self.m_TelegramBotApiToken = a_TelegramBotApiToken

7
bot_sys/bot_messages.py

@ -76,9 +76,8 @@ class BotMessages:
a_MessageLang = self.a_DefaultLanguage a_MessageLang = self.a_DefaultLanguage
cur_msg = BotMessage(self, a_MessageName, a_MessageDesc, a_MessageLang, a_MessagePhotoID, a_DateTime) cur_msg = BotMessage(self, a_MessageName, a_MessageDesc, a_MessageLang, a_MessagePhotoID, a_DateTime)
msg = self.GetMessages() msg = self.GetMessages()
if not msg.get(self.a_DefaultLanguage, None): if not msg.get(a_MessageLang, None):
msg[self.a_DefaultLanguage] = {} msg[a_MessageLang] = {}
if not msg[self.a_DefaultLanguage].get(a_MessageName, None): msg[a_MessageLang][a_MessageName] = cur_msg
msg[self.a_DefaultLanguage][a_MessageName] = cur_msg
return cur_msg return cur_msg

30
bot_sys/keyboard.py

@ -4,8 +4,9 @@
# Работа с кнопками и клавиатурой # Работа с кнопками и клавиатурой
from bot_sys import user_access from bot_sys import user_access
from aiogram import types, Bot, Dispatcher
from aiogram.types import ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton, InlineKeyboardMarkup, InlineKeyboardButton from aiogram.types import ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton, InlineKeyboardMarkup, InlineKeyboardButton
from aiogram import types
class ButtonWithAccess: class ButtonWithAccess:
def __init__(self, a_Label, a_AccessMode : user_access.AccessMode, a_AccessString): def __init__(self, a_Label, a_AccessMode : user_access.AccessMode, a_AccessString):
@ -47,9 +48,6 @@ def MakeButtons(a_ButtonList : [ButtonWithAccess], a_UserGroups):
def MakeKeyboard(a_ButtonList : [ButtonWithAccess], a_UserGroups): def MakeKeyboard(a_ButtonList : [ButtonWithAccess], a_UserGroups):
return MakeAiogramKeyboard(MakeButtons(a_ButtonList, a_UserGroups)) return MakeAiogramKeyboard(MakeButtons(a_ButtonList, a_UserGroups))
def MakeKeyboardRemove():
return types.ReplyKeyboardRemove()
def MakeKeyboardForMods(a_ModList, a_UserGroups): def MakeKeyboardForMods(a_ModList, a_UserGroups):
buttons = GetButtons(a_ModList) buttons = GetButtons(a_ModList)
return MakeKeyboard(buttons, a_UserGroups) return MakeKeyboard(buttons, a_UserGroups)
@ -79,3 +77,27 @@ def MakeInlineKeyboardButtons(a_ButtonList : [InlineButtonWithAccess], a_UserGro
def MakeInlineKeyboard(a_ButtonList : [InlineButtonWithAccess], a_UserGroups): def MakeInlineKeyboard(a_ButtonList : [InlineButtonWithAccess], a_UserGroups):
return MakeAiogramInlineKeyboard(MakeInlineKeyboardButtons(a_ButtonList, a_UserGroups)) return MakeAiogramInlineKeyboard(MakeInlineKeyboardButtons(a_ButtonList, a_UserGroups))
# -------------------------------
def MakeKeyboardRemove():
return types.ReplyKeyboardRemove()
def MakeAiogramInlineKeyboards(a_ButtonList : [InlineButton]):
buttons = []
for row in a_ButtonList:
r = []
for b in row:
r += [types.InlineKeyboardButton(text = str(b.label), callback_data = b.callback_data)]
buttons += [r]
button_list_chunks = Chunks(buttons, 20)
result = []
for c in button_list_chunks:
result += [InlineKeyboardMarkup(inline_keyboard=c)]
return result
def MakeAiogramKeyboard(a_ButtonList : [[str]]):
return types.ReplyKeyboardMarkup(keyboard=a_ButtonList, resize_keyboard = True)

Loading…
Cancel
Save