Skip to content

Commit

Permalink
pyrofork: Add some missings service messages
Browse files Browse the repository at this point in the history
CHAT_THEME_UPDATED
CHAT_WALLPAPER_UPDATED
CONTACT_REGISTERED
GIFT_CODE
SCREENSHOT_TAKEN

Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Aug 19, 2024
1 parent ce6b67c commit b316387
Show file tree
Hide file tree
Showing 11 changed files with 552 additions and 4 deletions.
8 changes: 8 additions & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,14 @@ def get_title_list(s: str) -> list:
Reaction
MessageReactionUpdated
MessageReactionCountUpdated
ExportedStoryLink
ChatTheme
ChatWallpaper
ContactRegistered
GiftCode
ScreenshotTaken
Wallpaper
WallpaperSettings
""",
stories="""
Stories
Expand Down
17 changes: 16 additions & 1 deletion pyrogram/enums/message_service_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,19 @@ class MessageServiceType(AutoName):
"Payment refunded"

BOT_ALLOWED = auto()
"Bot allowed"
"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"
63 changes: 60 additions & 3 deletions pyrogram/types/messages_and_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
]
38 changes: 38 additions & 0 deletions pyrogram/types/messages_and_media/chat_theme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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 ..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)
)
55 changes: 55 additions & 0 deletions pyrogram/types/messages_and_media/chat_wallpaper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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 ..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)
)
29 changes: 29 additions & 0 deletions pyrogram/types/messages_and_media/contact_registered.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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 ..object import Object


class ContactRegistered(Object):
"""A service message about a contact registered.
Currently holds no information.
"""

def __init__(self):
super().__init__()
97 changes: 97 additions & 0 deletions pyrogram/types/messages_and_media/gift_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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 ..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
)
Loading

0 comments on commit b316387

Please sign in to comment.