mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Refactor Reactions
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
b6d9e2c782
commit
cbd632c600
9 changed files with 33 additions and 156 deletions
|
|
@ -527,8 +527,6 @@ def pyrogram_api():
|
||||||
GeneralTopicHidden
|
GeneralTopicHidden
|
||||||
GeneralTopicUnhidden
|
GeneralTopicUnhidden
|
||||||
Reaction
|
Reaction
|
||||||
ReactionCount
|
|
||||||
ReactionType
|
|
||||||
MessageReactionUpdated
|
MessageReactionUpdated
|
||||||
MessageReactionCountUpdated
|
MessageReactionCountUpdated
|
||||||
""",
|
""",
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,6 @@ class ReactionType(AutoName):
|
||||||
|
|
||||||
CUSTOM_EMOJI = auto()
|
CUSTOM_EMOJI = auto()
|
||||||
"""Custom emoji reaction type."""
|
"""Custom emoji reaction type."""
|
||||||
|
|
||||||
|
PAID = auto()
|
||||||
|
"""Paid reaction type."""
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,6 @@ from .photo import Photo
|
||||||
from .poll import Poll
|
from .poll import Poll
|
||||||
from .poll_option import PollOption
|
from .poll_option import PollOption
|
||||||
from .reaction import Reaction
|
from .reaction import Reaction
|
||||||
from .reaction_type import ReactionType
|
|
||||||
from .reaction_count import ReactionCount
|
|
||||||
from .sticker import Sticker
|
from .sticker import Sticker
|
||||||
from .stickerset import StickerSet
|
from .stickerset import StickerSet
|
||||||
from .stories_privacy_rules import StoriesPrivacyRules
|
from .stories_privacy_rules import StoriesPrivacyRules
|
||||||
|
|
@ -68,5 +66,5 @@ from .exported_story_link import ExportedStoryLink
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Animation", "Audio", "AvailableEffect", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "LabeledPrice", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail",
|
"Animation", "Audio", "AvailableEffect", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "LabeledPrice", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail",
|
||||||
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
||||||
"Reaction", "WebAppData", "MessageReactions", "ReactionCount", "ReactionType", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
"Reaction", "WebAppData", "MessageReactions", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class MessageReactionCountUpdated(Object, Update):
|
||||||
date (:py:obj:`~datetime.datetime`):
|
date (:py:obj:`~datetime.datetime`):
|
||||||
Date of change of the reaction
|
Date of change of the reaction
|
||||||
|
|
||||||
reactions (:obj:`~pyrogram.types.ReactionCount`):
|
reactions (:obj:`~pyrogram.types.Reaction`):
|
||||||
List of reactions that are present on the message
|
List of reactions that are present on the message
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ class MessageReactionCountUpdated(Object, Update):
|
||||||
chat: "types.Chat",
|
chat: "types.Chat",
|
||||||
message_id: int,
|
message_id: int,
|
||||||
date: datetime,
|
date: datetime,
|
||||||
reactions: List["types.ReactionCount"]
|
reactions: List["types.Reaction"]
|
||||||
):
|
):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ class MessageReactionCountUpdated(Object, Update):
|
||||||
update: "raw.types.UpdateBotMessageReactions",
|
update: "raw.types.UpdateBotMessageReactions",
|
||||||
users: Dict[int, "raw.types.User"],
|
users: Dict[int, "raw.types.User"],
|
||||||
chats: Dict[int, "raw.types.Chat"]
|
chats: Dict[int, "raw.types.Chat"]
|
||||||
) -> "MessageReactionUpdated":
|
) -> "MessageReactionCountUpdated":
|
||||||
chat = None
|
chat = None
|
||||||
peer_id = utils.get_peer_id(update.peer)
|
peer_id = utils.get_peer_id(update.peer)
|
||||||
raw_peer_id = utils.get_raw_peer_id(update.peer)
|
raw_peer_id = utils.get_raw_peer_id(update.peer)
|
||||||
|
|
@ -81,7 +81,8 @@ class MessageReactionCountUpdated(Object, Update):
|
||||||
message_id=update.msg_id,
|
message_id=update.msg_id,
|
||||||
date=utils.timestamp_to_datetime(update.date),
|
date=utils.timestamp_to_datetime(update.date),
|
||||||
reactions=[
|
reactions=[
|
||||||
types.ReactionCount._parse(
|
types.Reaction._parse_count(
|
||||||
|
client,
|
||||||
rt
|
rt
|
||||||
) for rt in update.reactions
|
) for rt in update.reactions
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,10 @@ class MessageReactionUpdated(Object, Update):
|
||||||
date (:py:obj:`~datetime.datetime`):
|
date (:py:obj:`~datetime.datetime`):
|
||||||
Date of change of the reaction
|
Date of change of the reaction
|
||||||
|
|
||||||
old_reaction (:obj:`~pyrogram.types.ReactionType`):
|
old_reaction (:obj:`~pyrogram.types.Reaction`):
|
||||||
Previous list of reaction types that were set by the user
|
Previous list of reaction types that were set by the user
|
||||||
|
|
||||||
new_reaction (:obj:`~pyrogram.types.ReactionType`):
|
new_reaction (:obj:`~pyrogram.types.Reaction`):
|
||||||
New list of reaction types that have been set by the user
|
New list of reaction types that have been set by the user
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -65,8 +65,8 @@ class MessageReactionUpdated(Object, Update):
|
||||||
actor_chat: "types.Chat",
|
actor_chat: "types.Chat",
|
||||||
date: datetime,
|
date: datetime,
|
||||||
chat: "types.Chat",
|
chat: "types.Chat",
|
||||||
old_reaction: List["types.ReactionType"],
|
old_reaction: List["types.Reaction"],
|
||||||
new_reaction: List["types.ReactionType"]
|
new_reaction: List["types.Reaction"]
|
||||||
):
|
):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
|
|
@ -112,13 +112,15 @@ class MessageReactionUpdated(Object, Update):
|
||||||
chat=chat,
|
chat=chat,
|
||||||
actor_chat=actor_chat,
|
actor_chat=actor_chat,
|
||||||
old_reaction=[
|
old_reaction=[
|
||||||
types.ReactionType._parse(
|
types.Reaction._parse(
|
||||||
|
client,
|
||||||
rt
|
rt
|
||||||
) for rt in update.old_reactions
|
) for rt in update.old_reactions
|
||||||
],
|
],
|
||||||
new_reaction=[
|
new_reaction=[
|
||||||
types.ReactionType._parse(
|
types.Reaction._parse(
|
||||||
|
client,
|
||||||
rt
|
rt
|
||||||
) for rt in update.new_reactions
|
) for rt in update.new_reactions
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram import raw
|
from pyrogram import enums, raw
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,6 +28,9 @@ class Reaction(Object):
|
||||||
"""Contains information about a reaction.
|
"""Contains information about a reaction.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
type (``enums.ReactionType``):
|
||||||
|
Reaction type.
|
||||||
|
|
||||||
emoji (``str``, *optional*):
|
emoji (``str``, *optional*):
|
||||||
Reaction emoji.
|
Reaction emoji.
|
||||||
|
|
||||||
|
|
@ -46,6 +49,7 @@ class Reaction(Object):
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
client: "pyrogram.Client" = None,
|
client: "pyrogram.Client" = None,
|
||||||
|
type: "enums.ReactionType",
|
||||||
emoji: Optional[str] = None,
|
emoji: Optional[str] = None,
|
||||||
custom_emoji_id: Optional[int] = None,
|
custom_emoji_id: Optional[int] = None,
|
||||||
count: Optional[int] = None,
|
count: Optional[int] = None,
|
||||||
|
|
@ -53,6 +57,7 @@ class Reaction(Object):
|
||||||
):
|
):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
|
self.type = type
|
||||||
self.emoji = emoji
|
self.emoji = emoji
|
||||||
self.custom_emoji_id = custom_emoji_id
|
self.custom_emoji_id = custom_emoji_id
|
||||||
self.count = count
|
self.count = count
|
||||||
|
|
@ -66,14 +71,21 @@ class Reaction(Object):
|
||||||
if isinstance(reaction, raw.types.ReactionEmoji):
|
if isinstance(reaction, raw.types.ReactionEmoji):
|
||||||
return Reaction(
|
return Reaction(
|
||||||
client=client,
|
client=client,
|
||||||
|
type=enums.ReactionType.EMOJI,
|
||||||
emoji=reaction.emoticon
|
emoji=reaction.emoticon
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(reaction, raw.types.ReactionCustomEmoji):
|
if isinstance(reaction, raw.types.ReactionCustomEmoji):
|
||||||
return Reaction(
|
return Reaction(
|
||||||
client=client,
|
client=client,
|
||||||
|
type=enums.ReactionType.CUSTOM_EMOJI,
|
||||||
custom_emoji_id=reaction.document_id
|
custom_emoji_id=reaction.document_id
|
||||||
)
|
)
|
||||||
|
if isinstance(reaction, raw.types.ReactionPaid):
|
||||||
|
return Reaction(
|
||||||
|
client=client,
|
||||||
|
type=enums.ReactionType.PAID
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_count(
|
def _parse_count(
|
||||||
|
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
# 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
|
|
||||||
from .reaction_type import ReactionType
|
|
||||||
from ..object import Object
|
|
||||||
|
|
||||||
class ReactionCount(Object):
|
|
||||||
"""Represents a reaction added to a message along with the number of times it was added.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
|
|
||||||
type (:obj:`~pyrogram.types.ReactionType`):
|
|
||||||
Reaction type.
|
|
||||||
|
|
||||||
total_count (``int``):
|
|
||||||
Total reaction count.
|
|
||||||
|
|
||||||
chosen_order (``int``):
|
|
||||||
Chosen reaction order.
|
|
||||||
Available for chosen reactions.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
*,
|
|
||||||
type: ReactionType,
|
|
||||||
total_count: int,
|
|
||||||
chosen_order: int
|
|
||||||
):
|
|
||||||
super().__init__()
|
|
||||||
self.type = type
|
|
||||||
self.total_count = total_count
|
|
||||||
self.chosen_order = chosen_order
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _parse(
|
|
||||||
update: "raw.types.ReactionCount",
|
|
||||||
) -> Optional["ReactionCount"]:
|
|
||||||
return ReactionCount(
|
|
||||||
type=ReactionType._parse(
|
|
||||||
update.reaction
|
|
||||||
),
|
|
||||||
total_count=update.count,
|
|
||||||
chosen_order=update.chosen_order
|
|
||||||
)
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
# 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 enums, raw
|
|
||||||
from ..object import Object
|
|
||||||
|
|
||||||
class ReactionType(Object):
|
|
||||||
"""Contains information about a reaction.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
type (``enums.ReactionType``, *optional*):
|
|
||||||
Reaction type.
|
|
||||||
|
|
||||||
emoji (``str``, *optional*):
|
|
||||||
Reaction emoji.
|
|
||||||
|
|
||||||
custom_emoji_id (``int``, *optional*):
|
|
||||||
Custom emoji id.
|
|
||||||
"""
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
*,
|
|
||||||
type: str = "enums.ReactionType",
|
|
||||||
emoji: str = None,
|
|
||||||
custom_emoji_id: str = None
|
|
||||||
):
|
|
||||||
super().__init__()
|
|
||||||
self.type = type
|
|
||||||
self.emoji = emoji
|
|
||||||
self.custom_emoji_id = custom_emoji_id
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _parse(
|
|
||||||
update: "raw.types.Reaction",
|
|
||||||
) -> Optional["ReactionType"]:
|
|
||||||
if isinstance(update, raw.types.ReactionEmpty):
|
|
||||||
return None
|
|
||||||
elif isinstance(update, raw.types.ReactionEmoji):
|
|
||||||
return ReactionType(
|
|
||||||
type=enums.ReactionType.EMOJI,
|
|
||||||
emoji=update.emoticon
|
|
||||||
)
|
|
||||||
elif isinstance(update, raw.types.ReactionCustomEmoji):
|
|
||||||
return ReactionType(
|
|
||||||
type=enums.ReactionType.CUSTOM_EMOJI,
|
|
||||||
custom_emoji_id=update.document_id
|
|
||||||
)
|
|
||||||
|
|
||||||
def write(self):
|
|
||||||
if self.type == enums.ReactionType.EMOJI:
|
|
||||||
return raw.types.ReactionEmoji(
|
|
||||||
emoticon=self.emoji
|
|
||||||
)
|
|
||||||
if self.type == enums.ReactionType.CUSTOM_EMOJI:
|
|
||||||
return raw.types.ReactionCustomEmoji(
|
|
||||||
document_id=self.custom_emoji_id
|
|
||||||
)
|
|
||||||
|
|
@ -64,11 +64,11 @@ class ChatReactions(Object):
|
||||||
return ChatReactions(
|
return ChatReactions(
|
||||||
client=client,
|
client=client,
|
||||||
reactions=[
|
reactions=[
|
||||||
types.ReactionType._parse(reaction)
|
types.Reaction._parse(client, reaction)
|
||||||
for reaction in chat_reactions.reactions
|
for reaction in chat_reactions.reactions
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
if isinstance(chat_reactions, raw.types.ChatReactionsNone):
|
if isinstance(chat_reactions, raw.types.ChatReactionsNone):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue