mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Add BotAllowed and BotApp
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
b8b014129e
commit
7a9ffa2506
6 changed files with 181 additions and 4 deletions
|
|
@ -510,7 +510,6 @@ def pyrogram_api():
|
|||
ReactionType
|
||||
MessageReactionUpdated
|
||||
MessageReactionCountUpdated
|
||||
SuccessfulPayment
|
||||
""",
|
||||
stories="""
|
||||
Stories
|
||||
|
|
@ -531,9 +530,17 @@ def pyrogram_api():
|
|||
Identifier
|
||||
Listener
|
||||
""",
|
||||
bot="""
|
||||
Bot
|
||||
BotAllowed
|
||||
BotApp
|
||||
BotBusinessConnection
|
||||
PaymentInfo
|
||||
ShippingAddress
|
||||
SuccessfulPayment
|
||||
""",
|
||||
bot_keyboards="""
|
||||
Bot keyboards
|
||||
BotBusinessConnection
|
||||
ReplyKeyboardMarkup
|
||||
KeyboardButton
|
||||
ReplyKeyboardRemove
|
||||
|
|
@ -554,9 +561,7 @@ def pyrogram_api():
|
|||
MenuButtonWebApp
|
||||
MenuButtonDefault
|
||||
SentWebAppMessage
|
||||
PaymentInfo
|
||||
PreCheckoutQuery
|
||||
ShippingAddress
|
||||
""",
|
||||
bot_commands="""
|
||||
Bot commands
|
||||
|
|
|
|||
|
|
@ -114,3 +114,6 @@ class MessageServiceType(AutoName):
|
|||
|
||||
SUCCESSFUL_PAYMENT = auto()
|
||||
"Successful payment"
|
||||
|
||||
BOT_ALLOWED = auto()
|
||||
"Bot allowed"
|
||||
|
|
@ -17,6 +17,8 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .bot_allowed import BotAllowed
|
||||
from .bot_app import BotApp
|
||||
from .bot_business_connection import BotBusinessConnection
|
||||
from .bot_command import BotCommand
|
||||
from .bot_command_scope import BotCommandScope
|
||||
|
|
@ -55,6 +57,8 @@ from .successful_payment import SuccessfulPayment
|
|||
from .web_app_info import WebAppInfo
|
||||
|
||||
__all__ = [
|
||||
"BotAllowed",
|
||||
"BotApp",
|
||||
"BotBusinessConnection",
|
||||
"CallbackGame",
|
||||
"CallbackQuery",
|
||||
|
|
|
|||
68
pyrogram/types/bots_and_keyboards/bot_allowed.py
Normal file
68
pyrogram/types/bots_and_keyboards/bot_allowed.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||
#
|
||||
# This file is part of Pyrofork.
|
||||
#
|
||||
# Pyrofork is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrofork is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pyrogram
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from pyrogram import raw, types
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class BotAllowed(Object):
|
||||
|
||||
"""Contains information about a allowed bot.
|
||||
|
||||
Parameters:
|
||||
attach_menu (``bool``, *optional*):
|
||||
True, if the bot can attach to menu.
|
||||
|
||||
from_request (``bool``, *optional*):
|
||||
True, if the bot is allowed from request.
|
||||
|
||||
domain (``str``, *optional*):
|
||||
The domain of the bot.
|
||||
|
||||
app (:obj:`types.BotApp`, *optional*):
|
||||
The app of the bot.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
attach_menu: Optional[bool] = None,
|
||||
from_request: Optional[bool] = None,
|
||||
domain: Optional[str] = None,
|
||||
app: Optional["types.BotApp"] = None
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.attach_menu = attach_menu
|
||||
self.from_request = from_request
|
||||
self.domain = domain
|
||||
self.app = app
|
||||
|
||||
@staticmethod
|
||||
def _parse(client: "pyrogram.Client", bot_allowed: "raw.types.BotAllowed") -> "BotAllowed":
|
||||
bot_app = getattr(bot_allowed, "app", None)
|
||||
return BotAllowed(
|
||||
attach_menu=getattr(bot_allowed, "attach_menu", None),
|
||||
from_request=getattr(bot_allowed, "from_request", None),
|
||||
domain=getattr(bot_allowed, "domain", None),
|
||||
app=types.BotApp._parse(client, bot_app) if bot_app is not None else None
|
||||
)
|
||||
87
pyrogram/types/bots_and_keyboards/bot_app.py
Normal file
87
pyrogram/types/bots_and_keyboards/bot_app.py
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||
#
|
||||
# This file is part of Pyrofork.
|
||||
#
|
||||
# Pyrofork is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrofork is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pyrogram
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from pyrogram import raw, types
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class BotApp(Object):
|
||||
|
||||
"""Contains information about a bot app.
|
||||
|
||||
Parameters:
|
||||
id (``int``):
|
||||
The id of the app.
|
||||
|
||||
short_name (``str``):
|
||||
The short name of the app.
|
||||
|
||||
title (``str``):
|
||||
The title of the app.
|
||||
|
||||
description (``str``):
|
||||
The description of the app.
|
||||
|
||||
photo (``types.Photo``):
|
||||
The photo of the app.
|
||||
|
||||
document (``types.Document``, *optional*):
|
||||
The document of the app.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: int,
|
||||
short_name: str,
|
||||
title: str,
|
||||
description: str,
|
||||
photo: "types.Photo",
|
||||
document: Optional["types.Document"] = None
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.id = id
|
||||
self.short_name = short_name
|
||||
self.title = title
|
||||
self.description = description
|
||||
self.photo = photo
|
||||
self.document = document
|
||||
|
||||
@staticmethod
|
||||
def _parse(client: "pyrogram.Client", bot_app: "raw.types.BotApp") -> "BotApp":
|
||||
document = None
|
||||
if isinstance(bot_app.document, raw.types.Document):
|
||||
attributes = {type(i): i for i in bot_app.document.attributes}
|
||||
file_name = getattr(
|
||||
attributes.get(
|
||||
raw.types.DocumentAttributeFilename, None
|
||||
), "file_name", None
|
||||
)
|
||||
document = types.Document._parse(client, bot_app.document, file_name)
|
||||
return BotApp(
|
||||
id=bot_app.id,
|
||||
short_name=bot_app.short_name,
|
||||
title=bot_app.title,
|
||||
description=bot_app.description,
|
||||
photo=types.Photo._parse(client, bot_app.photo),
|
||||
document=document
|
||||
)
|
||||
|
|
@ -341,6 +341,9 @@ class Message(Object, Update):
|
|||
E.g.: "/start 1 2 3" would produce ["start", "1", "2", "3"].
|
||||
Only applicable when using :obj:`~pyrogram.filters.command`.
|
||||
|
||||
bot_allowed (:obj:`~pyrogram.types.BotAllowed`, *optional*):
|
||||
Contains information about a allowed bot.
|
||||
|
||||
chat_shared (List of ``int``, *optional*):
|
||||
Service message: chat/channel shared
|
||||
|
||||
|
|
@ -506,6 +509,7 @@ class Message(Object, Update):
|
|||
outgoing: bool = None,
|
||||
matches: List[Match] = None,
|
||||
command: List[str] = None,
|
||||
bot_allowed: "types.BotAllowed" = None,
|
||||
chat_shared: List[int] = None,
|
||||
user_shared: List[int] = None,
|
||||
forum_topic_created: "types.ForumTopicCreated" = None,
|
||||
|
|
@ -617,6 +621,7 @@ class Message(Object, Update):
|
|||
self.matches = matches
|
||||
self.command = command
|
||||
self.reply_markup = reply_markup
|
||||
self.bot_allowed = bot_allowed
|
||||
self.chat_shared = chat_shared
|
||||
self.user_shared = user_shared
|
||||
self.forum_topic_created = forum_topic_created
|
||||
|
|
@ -720,6 +725,7 @@ class Message(Object, Update):
|
|||
group_chat_created = None
|
||||
channel_chat_created = None
|
||||
new_chat_photo = None
|
||||
bot_allowed = None
|
||||
chat_shared = None
|
||||
user_shared = None
|
||||
is_topic_message = None
|
||||
|
|
@ -778,6 +784,9 @@ class Message(Object, Update):
|
|||
elif isinstance(action, raw.types.MessageActionChatEditPhoto):
|
||||
new_chat_photo = types.Photo._parse(client, action.photo)
|
||||
service_type = enums.MessageServiceType.NEW_CHAT_PHOTO
|
||||
elif isinstance(action, raw.types.MessageActionBotAllowed):
|
||||
bot_allowed = types.BotAllowed._parse(client, action)
|
||||
service_type = enums.MessageServiceType.BOT_ALLOWED
|
||||
elif isinstance(action, raw.types.MessageActionRequestedPeer):
|
||||
chat_shared = []
|
||||
user_shared = []
|
||||
|
|
@ -861,6 +870,7 @@ class Message(Object, Update):
|
|||
migrate_to_chat_id=utils.get_channel_id(migrate_to_chat_id) if migrate_to_chat_id else None,
|
||||
migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None,
|
||||
group_chat_created=group_chat_created,
|
||||
bot_allowed=bot_allowed,
|
||||
channel_chat_created=channel_chat_created,
|
||||
chat_shared=chat_shared if chat_shared is not None and len(chat_shared) > 0 else None,
|
||||
user_shared=user_shared if user_shared is not None and len(user_shared) > 0 else None,
|
||||
|
|
|
|||
Loading…
Reference in a new issue