Skip to content

Commit

Permalink
Renamed giveaway types and added some service messages to Message
Browse files Browse the repository at this point in the history
Co-authored-by: Shrimadhav U K <SpEcHiDe@users.noreply.github.com>
  • Loading branch information
KurimuzonAkuma and SpEcHiDe committed Oct 24, 2024
1 parent b5c83aa commit b31be17
Show file tree
Hide file tree
Showing 26 changed files with 1,009 additions and 250 deletions.
16 changes: 13 additions & 3 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ def get_title_list(s: str) -> list:
BusinessConnection
BusinessInfo
BusinessIntro
BusinessMessage
BusinessRecipients
BusinessWeeklyOpen
BusinessWorkingHours
Expand Down Expand Up @@ -512,6 +511,7 @@ def get_title_list(s: str) -> list:
""",
messages_media="""
Messages & Media
BusinessMessage
Message
MessageEntity
Photo
Expand All @@ -533,19 +533,24 @@ def get_title_list(s: str) -> list:
PollOption
Dice
Reaction
RefundedPayment
StarGift
VideoChatScheduled
VideoChatStarted
VideoChatEnded
VideoChatMembersInvited
PhoneCallStarted
PhoneCallEnded
WebAppData
MessageReactions
ChatReactions
Story
MyBoost
BoostsStatus
Giveaway
GiveawayResult
GiveawayCreated
GiveawayCompleted
GiveawayWinners
Invoice
GiftCode
CheckedGiftCode
Expand All @@ -554,6 +559,9 @@ def get_title_list(s: str) -> list:
PaidMediaPreview
PaymentForm
ChatBoost
ContactRegistered
ScreenshotTaken
WriteAccessAllowed
""",
bot_keyboards="""
Bot keyboards
Expand Down Expand Up @@ -825,7 +833,7 @@ def get_title_list(s: str) -> list:
""",
star_gift="""
StarGift
StarGift.save
StarGift.show
StarGift.hide
"""
)
Expand Down Expand Up @@ -868,6 +876,7 @@ def get_title_list(s: str) -> list:
BusinessSchedule
ChatAction
ChatEventAction
ChatJoinType
ChatMemberStatus
ChatMembersFilter
ChatType
Expand All @@ -878,6 +887,7 @@ def get_title_list(s: str) -> list:
MessagesFilter
NextCodeType
ParseMode
PhoneCallDiscardReason
PollType
PrivacyKey
ProfileColor
Expand Down
4 changes: 4 additions & 0 deletions pyrogram/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .business_schedule import BusinessSchedule
from .chat_action import ChatAction
from .chat_event_action import ChatEventAction
from .chat_join_type import ChatJoinType
from .chat_member_status import ChatMemberStatus
from .chat_members_filter import ChatMembersFilter
from .chat_type import ChatType
Expand All @@ -30,6 +31,7 @@
from .messages_filter import MessagesFilter
from .next_code_type import NextCodeType
from .parse_mode import ParseMode
from .phone_call_discard_reason import PhoneCallDiscardReason
from .poll_type import PollType
from .privacy_key import PrivacyKey
from .profile_color import ProfileColor
Expand All @@ -42,6 +44,7 @@
'BusinessSchedule',
'ChatAction',
'ChatEventAction',
'ChatJoinType',
'ChatMemberStatus',
'ChatMembersFilter',
'ChatType',
Expand All @@ -53,6 +56,7 @@
'MessagesFilter',
'NextCodeType',
'ParseMode',
'PhoneCallDiscardReason',
'PollType',
'PrivacyKey',
'ProfileColor',
Expand Down
34 changes: 34 additions & 0 deletions pyrogram/enums/chat_join_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from enum import auto

from .auto_name import AutoName


class ChatJoinType(AutoName):
"""How the service message :obj:`~pyrogram.enums.MessageServiceType.NEW_CHAT_MEMBERS` was used for the member to join the chat."""

BY_ADD = auto()
"A new member joined the chat via an invite link"

BY_LINK = auto()
"A new member joined the chat via an invite link"

BY_REQUEST = auto()
"A new member was accepted to the chat by an administrator"
4 changes: 2 additions & 2 deletions pyrogram/enums/message_media_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class MessageMediaType(AutoName):
GIVEAWAY = auto()
"Giveaway media"

GIVEAWAY_RESULT = auto()
"Giveaway result media"
GIVEAWAY_WINNERS = auto()
"Giveaway winners media"

STORY = auto()
"Story media"
Expand Down
28 changes: 23 additions & 5 deletions pyrogram/enums/message_service_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class MessageServiceType(AutoName):
GAME_HIGH_SCORE = auto()
"Game high score"

GIVEAWAY_LAUNCH = auto()
"Giveaway launch"
GIVEAWAY_CREATED = auto()
"Giveaway created"

GIFT_CODE = auto()
"Gift code"
Expand All @@ -96,6 +96,12 @@ class MessageServiceType(AutoName):
VIDEO_CHAT_MEMBERS_INVITED = auto()
"Video chat members invited"

PHONE_CALL_STARTED = auto()
"Phone call started"

PHONE_CALL_ENDED = auto()
"Phone call ended"

WEB_APP_DATA = auto()
"Web app data"

Expand All @@ -105,14 +111,26 @@ class MessageServiceType(AutoName):
SUCCESSFUL_PAYMENT = auto()
"Successful payment"

REFUNDED_PAYMENT = auto()
"Refunded payment"

CHAT_TTL_CHANGED = auto()
"Chat TTL changed"

BOOST_APPLY = auto()
"Boost apply"

JOIN_REQUEST_APPROVED = auto()
"Join request approved"

STAR_GIFT = auto()
"Star gift"

CONNECTED_WEBSITE = auto()
"Connected website"

WRITE_ACCESS_ALLOWED = auto()
"Write access allowed"

SCREENSHOT_TAKEN = auto()
"Screenshot taken"

CONTACT_REGISTERED = auto()
"Contact registered"
36 changes: 36 additions & 0 deletions pyrogram/enums/phone_call_discard_reason.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from pyrogram import raw
from .auto_name import AutoName


class PhoneCallDiscardReason(AutoName):
"""Phone call discard reason enumeration used in :obj:`~pyrogram.types.PhoneCallEnded`."""

BUSY = raw.types.PhoneCallDiscardReasonBusy
"Busy"

DISCONNECT = raw.types.PhoneCallDiscardReasonDisconnect
"Disconnect"

HANGUP = raw.types.PhoneCallDiscardReasonHangup
"Hangup"

MISSED = raw.types.PhoneCallDiscardReasonMissed
"Missed"
10 changes: 5 additions & 5 deletions pyrogram/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ async def giveaway_filter(_, __, m: Message):

# endregion

# region giveaway_result_filter
async def giveaway_result_filter(_, __, m: Message):
return bool(m.giveaway_result)
# region giveaway_winners_filter
async def giveaway_winners_filter(_, __, m: Message):
return bool(m.giveaway_winners)


giveaway_result = create(giveaway_result_filter)
"""Filter messages that contain :obj:`~pyrogram.types.GiveawayResult` objects."""
giveaway_winners = create(giveaway_winners_filter)
"""Filter messages that contain :obj:`~pyrogram.types.GiveawayWinners` objects."""


# endregion
Expand Down
3 changes: 2 additions & 1 deletion pyrogram/methods/payments/send_star_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async def send_star_gift(
hide_my_name (``bool``, *optional*):
If True, your name will be hidden from visitors to the gift recipient's profile.
Defaults to None.
Returns:
``bool``: On success, True is returned.
Expand All @@ -80,7 +81,7 @@ async def send_star_gift(
user_id=peer,
gift_id=star_gift_id,
hide_name=hide_my_name,
message=raw.types.TextWithEntities(text=text, entities=entities) if text else None
message=raw.types.TextWithEntities(text=text, entities=entities or []) if text else None
)

form = await self.invoke(
Expand Down
16 changes: 14 additions & 2 deletions pyrogram/types/messages_and_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .business_message import BusinessMessage
from .chat_boost import ChatBoost
from .checked_gift_code import CheckedGiftCode
from .contact_registered import ContactRegistered
from .contact import Contact
from .dice import Dice
from .document import Document
Expand All @@ -37,7 +38,9 @@
from .gift_code import GiftCode
from .invoice import Invoice
from .giveaway import Giveaway
from .giveaway_result import GiveawayResult
from .giveaway_completed import GiveawayCompleted
from .giveaway_created import GiveawayCreated
from .giveaway_winners import GiveawayWinners
from .location import Location
from .message import Message
from .message_entity import MessageEntity
Expand All @@ -50,6 +53,8 @@
from .poll import Poll
from .poll_option import PollOption
from .reaction import Reaction
from .refunded_payment import RefundedPayment
from .screenshot_taken import ScreenshotTaken
from .star_gift import StarGift
from .sticker import Sticker
from .story import Story
Expand All @@ -62,6 +67,7 @@
from .voice import Voice
from .web_app_data import WebAppData
from .web_page import WebPage
from .write_access_allowed import WriteAccessAllowed

__all__ = [
"Animation",
Expand All @@ -71,6 +77,7 @@
"BusinessMessage",
"ChatBoost",
"CheckedGiftCode",
"ContactRegistered",
"Contact",
"Dice",
"Document",
Expand All @@ -85,7 +92,9 @@
"GiftCode",
"Giveaway",
"Invoice",
"GiveawayResult",
"GiveawayCompleted",
"GiveawayCreated",
"GiveawayWinners",
"Location",
"Message",
"MessageEntity",
Expand All @@ -98,6 +107,8 @@
"Poll",
"PollOption",
"Reaction",
"RefundedPayment",
"ScreenshotTaken",
"StarGift",
"Sticker",
"Story",
Expand All @@ -110,4 +121,5 @@
"Voice",
"WebAppData",
"WebPage",
"WriteAccessAllowed",
]
7 changes: 1 addition & 6 deletions pyrogram/types/messages_and_media/business_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ def _parse(
schedule = None

if isinstance(message, raw.types.BusinessAwayMessage):
if isinstance(message.schedule, raw.types.BusinessAwayMessageScheduleAlways):
schedule = enums.BusinessSchedule.ALWAYS
elif isinstance(message.schedule, raw.types.BusinessAwayMessageScheduleOutsideWorkHours):
schedule = enums.BusinessSchedule.OUTSIDE_WORK_HOURS
elif isinstance(message.schedule, raw.types.BusinessAwayMessageScheduleCustom):
schedule = enums.BusinessSchedule.CUSTOM
schedule = enums.BusinessSchedule(type(message.schedule))

return BusinessMessage(
shortcut_id=message.shortcut_id,
Expand Down
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 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from ..object import Object


class ContactRegistered(Object):
"""A service message that a contact has registered with Telegram.
Currently holds no information.
"""

def __init__(self):
super().__init__()
Loading

0 comments on commit b31be17

Please sign in to comment.