Skip to content

Commit

Permalink
pyrofork: Add BotAllowed and BotApp
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Jun 15, 2024
1 parent abd611c commit 7ed761c
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 4 deletions.
13 changes: 9 additions & 4 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ def get_title_list(s: str) -> list:
ReactionType
MessageReactionUpdated
MessageReactionCountUpdated
SuccessfulPayment
""",
stories="""
Stories
Expand All @@ -531,9 +530,17 @@ def get_title_list(s: str) -> list:
Identifier
Listener
""",
bot="""
Bot
BotAllowed
BotApp
BotBusinessConnection
PaymentInfo
ShippingAddress
SuccessfulPayment
""",
bot_keyboards="""
Bot keyboards
BotBusinessConnection
ReplyKeyboardMarkup
KeyboardButton
ReplyKeyboardRemove
Expand All @@ -554,9 +561,7 @@ def get_title_list(s: str) -> list:
MenuButtonWebApp
MenuButtonDefault
SentWebAppMessage
PaymentInfo
PreCheckoutQuery
ShippingAddress
""",
bot_commands="""
Bot commands
Expand Down
3 changes: 3 additions & 0 deletions pyrogram/enums/message_service_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ class MessageServiceType(AutoName):

SUCCESSFUL_PAYMENT = auto()
"Successful payment"

BOT_ALLOWED = auto()
"Bot allowed"
4 changes: 4 additions & 0 deletions pyrogram/types/bots_and_keyboards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,6 +57,8 @@
from .web_app_info import WebAppInfo

__all__ = [
"BotAllowed",
"BotApp",
"BotBusinessConnection",
"CallbackGame",
"CallbackQuery",
Expand Down
65 changes: 65 additions & 0 deletions pyrogram/types/bots_and_keyboards/bot_allowed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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/>.

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(bot_allowed: "raw.types.BotAllowed") -> "BotAllowed":
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(getattr(bot_allowed, "app", None))
)
76 changes: 76 additions & 0 deletions pyrogram/types/bots_and_keyboards/bot_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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/>.

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(bot_app: "raw.types.BotApp") -> "BotApp":
return BotApp(
id=bot_app.id,
short_name=bot_app.short_name,
title=bot_app.title,
description=bot_app.description,
photo=types.Photo._parse(bot_app.photo),
document=types.Document._parse(getattr(bot_app, "document", None))
)
10 changes: 10 additions & 0 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -506,6 +509,7 @@ def __init__(
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,
Expand Down Expand Up @@ -617,6 +621,7 @@ def __init__(
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
Expand Down Expand Up @@ -720,6 +725,7 @@ async def _parse(
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
Expand Down Expand Up @@ -778,6 +784,9 @@ async def _parse(
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(action)
service_type = enums.MessageServiceType.BOT_ALLOWED
elif isinstance(action, raw.types.MessageActionRequestedPeer):
chat_shared = []
user_shared = []
Expand Down Expand Up @@ -861,6 +870,7 @@ async def _parse(
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,
Expand Down

0 comments on commit 7ed761c

Please sign in to comment.