From b316387b8e7b52f308dd11320dc2e19cb32d8e79 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Mon, 19 Aug 2024 00:43:03 +0700 Subject: [PATCH] pyrofork: Add some missings service messages CHAT_THEME_UPDATED CHAT_WALLPAPER_UPDATED CONTACT_REGISTERED GIFT_CODE SCREENSHOT_TAKEN Signed-off-by: wulan17 --- compiler/docs/compiler.py | 8 ++ pyrogram/enums/message_service_type.py | 17 +++- pyrogram/types/messages_and_media/__init__.py | 63 +++++++++++- .../types/messages_and_media/chat_theme.py | 38 ++++++++ .../messages_and_media/chat_wallpaper.py | 55 +++++++++++ .../messages_and_media/contact_registered.py | 29 ++++++ .../types/messages_and_media/gift_code.py | 97 +++++++++++++++++++ pyrogram/types/messages_and_media/message.py | 35 +++++++ .../messages_and_media/screenshot_taken.py | 29 ++++++ .../types/messages_and_media/wallpaper.py | 93 ++++++++++++++++++ .../messages_and_media/wallpaper_settings.py | 92 ++++++++++++++++++ 11 files changed, 552 insertions(+), 4 deletions(-) create mode 100644 pyrogram/types/messages_and_media/chat_theme.py create mode 100644 pyrogram/types/messages_and_media/chat_wallpaper.py create mode 100644 pyrogram/types/messages_and_media/contact_registered.py create mode 100644 pyrogram/types/messages_and_media/gift_code.py create mode 100644 pyrogram/types/messages_and_media/screenshot_taken.py create mode 100644 pyrogram/types/messages_and_media/wallpaper.py create mode 100644 pyrogram/types/messages_and_media/wallpaper_settings.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 08b5b429..67c8d6ab 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -531,6 +531,14 @@ def get_title_list(s: str) -> list: Reaction MessageReactionUpdated MessageReactionCountUpdated + ExportedStoryLink + ChatTheme + ChatWallpaper + ContactRegistered + GiftCode + ScreenshotTaken + Wallpaper + WallpaperSettings """, stories=""" Stories diff --git a/pyrogram/enums/message_service_type.py b/pyrogram/enums/message_service_type.py index 5706ade4..1739ab6e 100644 --- a/pyrogram/enums/message_service_type.py +++ b/pyrogram/enums/message_service_type.py @@ -113,4 +113,19 @@ class MessageServiceType(AutoName): "Payment refunded" BOT_ALLOWED = auto() - "Bot allowed" \ No newline at end of file + "Bot allowed" + + CHAT_THEME_UPDATED = auto() + "Chat theme updated" + + CHAT_WALLPAPER_UPDATED = auto() + "Chat wallpaper updated" + + CONTACT_REGISTERED = auto() + "Contact registered" + + GIFT_CODE = auto() + "Gift code" + + SCREENSHOT_TAKEN = auto() + "Screenshot taken" diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 72fa293a..9cf9d3e5 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -20,10 +20,14 @@ from .animation import Animation from .audio import Audio from .available_effect import AvailableEffect +from .chat_theme import ChatTheme +from .chat_wallpaper import ChatWallpaper from .contact import Contact +from .contact_registered import ContactRegistered from .dice import Dice from .document import Document from .game import Game +from .gift_code import GiftCode from .gifted_premium import GiftedPremium from .giveaway import Giveaway from .giveaway_launched import GiveawayLaunched @@ -39,6 +43,7 @@ from .poll import Poll from .poll_option import PollOption from .reaction import Reaction +from .screenshot_taken import ScreenshotTaken from .sticker import Sticker from .stickerset import StickerSet from .stories_privacy_rules import StoriesPrivacyRules @@ -63,9 +68,61 @@ from .story_skipped import StorySkipped from .story_views import StoryViews from .exported_story_link import ExportedStoryLink +from .wallpaper import Wallpaper +from .wallpaper_settings import WallpaperSettings __all__ = [ - "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", - "Reaction", "WebAppData", "MessageReactions", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageReactor", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink" + "Animation", + "Audio", + "AvailableEffect", + "ChatTheme", + "ChatWallpaper", + "Contact", + "ContactRegistered", + "Document", + "Game", + "GiftCode", + "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", + "Reaction", + "WebAppData", + "MessageReactions", + "MessageReactionUpdated", + "MessageReactionCountUpdated", + "MessageReactor", + "MessageStory", + "ScreenshotTaken", + "Story", + "StoryDeleted", + "StorySkipped", + "StoryViews", + "StoryForwardHeader", + "StoriesPrivacyRules", + "ExportedStoryLink", + "Wallpaper", + "WallpaperSettings" ] diff --git a/pyrogram/types/messages_and_media/chat_theme.py b/pyrogram/types/messages_and_media/chat_theme.py new file mode 100644 index 00000000..5a21dde1 --- /dev/null +++ b/pyrogram/types/messages_and_media/chat_theme.py @@ -0,0 +1,38 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +from ..object import Object +from pyrogram import raw + +class ChatTheme(Object): + """A service message about a chat theme. + + parameters: + emoticon (``str``): + The emoticon of the chat theme. + """ + + def __init__(self, emoticon: str): + super().__init__() + self.emoticon = emoticon + + @staticmethod + def _parse(chat_theme: "raw.types.MessageActionSetChatTheme") -> "ChatTheme": + return ChatTheme( + emoticon=getattr(chat_theme, "emoticon", None) + ) diff --git a/pyrogram/types/messages_and_media/chat_wallpaper.py b/pyrogram/types/messages_and_media/chat_wallpaper.py new file mode 100644 index 00000000..e829ad29 --- /dev/null +++ b/pyrogram/types/messages_and_media/chat_wallpaper.py @@ -0,0 +1,55 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +import pyrogram + +from ..object import Object +from pyrogram import raw, types + +class ChatWallpaper(Object): + """A service message about a chat wallpaper. + + parameters: + wallpaper (:obj:`types.WallPaper`): + The chat wallpaper. + + is_same (``bool``, *optional*): + True, if the chat wallpaper is the same as the previous one. + + is_both (``bool``, *optional*): + True, if the chat wallpaper is for both side. + """ + + def __init__( + self, + wallpaper: "types.WallPaper", + is_same: bool = None, + is_both: bool = None + ): + super().__init__() + self.wallpaper = wallpaper + self.is_same = is_same + self.is_both = is_both + + @staticmethod + def _parse(client: "pyrogram.Client", chat_wallpaper: "raw.types.ChatWallpaper") -> "ChatWallpaper": + return ChatWallpaper( + wallpaper=types.WallPaper._parse(client, chat_wallpaper.wallpaper), + is_same=getattr(chat_wallpaper, "is_same", None), + is_both=getattr(chat_wallpaper, "is_both", None) + ) diff --git a/pyrogram/types/messages_and_media/contact_registered.py b/pyrogram/types/messages_and_media/contact_registered.py new file mode 100644 index 00000000..6f896749 --- /dev/null +++ b/pyrogram/types/messages_and_media/contact_registered.py @@ -0,0 +1,29 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +from ..object import Object + + +class ContactRegistered(Object): + """A service message about a contact registered. + + Currently holds no information. + """ + + def __init__(self): + super().__init__() diff --git a/pyrogram/types/messages_and_media/gift_code.py b/pyrogram/types/messages_and_media/gift_code.py new file mode 100644 index 00000000..34680832 --- /dev/null +++ b/pyrogram/types/messages_and_media/gift_code.py @@ -0,0 +1,97 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +import pyrogram + +from ..object import Object +from pyrogram import types, utils + + +class GiftCode(Object): + """A service message about a gift code. + + parameters: + months (``int``): + How long the telegram premium last (in month). + + slug (``str``): + The slug of the gift code. + + is_giveaway (``bool``, *optional*): + True, if the gift code is from a giveaway. + + is_unclaimed (``bool``, *optional*): + True, if the gift code is unclaimed. + + boosted_chat (:obj:`~pyrogram.types.Chat`, *optional*): + The chat that the gift code boost. + + currency (``str``, *optional*): + The currency of the gift code. + + amount (``int``, *optional*): + The amount of the gift code. + + crypto_currency (``str``, *optional*): + The crypto currency of the gift code. + + crypto_amount (``int``, *optional*): + The crypto amount of the gift code. + """ + + def __init__( + self, + months: int, + slug: str, + is_giveaway: bool = None, + is_unclaimed: bool = None, + boosted_chat: "types.Chat" = None, + currency: str = None, + amount: int = None, + crypto_currency: str = None, + crypto_amount: int = None + ): + super().__init__() + self.months = months + self.slug = slug + self.is_giveaway = is_giveaway + self.is_unclaimed = is_unclaimed + self.boosted_chat = boosted_chat + self.currency = currency + self.amount = amount + self.crypto_currency = crypto_currency + self.crypto_amount = crypto_amount + + @staticmethod + def _parse(client: "pyrogram.Client", gift_code: "types.GiftCode", chats: dict,) -> "GiftCode": + boosted_chat = None + boosted_chat_raw = chats.get(utils.get_channel_id(gift_code.boost_peer), None) + if boosted_chat_raw: + boosted_chat = types.Chat._parse_channel_chat(client, boosted_chat_raw) + + return GiftCode( + months=gift_code.months, + slug=gift_code.slug, + is_giveaway=gift_code.is_giveaway, + is_unclaimed=gift_code.is_unclaimed, + boosted_chat=boosted_chat, + currency=gift_code.currency, + amount=gift_code.amount, + crypto_currency=gift_code.crypto_currency, + crypto_amount=gift_code.crypto_amount + ) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 310b0d21..8a2ff1ea 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -486,6 +486,11 @@ def __init__( giveaway: "types.Giveaway" = None, giveaway_result: "types.GiveawayResult" = None, boosts_applied: int = None, + chat_theme_updated: "types.ChatTheme" = None, + chat_wallpaper_updated: "types.ChatWallpaper" = None, + contact_registered: "types.ContactRegistered" = None, + gift_code: "types.GiftCode" = None, + screenshot_taken: "types.ScreenshotTaken" = None, invoice: "types.Invoice" = None, story: Union["types.MessageStory", "types.Story"] = None, video: "types.Video" = None, @@ -599,6 +604,11 @@ def __init__( self.giveaway = giveaway self.giveaway_result = giveaway_result self.boosts_applied = boosts_applied + self.chat_theme_updated = chat_theme_updated + self.chat_wallpaper_updated = chat_wallpaper_updated + self.contact_registered = contact_registered + self.gift_code = gift_code + self.screenshot_taken = screenshot_taken self.invoice = invoice self.story = story self.video = video @@ -756,6 +766,11 @@ async def _parse( successful_payment = None payment_refunded = None boosts_applied = None + chat_theme_updated = None + chat_wallpaper_updated = None + contact_registered = None + gift_code = None + screenshot_taken = None service_type = None chat_join_type = None @@ -859,6 +874,21 @@ async def _parse( elif isinstance(action, raw.types.MessageActionPaymentRefunded): payment_refunded = await types.PaymentRefunded._parse(client, action) service_type = enums.MessageServiceType.PAYMENT_REFUNDED + elif isinstance(action, raw.types.MessageActionSetChatTheme): + chat_theme_updated = types.ChatTheme._parse(action) + service_type = enums.MessageServiceType.CHAT_THEME_UPDATED + elif isinstance(action, raw.types.MessageActionSetChatWallPaper): + chat_wallpaper_updated = types.ChatWallpaper._parse(client, action) + service_type = enums.MessageServiceType.CHAT_WALLPAPER_UPDATED + elif isinstance(action, raw.types.MessageActionContactSignUp): + contact_registered = types.ContactRegistered() + service_type = enums.MessageServiceType.CONTACT_REGISTERED + elif isinstance(action, raw.types.MessageActionGiftCode): + gift_code = types.GiftCode._parse(client, action, chats) + service_type = enums.MessageServiceType.GIFT_CODE + elif isinstance(action, raw.types.MessageActionScreenshotTaken): + screenshot_taken = types.ScreenshotTaken() + service_type = enums.MessageServiceType.SCREENSHOT_TAKEN parsed_message = Message( id=message.id, @@ -898,6 +928,11 @@ async def _parse( successful_payment=successful_payment, payment_refunded=payment_refunded, boosts_applied=boosts_applied, + chat_theme_updated=chat_theme_updated, + chat_wallpaper_updated=chat_wallpaper_updated, + contact_registered=contact_registered, + gift_code=gift_code, + screenshot_taken=screenshot_taken, raw=message, chat_join_type=chat_join_type, client=client diff --git a/pyrogram/types/messages_and_media/screenshot_taken.py b/pyrogram/types/messages_and_media/screenshot_taken.py new file mode 100644 index 00000000..dd4a63d9 --- /dev/null +++ b/pyrogram/types/messages_and_media/screenshot_taken.py @@ -0,0 +1,29 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +from ..object import Object + + +class ScreenshotTaken(Object): + """A service message about a screenshot taken. + + Currently holds no information. + """ + + def __init__(self): + super().__init__() diff --git a/pyrogram/types/messages_and_media/wallpaper.py b/pyrogram/types/messages_and_media/wallpaper.py new file mode 100644 index 00000000..e5ea024b --- /dev/null +++ b/pyrogram/types/messages_and_media/wallpaper.py @@ -0,0 +1,93 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +import pyrogram + +from ..object import Object +from pyrogram import raw, types + +class Wallpaper(Object): + """A wallpaper. + + parameters: + id (``int``): + Unique identifier for this wallpaper. + + slug (``str``): + The slug of the wallpaper. + + document (:obj:`~pyrogram.types.Document`): + The document of the wallpaper. + + is_creator (:obj:`bool`, optional): + True, if the wallpaper was created by the current user. + + is_default (:obj:`bool`, optional): + True, if the wallpaper is the default wallpaper. + + is_pattern (:obj:`bool`, optional): + True, if the wallpaper is a pattern. + + id_dark (:obj:`bool`, optional): + True, if the wallpaper is dark. + + settings (:obj:`~pyrogram.types.WallpaperSettings`, optional): + The settings of the wallpaper. + """ + + def __init__( + self, + id: int, + slug: str, + document: "types.Document", + is_creator: bool = None, + is_default: bool = None, + is_pattern: bool = None, + is_dark: bool = None, + settings: "types.WallpaperSettings" = None + ): + super().__init__() + self.id = id + self.slug = slug + self.document = document + self.is_creator = is_creator + self.is_default = is_default + self.is_pattern = is_pattern + self.is_dark = is_dark + self.settings = settings + + @staticmethod + def _parse(client: "pyrogram.Client", wallpaper: "raw.base.WallPaper") -> "Wallpaper": + doc = wallpaper.document + attributes = {type(i): i for i in doc.attributes} + + file_name = getattr( + attributes.get( + raw.types.DocumentAttributeFilename, None + ), "file_name", None + ) + return Wallpaper( + id=wallpaper.id, + slug=wallpaper.slug, + document=types.Document._parse(client, doc, file_name), + is_creator=getattr(wallpaper, "creator", None), + is_default=getattr(wallpaper, "default", None), + is_pattern=getattr(wallpaper, "pattern", None), + is_dark=getattr(wallpaper, "dark", None), + settings=types.WallpaperSettings._parse(wallpaper.settings) + ) diff --git a/pyrogram/types/messages_and_media/wallpaper_settings.py b/pyrogram/types/messages_and_media/wallpaper_settings.py new file mode 100644 index 00000000..f931e3e7 --- /dev/null +++ b/pyrogram/types/messages_and_media/wallpaper_settings.py @@ -0,0 +1,92 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +from ..object import Object +from pyrogram import raw + +class WallpaperSettings(Object): + """A wallpaper settings. + + parameters: + is_blur (``bool``, *optional*): + True, if the wallpaper is blurred. + + is_motion (``bool``, *optional*): + True, if the wallpaper is motion. + + background_color (``int``, *optional*): + The background color of the wallpaper. + + second_background_color (``int``, *optional*): + The second background color of the wallpaper. + + third_background_color (``int``, *optional*): + The third background color of the wallpaper. + + fourth_background_color (``int``, *optional*): + The fourth background color of the wallpaper. + + intensity (``int``, *optional*): + The intensity of the wallpaper. + + rotation (``int``, *optional*): + The rotation of the wallpaper. + + emoticon (``str``, *optional*): + The emoticon of the wallpaper. + """ + + def __init__( + self, + is_blur: bool = None, + is_motion: bool = None, + background_color: int = None, + second_background_color: int = None, + third_background_color: int = None, + fourth_background_color: int = None, + intensity: int = None, + rotation: int = None, + emoticon: str = None + ): + super().__init__() + self.is_blur = is_blur + self.is_motion = is_motion + self.background_color = background_color + self.second_background_color = second_background_color + self.third_background_color = third_background_color + self.fourth_background_color = fourth_background_color + self.intensity = intensity + self.rotation = rotation + self.emoticon = emoticon + + @staticmethod + def _parse(wallpaper_settings: "raw.types.WallPaperSettings") -> "WallpaperSettings": + if wallpaper_settings is None: + return None + + return WallpaperSettings( + is_blur=getattr(wallpaper_settings, "blur", None), + is_motion=getattr(wallpaper_settings, "motion", None), + background_color=getattr(wallpaper_settings, "background_color", None), + second_background_color=getattr(wallpaper_settings, "second_background_color", None), + third_background_color=getattr(wallpaper_settings, "third_background_color", None), + fourth_background_color=getattr(wallpaper_settings, "fourth_background_color", None), + intensity=getattr(wallpaper_settings, "intensity", None), + rotation=getattr(wallpaper_settings, "rotation", None), + emoticon=getattr(wallpaper_settings, "emoticon", None) + )