|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
#-*-coding utf-8-*- |
|
|
|
|
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru> |
|
|
|
|
|
|
|
|
|
from bot_sys import interfaces, bot_bd, keyboard |
|
|
|
|
from bot_sys import interfaces, bot_bd, keyboard, user_access |
|
|
|
|
|
|
|
|
|
from aiogram import types |
|
|
|
|
from aiogram import Bot |
|
|
|
@ -17,68 +17,47 @@ class AiogramBot(interfaces.IBot):
|
|
|
|
|
self.m_Log = a_Log |
|
|
|
|
self.m_TBot = Bot(token=self.m_TelegramBotApiToken, parse_mode = types.ParseMode.HTML) |
|
|
|
|
self.m_Storage = MemoryStorage() |
|
|
|
|
self.m_Dispatcher = Dispatcher(self.m_TBot, storage = storage) |
|
|
|
|
self.m_Dispatcher = Dispatcher(self.m_TBot, storage = self.m_Storage) |
|
|
|
|
|
|
|
|
|
def GetRootIDs(): |
|
|
|
|
def GetRootIDs(self): |
|
|
|
|
return self.m_RootIDs |
|
|
|
|
|
|
|
|
|
def GetLog(): |
|
|
|
|
def GetLog(self): |
|
|
|
|
return self.m_Log |
|
|
|
|
|
|
|
|
|
def SQLRequest(self, a_Request : str, commit = False, return_error = False, param = None): |
|
|
|
|
return bot_bd.SQLRequest(self.m_BDFileName, a_Request, commit = commit, return_error = return_error, param = param) |
|
|
|
|
|
|
|
|
|
def GetUserGroupData(a_UserID): |
|
|
|
|
def GetGroupNamesForUser(a_UserID): |
|
|
|
|
return SQLRequest('SELECT groupName FROM user_groups WHERE group_id=(SELECT group_id FROM user_in_groups WHERE user_id = ?)', param = [a_UserID]) |
|
|
|
|
r = GetGroupNamesForUser(a_UserID) |
|
|
|
|
groups = [] |
|
|
|
|
for i in r: |
|
|
|
|
if len(i) > 0: |
|
|
|
|
groups += [i[0]] |
|
|
|
|
return user_access.UserGroups(a_UserID, groups) |
|
|
|
|
|
|
|
|
|
def GetModulesAccessList(): |
|
|
|
|
return bot_bd.RequestSelectTemplate(self.m_BDFileName, table_name)() |
|
|
|
|
|
|
|
|
|
def GetAccessForModule(a_ModuleName): |
|
|
|
|
alist = GetModulesAccessList() |
|
|
|
|
for i in alist: |
|
|
|
|
if i[0] == a_ModuleName: |
|
|
|
|
return i[1] |
|
|
|
|
return '' |
|
|
|
|
|
|
|
|
|
def GetItemDefaultAccessForModule(a_ModuleName): |
|
|
|
|
alist = GetModulesAccessList() |
|
|
|
|
for i in alist: |
|
|
|
|
if i[0] == a_ModuleName: |
|
|
|
|
return i[2] |
|
|
|
|
return '' |
|
|
|
|
|
|
|
|
|
async def SendMessage(self, a_UserID, a_Message, a_PhotoIDs, a_InlineKeyboardButtons, a_KeyboardButtons): |
|
|
|
|
inline_keyboard = keyboard.MakeAiogramInlineKeyboard(a_InlineKeyboardButtons) |
|
|
|
|
keyboard = keyboard.MakeAiogramKeyboard(a_KeyboardButtons) |
|
|
|
|
if not keyboard: |
|
|
|
|
keyboard = inline_keyboard |
|
|
|
|
if a_PhotoIDs and a_PhotoIDs != 0 or a_PhotoIDs != '0': |
|
|
|
|
self.m_TBot.send_photo( |
|
|
|
|
base_keyboard = keyboard.MakeAiogramKeyboard(a_KeyboardButtons) |
|
|
|
|
if a_InlineKeyboardButtons: |
|
|
|
|
base_keyboard = inline_keyboard |
|
|
|
|
if a_PhotoIDs and a_PhotoIDs != 0 and a_PhotoIDs != '0': |
|
|
|
|
await self.m_TBot.send_photo( |
|
|
|
|
a_UserID, |
|
|
|
|
a_PhotoIDs, |
|
|
|
|
a_Message, |
|
|
|
|
reply_markup = keyboard |
|
|
|
|
reply_markup = base_keyboard |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
self.m_TBot.send_message( |
|
|
|
|
await self.m_TBot.send_message( |
|
|
|
|
a_UserID, |
|
|
|
|
a_Message, |
|
|
|
|
reply_markup = keyboard |
|
|
|
|
reply_markup = base_keyboard |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def RegisterMessageHandler(self, a_MessageHandler, a_CheckFunc): |
|
|
|
|
self.m_Dispatcher.register_message_handler(a_MessageHandler, a_CheckFunc) |
|
|
|
|
def RegisterMessageHandler(self, a_MessageHandler, a_CheckFunc, commands=None, regexp=None, content_types=None, state=None): |
|
|
|
|
if a_CheckFunc: |
|
|
|
|
self.m_Dispatcher.register_message_handler(a_MessageHandler, a_CheckFunc, commands=commands, regexp=regexp, content_types=content_types, state=state) |
|
|
|
|
else: |
|
|
|
|
self.m_Dispatcher.register_message_handler(a_MessageHandler, commands=commands, regexp=regexp, content_types=content_types, state=state) |
|
|
|
|
|
|
|
|
|
def RegisterCallbackHandler(self, a_CallbackHandler, a_CheckFunc): |
|
|
|
|
self.m_Dispatcher.register_callback_query_handler(a_CallbackHandler, a_CheckFunc) |
|
|
|
|
def RegisterCallbackHandler(self, a_CallbackHandler, a_CheckFunc, commands=None, regexp=None, content_types=None, state=None): |
|
|
|
|
if a_CheckFunc: |
|
|
|
|
self.register_callback_query_handler.register_message_handler(a_CallbackHandler, a_CheckFunc, commands=commands, regexp=regexp, content_types=content_types, state=state) |
|
|
|
|
else: |
|
|
|
|
self.register_callback_query_handler.register_message_handler(a_CallbackHandler, commands=commands, regexp=regexp, content_types=content_types, state=state) |
|
|
|
|
|
|
|
|
|
def StartPolling(self): |
|
|
|
|
executor.start_polling(self.m_Dispatcher) |
|
|
|
|