You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.7 KiB
64 lines
2.7 KiB
# -*- coding: utf8 -*- |
|
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru> |
|
|
|
# Простые информационные сообщения |
|
|
|
from bot_sys import user_access |
|
from bot_modules import access |
|
from aiogram import types |
|
|
|
class WorkFuncResult(): |
|
def __init__(self, a_StringMessage : str, photo_id = None, item_access = None): |
|
self.string_message = a_StringMessage |
|
self.photo_id = photo_id |
|
self.item_access = item_access |
|
|
|
def InfoMessageTemplate(a_Bot, a_HelpMessage, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_AccessFunc, access_mode = user_access.AccessMode.VIEW): |
|
async def GetMessage(a_Message : types.message, state = None): |
|
return WorkFuncResult(a_HelpMessage) |
|
|
|
return SimpleMessageTemplate(a_Bot, GetMessage, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_AccessFunc, access_mode = access_mode) |
|
|
|
def SimpleMessageTemplate(a_Bot, a_WorkFunc, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_AccessFunc, access_mode = user_access.AccessMode.VIEW): |
|
def ProxyGetButtonsTemplate(a_GetButtonsFunc): |
|
def ReturnNone(): |
|
return None |
|
if a_GetButtonsFunc: |
|
return a_GetButtonsFunc |
|
else: |
|
return ReturnNone |
|
|
|
async def AccessDeniedMessage(a_UserID, a_Message, user_groups): |
|
return a_Bot.SendMessage( |
|
a_UserID, |
|
access.access_denied_message, |
|
None, |
|
None, |
|
ProxyGetButtonsTemplate(a_GetButtonsFunc)(a_Message, user_groups) |
|
) |
|
|
|
async def SimpleMessage(a_Message : types.message, state = None): |
|
user_id = str(a_Message.from_user.id) |
|
user_groups = a_Bot.GetUserGroupData(user_id) |
|
if not user_access.CheckAccess(a_Bot.GetRootIDs(), a_AccessFunc(), user_groups, access_mode): |
|
return await AccessDeniedMessage(user_id, a_Message, user_groups) |
|
|
|
res = await a_WorkFunc(a_Message, state = state) |
|
if res is None: |
|
return |
|
|
|
msg = res.string_message |
|
if msg is None: |
|
return |
|
|
|
if not res.item_access is None and not user_access.CheckAccess(a_Bot.GetRootIDs(), res.item_access, user_groups, access_mode): |
|
return await AccessDeniedMessage(user_id, a_Message, user_groups) |
|
|
|
await a_Bot.SendMessage( |
|
user_id, |
|
msg, |
|
res.photo_id, |
|
ProxyGetButtonsTemplate(a_GetInlineButtonsFunc)(a_Message, user_groups), |
|
ProxyGetButtonsTemplate(a_GetButtonsFunc)(a_Message, user_groups) |
|
) |
|
return SimpleMessage
|
|
|