mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-03 14:04:51 +00:00
Compare commits
8 commits
2343c68264
...
50b8d17400
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50b8d17400 | ||
|
|
e020eba68f | ||
|
|
e5b01eb04b | ||
|
|
776ee3afb3 | ||
|
|
a1db77fcee | ||
|
|
6e3a840c5a | ||
|
|
1b27e24675 | ||
|
|
c8b90101eb |
17 changed files with 478 additions and 150 deletions
|
|
@ -194,6 +194,8 @@ messageActionGiftStars#45d5b021 flags:# currency:string amount:long stars:long c
|
|||
messageActionPrizeStars#b00c47a2 flags:# unclaimed:flags.0?true stars:long transaction_id:string boost_peer:Peer giveaway_msg_id:int = MessageAction;
|
||||
messageActionStarGift#4717e8a4 flags:# name_hidden:flags.0?true saved:flags.2?true converted:flags.3?true upgraded:flags.5?true refunded:flags.9?true can_upgrade:flags.10?true gift:StarGift message:flags.1?TextWithEntities convert_stars:flags.4?long upgrade_msg_id:flags.5?int upgrade_stars:flags.8?long from_id:flags.11?Peer peer:flags.12?Peer saved_id:flags.12?long = MessageAction;
|
||||
messageActionStarGiftUnique#acdfcb81 flags:# upgrade:flags.0?true transferred:flags.1?true saved:flags.2?true refunded:flags.5?true gift:StarGift can_export_at:flags.3?int transfer_stars:flags.4?long from_id:flags.6?Peer peer:flags.7?Peer saved_id:flags.7?long = MessageAction;
|
||||
messageActionPaidMessagesRefunded#ac1f1fcd count:int stars:long = MessageAction;
|
||||
messageActionPaidMessagesPrice#bcd71419 stars:long = MessageAction;
|
||||
|
||||
dialog#d58a08c6 flags:# pinned:flags.2?true unread_mark:flags.3?true view_forum_as_messages:flags.6?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int ttl_period:flags.5?int = Dialog;
|
||||
dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog;
|
||||
|
|
@ -213,6 +215,7 @@ geoPoint#b2a2f663 flags:# long:double lat:double access_hash:long accuracy_radiu
|
|||
|
||||
auth.sentCode#5e002502 flags:# type:auth.SentCodeType phone_code_hash:string next_type:flags.1?auth.CodeType timeout:flags.2?int = auth.SentCode;
|
||||
auth.sentCodeSuccess#2390fe44 authorization:auth.Authorization = auth.SentCode;
|
||||
auth.sentCodePaymentRequired#d7cef980 store_product:string phone_code_hash:string = auth.SentCode;
|
||||
|
||||
auth.authorization#2ea2c0d4 flags:# setup_password_required:flags.1?true otherwise_relogin_days:flags.1?int tmp_sessions:flags.0?int future_auth_token:flags.2?bytes user:User = auth.Authorization;
|
||||
auth.authorizationSignUpRequired#44747e9a flags:# terms_of_service:flags.0?help.TermsOfService = auth.Authorization;
|
||||
|
|
@ -245,7 +248,7 @@ inputReportReasonFake#f5ddd6e7 = ReportReason;
|
|||
inputReportReasonIllegalDrugs#a8eb2be = ReportReason;
|
||||
inputReportReasonPersonalDetails#9ec7863d = ReportReason;
|
||||
|
||||
userFull#d2234ea0 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true translations_disabled:flags.23?true stories_pinned_available:flags.26?true blocked_my_stories_from:flags.27?true wallpaper_overridden:flags.28?true contact_require_premium:flags.29?true read_dates_private:flags.30?true flags2:# sponsored_enabled:flags2.7?true can_view_revenue:flags2.9?true bot_can_manage_emoji_status:flags2.10?true id:long about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights wallpaper:flags.24?WallPaper stories:flags.25?PeerStories business_work_hours:flags2.0?BusinessWorkHours business_location:flags2.1?BusinessLocation business_greeting_message:flags2.2?BusinessGreetingMessage business_away_message:flags2.3?BusinessAwayMessage business_intro:flags2.4?BusinessIntro birthday:flags2.5?Birthday personal_channel_id:flags2.6?long personal_channel_message:flags2.6?int stargifts_count:flags2.8?int starref_program:flags2.11?StarRefProgram bot_verification:flags2.12?BotVerification send_paid_messages_stars:flags2.14?long = UserFull;
|
||||
userFull#99e78045 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true translations_disabled:flags.23?true stories_pinned_available:flags.26?true blocked_my_stories_from:flags.27?true wallpaper_overridden:flags.28?true contact_require_premium:flags.29?true read_dates_private:flags.30?true flags2:# sponsored_enabled:flags2.7?true can_view_revenue:flags2.9?true bot_can_manage_emoji_status:flags2.10?true display_gifts_button:flags2.16?true id:long about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights wallpaper:flags.24?WallPaper stories:flags.25?PeerStories business_work_hours:flags2.0?BusinessWorkHours business_location:flags2.1?BusinessLocation business_greeting_message:flags2.2?BusinessGreetingMessage business_away_message:flags2.3?BusinessAwayMessage business_intro:flags2.4?BusinessIntro birthday:flags2.5?Birthday personal_channel_id:flags2.6?long personal_channel_message:flags2.6?int stargifts_count:flags2.8?int starref_program:flags2.11?StarRefProgram bot_verification:flags2.12?BotVerification send_paid_messages_stars:flags2.14?long disallowed_gifts:flags2.15?DisallowedGiftsSettings = UserFull;
|
||||
|
||||
contact#145ade0b user_id:long mutual:Bool = Contact;
|
||||
|
||||
|
|
@ -436,6 +439,7 @@ updateBusinessBotCallbackQuery#1ea2fda7 flags:# query_id:long user_id:long conne
|
|||
updateStarsRevenueStatus#a584b019 peer:Peer status:StarsRevenueStatus = Update;
|
||||
updateBotPurchasedPaidMedia#283bd312 user_id:long payload:string qts:int = Update;
|
||||
updatePaidReactionPrivacy#8b725fce private:PaidReactionPrivacy = Update;
|
||||
updateSentPhoneCode#504aa18f sent_code:auth.SentCode = Update;
|
||||
|
||||
updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
|
||||
|
||||
|
|
@ -1320,7 +1324,7 @@ statsGroupTopInviter#535f779d user_id:long invitations:int = StatsGroupTopInvite
|
|||
|
||||
stats.megagroupStats#ef7ff916 period:StatsDateRangeDays members:StatsAbsValueAndPrev messages:StatsAbsValueAndPrev viewers:StatsAbsValueAndPrev posters:StatsAbsValueAndPrev growth_graph:StatsGraph members_graph:StatsGraph new_members_by_source_graph:StatsGraph languages_graph:StatsGraph messages_graph:StatsGraph actions_graph:StatsGraph top_hours_graph:StatsGraph weekdays_graph:StatsGraph top_posters:Vector<StatsGroupTopPoster> top_admins:Vector<StatsGroupTopAdmin> top_inviters:Vector<StatsGroupTopInviter> users:Vector<User> = stats.MegagroupStats;
|
||||
|
||||
globalPrivacySettings#c9d8df1c flags:# archive_and_mute_new_noncontact_peers:flags.0?true keep_archived_unmuted:flags.1?true keep_archived_folders:flags.2?true hide_read_marks:flags.3?true new_noncontact_peers_require_premium:flags.4?true noncontact_peers_paid_stars:flags.5?long = GlobalPrivacySettings;
|
||||
globalPrivacySettings#fe41b34f flags:# archive_and_mute_new_noncontact_peers:flags.0?true keep_archived_unmuted:flags.1?true keep_archived_folders:flags.2?true hide_read_marks:flags.3?true new_noncontact_peers_require_premium:flags.4?true display_gifts_button:flags.7?true noncontact_peers_paid_stars:flags.5?long disallowed_gifts:flags.6?DisallowedGiftsSettings = GlobalPrivacySettings;
|
||||
|
||||
help.countryCode#4203c5ef flags:# country_code:string prefixes:flags.0?Vector<string> patterns:flags.1?Vector<string> = help.CountryCode;
|
||||
|
||||
|
|
@ -1503,6 +1507,7 @@ inputStorePaymentPremiumGiveaway#160544ca flags:# only_new_subscribers:flags.0?t
|
|||
inputStorePaymentStarsTopup#dddd0f56 stars:long currency:string amount:long = InputStorePaymentPurpose;
|
||||
inputStorePaymentStarsGift#1d741ef7 user_id:InputUser stars:long currency:string amount:long = InputStorePaymentPurpose;
|
||||
inputStorePaymentStarsGiveaway#751f08fa flags:# only_new_subscribers:flags.0?true winners_are_visible:flags.3?true stars:long boost_peer:InputPeer additional_peers:flags.1?Vector<InputPeer> countries_iso2:flags.2?Vector<string> prize_description:flags.4?string random_id:long until_date:int currency:string amount:long users:int = InputStorePaymentPurpose;
|
||||
inputStorePaymentAuthCode#9bb2636d flags:# restore:flags.0?true phone_number:string phone_code_hash:string currency:string amount:long = InputStorePaymentPurpose;
|
||||
|
||||
paymentFormMethod#88f8f21b url:string title:string = PaymentFormMethod;
|
||||
|
||||
|
|
@ -1761,7 +1766,7 @@ inputQuickReplyShortcutId#1190cf1 shortcut_id:int = InputQuickReplyShortcut;
|
|||
messages.quickReplies#c68d6695 quick_replies:Vector<QuickReply> messages:Vector<Message> chats:Vector<Chat> users:Vector<User> = messages.QuickReplies;
|
||||
messages.quickRepliesNotModified#5f91eb5b = messages.QuickReplies;
|
||||
|
||||
connectedBot#bd068601 flags:# can_reply:flags.0?true bot_id:long recipients:BusinessBotRecipients = ConnectedBot;
|
||||
connectedBot#cd64636c flags:# bot_id:long recipients:BusinessBotRecipients rights:BusinessBotRights = ConnectedBot;
|
||||
|
||||
account.connectedBots#17d7f87b connected_bots:Vector<ConnectedBot> users:Vector<User> = account.ConnectedBots;
|
||||
|
||||
|
|
@ -1769,7 +1774,7 @@ messages.dialogFilters#2ad93719 flags:# tags_enabled:flags.0?true filters:Vector
|
|||
|
||||
birthday#6c8e1e06 flags:# day:int month:int year:flags.0?int = Birthday;
|
||||
|
||||
botBusinessConnection#896433b4 flags:# can_reply:flags.0?true disabled:flags.1?true connection_id:string user_id:long dc_id:int date:int = BotBusinessConnection;
|
||||
botBusinessConnection#8f34b2f5 flags:# disabled:flags.1?true connection_id:string user_id:long dc_id:int date:int rights:flags.2?BusinessBotRights = BotBusinessConnection;
|
||||
|
||||
inputBusinessIntro#9c469cd flags:# title:string description:string sticker:flags.0?InputDocument = InputBusinessIntro;
|
||||
|
||||
|
|
@ -1953,6 +1958,15 @@ requirementToContactEmpty#50a9839 = RequirementToContact;
|
|||
requirementToContactPremium#e581e4e9 = RequirementToContact;
|
||||
requirementToContactPaidMessages#b4f67e93 stars_amount:long = RequirementToContact;
|
||||
|
||||
businessBotRights#a0624cf7 flags:# reply:flags.0?true read_messages:flags.1?true delete_sent_messages:flags.2?true delete_received_messages:flags.3?true edit_name:flags.4?true edit_bio:flags.5?true edit_profile_photo:flags.6?true edit_username:flags.7?true view_gifts:flags.8?true sell_gifts:flags.9?true change_gift_settings:flags.10?true transfer_and_upgrade_gifts:flags.11?true transfer_stars:flags.12?true manage_stories:flags.13?true = BusinessBotRights;
|
||||
|
||||
disallowedGiftsSettings#71f276c4 flags:# disallow_unlimited_stargifts:flags.0?true disallow_limited_stargifts:flags.1?true disallow_unique_stargifts:flags.2?true disallow_premium_gifts:flags.3?true = DisallowedGiftsSettings;
|
||||
|
||||
sponsoredPeer#c69708d3 flags:# random_id:bytes peer:Peer sponsor_info:flags.0?string additional_info:flags.1?string = SponsoredPeer;
|
||||
|
||||
contacts.sponsoredPeersEmpty#ea32b4b1 = contacts.SponsoredPeers;
|
||||
contacts.sponsoredPeers#eb032884 peers:Vector<SponsoredPeer> chats:Vector<Chat> users:Vector<User> = contacts.SponsoredPeers;
|
||||
|
||||
---functions---
|
||||
|
||||
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
|
||||
|
|
@ -2087,7 +2101,7 @@ account.updateBusinessWorkHours#4b00e066 flags:# business_work_hours:flags.0?Bus
|
|||
account.updateBusinessLocation#9e6b131a flags:# geo_point:flags.1?InputGeoPoint address:flags.0?string = Bool;
|
||||
account.updateBusinessGreetingMessage#66cdafc4 flags:# message:flags.0?InputBusinessGreetingMessage = Bool;
|
||||
account.updateBusinessAwayMessage#a26a7fa5 flags:# message:flags.0?InputBusinessAwayMessage = Bool;
|
||||
account.updateConnectedBot#43d8521d flags:# can_reply:flags.0?true deleted:flags.1?true bot:InputUser recipients:InputBusinessBotRecipients = Updates;
|
||||
account.updateConnectedBot#66a08c7e flags:# deleted:flags.1?true rights:flags.0?BusinessBotRights bot:InputUser recipients:InputBusinessBotRecipients = Updates;
|
||||
account.getConnectedBots#4ea4c80f = account.ConnectedBots;
|
||||
account.getBotBusinessConnection#76a86270 connection_id:string = Updates;
|
||||
account.updateBusinessIntro#a614d034 flags:# intro:flags.0?InputBusinessIntro = Bool;
|
||||
|
|
@ -2138,6 +2152,7 @@ contacts.importContactToken#13005788 token:string = User;
|
|||
contacts.editCloseFriends#ba6705f0 id:Vector<long> = Bool;
|
||||
contacts.setBlocked#94c65c76 flags:# my_stories_from:flags.0?true id:Vector<InputPeer> limit:int = Bool;
|
||||
contacts.getBirthdays#daeda864 = contacts.ContactBirthdays;
|
||||
contacts.getSponsoredPeers#b6c8c393 q:string = contacts.SponsoredPeers;
|
||||
|
||||
messages.getMessages#63c66506 id:Vector<InputMessage> = messages.Messages;
|
||||
messages.getDialogs#a0f4cb4f flags:# exclude_pinned:flags.0?true folder_id:flags.1?int offset_date:int offset_id:int offset_peer:InputPeer limit:int hash:long = messages.Dialogs;
|
||||
|
|
@ -2356,9 +2371,9 @@ messages.requestMainWebView#c9e01e7b flags:# compact:flags.7?true fullscreen:fla
|
|||
messages.sendPaidReaction#58bbcb50 flags:# peer:InputPeer msg_id:int count:int random_id:long private:flags.0?PaidReactionPrivacy = Updates;
|
||||
messages.togglePaidReactionPrivacy#435885b5 peer:InputPeer msg_id:int private:PaidReactionPrivacy = Bool;
|
||||
messages.getPaidReactionPrivacy#472455aa = Updates;
|
||||
messages.viewSponsoredMessage#673ad8f1 peer:InputPeer random_id:bytes = Bool;
|
||||
messages.clickSponsoredMessage#f093465 flags:# media:flags.0?true fullscreen:flags.1?true peer:InputPeer random_id:bytes = Bool;
|
||||
messages.reportSponsoredMessage#1af3dbb8 peer:InputPeer random_id:bytes option:bytes = channels.SponsoredMessageReportResult;
|
||||
messages.viewSponsoredMessage#269e3643 random_id:bytes = Bool;
|
||||
messages.clickSponsoredMessage#8235057e flags:# media:flags.0?true fullscreen:flags.1?true random_id:bytes = Bool;
|
||||
messages.reportSponsoredMessage#12cbf0c4 random_id:bytes option:bytes = channels.SponsoredMessageReportResult;
|
||||
messages.getSponsoredMessages#9bd2f439 peer:InputPeer = messages.SponsoredMessages;
|
||||
messages.savePreparedInlineMessage#f21f7f2f flags:# result:InputBotInlineResult user_id:InputUser peer_types:flags.0?Vector<InlineQueryPeerType> = messages.BotPreparedInlineMessage;
|
||||
messages.getPreparedInlineMessage#857ebdb8 bot:InputUser id:string = messages.PreparedInlineMessage;
|
||||
|
|
@ -2514,7 +2529,6 @@ payments.getBankCardData#2e79d779 number:string = payments.BankCardData;
|
|||
payments.exportInvoice#f91b065 invoice_media:InputMedia = payments.ExportedInvoice;
|
||||
payments.assignAppStoreTransaction#80ed747d receipt:bytes purpose:InputStorePaymentPurpose = Updates;
|
||||
payments.assignPlayMarketTransaction#dffd50d3 receipt:DataJSON purpose:InputStorePaymentPurpose = Updates;
|
||||
payments.canPurchasePremium#9fc19eb6 purpose:InputStorePaymentPurpose = Bool;
|
||||
payments.getPremiumGiftCodeOptions#2757ba54 flags:# boost_peer:flags.0?InputPeer = Vector<PremiumGiftCodeOption>;
|
||||
payments.checkGiftCode#8e51b4c1 slug:string = payments.CheckedGiftCode;
|
||||
payments.applyGiftCode#f6e26854 slug:string = Updates;
|
||||
|
|
@ -2552,6 +2566,7 @@ payments.getSavedStarGift#b455a106 stargift:Vector<InputSavedStarGift> = payment
|
|||
payments.getStarGiftWithdrawalUrl#d06e93a8 stargift:InputSavedStarGift password:InputCheckPasswordSRP = payments.StarGiftWithdrawalUrl;
|
||||
payments.toggleChatStarGiftNotifications#60eaefa1 flags:# enabled:flags.0?true peer:InputPeer = Bool;
|
||||
payments.toggleStarGiftsPinnedToTop#1513e7b0 peer:InputPeer stargift:Vector<InputSavedStarGift> = Bool;
|
||||
payments.canPurchaseStore#4fdc5ea7 purpose:InputStorePaymentPurpose = Bool;
|
||||
|
||||
stickers.createStickerSet#9021ab67 flags:# masks:flags.0?true emojis:flags.5?true text_color:flags.6?true user_id:InputUser title:string short_name:string thumb:flags.2?InputDocument stickers:Vector<InputStickerSetItem> software:flags.3?string = messages.StickerSet;
|
||||
stickers.removeStickerFromSet#f7760f51 sticker:InputDocument = messages.StickerSet;
|
||||
|
|
@ -2672,4 +2687,4 @@ smsjobs.finishJob#4f1ebf24 flags:# job_id:string error:flags.0?string = Bool;
|
|||
|
||||
fragment.getCollectibleInfo#be1e85ba collectible:InputCollectible = fragment.CollectibleInfo;
|
||||
|
||||
// LAYER 200
|
||||
// LAYER 201
|
||||
|
|
|
|||
|
|
@ -524,6 +524,7 @@ def pyrogram_api():
|
|||
Audio
|
||||
AvailableEffect
|
||||
Document
|
||||
ExternalReplyInfo
|
||||
AlternativeVideo
|
||||
Animation
|
||||
Video
|
||||
|
|
|
|||
|
|
@ -109,9 +109,11 @@ class SendReaction:
|
|||
add_to_recent=add_to_recent
|
||||
)
|
||||
)
|
||||
users = {i.id: i for i in r.users}
|
||||
chats = {i.id: i for i in r.chats}
|
||||
for i in r.updates:
|
||||
if isinstance(i, raw.types.UpdateMessageReactions):
|
||||
return types.MessageReactions._parse(self, i.reactions)
|
||||
return types.MessageReactions._parse(self, i.reactions, users, chats)
|
||||
elif story_id is not None:
|
||||
await self.invoke(
|
||||
raw.functions.stories.SendReaction(
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ class SendPaidReaction:
|
|||
)
|
||||
)
|
||||
users = {i.id: i for i in r.users}
|
||||
chats = {i.id: i for i in r.chats}
|
||||
|
||||
for i in r.updates:
|
||||
if isinstance(i, raw.types.UpdateMessageReactions):
|
||||
return types.MessageReactions._parse(self, i.reactions, users)
|
||||
return types.MessageReactions._parse(self, i.reactions, users, chats)
|
||||
|
|
|
|||
|
|
@ -17,14 +17,12 @@
|
|||
# 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 Union, List, Match, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, enums
|
||||
from pyrogram import types
|
||||
from pyrogram import raw, types
|
||||
from typing import Dict
|
||||
from ..object import Object
|
||||
from ..update import Update
|
||||
from ... import utils
|
||||
|
||||
|
||||
class PreCheckoutQuery(Object, Update):
|
||||
|
|
@ -76,7 +74,11 @@ class PreCheckoutQuery(Object, Update):
|
|||
self.payment_info = payment_info
|
||||
|
||||
@staticmethod
|
||||
async def _parse(client: "pyrogram.Client", pre_checkout_query, users) -> "PreCheckoutQuery":
|
||||
async def _parse(
|
||||
client: "pyrogram.Client",
|
||||
pre_checkout_query: "raw.types.UpdateBotPrecheckoutQuery",
|
||||
users: Dict[int, "raw.types.User"] = None
|
||||
) -> "PreCheckoutQuery":
|
||||
# Try to decode pre-checkout query payload into string. If that fails, fallback to bytes instead of decoding by
|
||||
# ignoring/replacing errors, this way, button clicks will still work.
|
||||
try:
|
||||
|
|
@ -95,14 +97,7 @@ class PreCheckoutQuery(Object, Update):
|
|||
name=pre_checkout_query.info.name,
|
||||
phone_number=pre_checkout_query.info.phone,
|
||||
email=pre_checkout_query.info.email,
|
||||
shipping_address=types.ShippingAddress(
|
||||
street_line1=pre_checkout_query.info.shipping_address.street_line1,
|
||||
street_line2=pre_checkout_query.info.shipping_address.street_line2,
|
||||
city=pre_checkout_query.info.shipping_address.city,
|
||||
state=pre_checkout_query.info.shipping_address.state,
|
||||
post_code=pre_checkout_query.info.shipping_address.post_code,
|
||||
country_code=pre_checkout_query.info.shipping_address.country_iso2
|
||||
)
|
||||
shipping_address=types.ShippingAddress._parse(pre_checkout_query.info.shipping_address)
|
||||
) if pre_checkout_query.info else None,
|
||||
client=client
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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 pyrogram import raw
|
||||
|
||||
from ..object import Object
|
||||
|
||||
|
||||
|
|
@ -60,3 +62,17 @@ class ShippingAddress(Object):
|
|||
self.state = state
|
||||
self.post_code = post_code
|
||||
self.country_code = country_code
|
||||
|
||||
@staticmethod
|
||||
def _parse(shipping_address: "raw.types.raw.types.PostAddress") -> "ShippingAddress":
|
||||
if shipping_address is None:
|
||||
return None
|
||||
|
||||
return ShippingAddress(
|
||||
street_line1=shipping_address.street_line1,
|
||||
street_line2=shipping_address.street_line2,
|
||||
city=shipping_address.city,
|
||||
state=shipping_address.state,
|
||||
post_code=shipping_address.post_code,
|
||||
country_code=shipping_address.country_code
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
|
|
@ -16,8 +17,6 @@
|
|||
# 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 typing import Union, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, types
|
||||
|
||||
|
|
@ -49,20 +48,20 @@ class ShippingQuery(Object, Update):
|
|||
client: "pyrogram.Client" = None,
|
||||
id: str,
|
||||
from_user: "types.User",
|
||||
invoice_payload: str,
|
||||
payload: str,
|
||||
shipping_address: "types.ShippingAddress" = None
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
self.invoice_payload = invoice_payload
|
||||
self.payload = payload
|
||||
self.shipping_address = shipping_address
|
||||
|
||||
@staticmethod
|
||||
async def _parse(
|
||||
client: "pyrogram.Client",
|
||||
shipping_query: "raw.types.updateBotShippingQuery",
|
||||
shipping_query: "raw.types.UpdateBotShippingQuery",
|
||||
users: dict
|
||||
) -> "types.PreCheckoutQuery":
|
||||
# Try to decode pre-checkout query payload into string. If that fails, fallback to bytes instead of decoding by
|
||||
|
|
@ -72,19 +71,12 @@ class ShippingQuery(Object, Update):
|
|||
except (UnicodeDecodeError, AttributeError):
|
||||
payload = shipping_query.payload
|
||||
|
||||
return types.PreCheckoutQuery(
|
||||
id=str(shipping_query.query_id),
|
||||
from_user=types.User._parse(client, users[shipping_query.user_id]),
|
||||
invoice_payload=payload,
|
||||
shipping_address=types.ShippingAddress(
|
||||
country_code=shipping_query.shipping_address.country_iso2,
|
||||
state=shipping_query.shipping_address.state,
|
||||
city=shipping_query.shipping_address.city,
|
||||
street_line1=shipping_query.shipping_address.street_line1,
|
||||
street_line2=shipping_query.shipping_address.street_line2,
|
||||
post_code=shipping_query.shipping_address.post_code
|
||||
),
|
||||
client=client
|
||||
return ShippingQuery(
|
||||
client=client,
|
||||
id=shipping_query.query_id,
|
||||
from_user=types.User._parse(client, users.get(shipping_query.user_id)),
|
||||
payload=payload,
|
||||
shipping_address=types.ShippingAddress._parse(shipping_query.shipping_address)
|
||||
)
|
||||
|
||||
async def answer(
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from .contact import Contact
|
|||
from .contact_registered import ContactRegistered
|
||||
from .dice import Dice
|
||||
from .document import Document
|
||||
from .external_reply_info import ExternalReplyInfo
|
||||
from .game import Game
|
||||
from .giveaway import Giveaway
|
||||
from .giveaway_launched import GiveawayLaunched
|
||||
|
|
@ -89,6 +90,7 @@ __all__ = [
|
|||
"Contact",
|
||||
"ContactRegistered",
|
||||
"Document",
|
||||
"ExternalReplyInfo",
|
||||
"Game",
|
||||
"Giveaway",
|
||||
"GiveawayLaunched",
|
||||
|
|
|
|||
327
pyrogram/types/messages_and_media/external_reply_info.py
Normal file
327
pyrogram/types/messages_and_media/external_reply_info.py
Normal file
|
|
@ -0,0 +1,327 @@
|
|||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||
#
|
||||
# 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 typing import Dict, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import enums, raw, types, utils
|
||||
|
||||
from ..object import Object
|
||||
|
||||
|
||||
class ExternalReplyInfo(Object):
|
||||
"""This object contains information about a message that is being replied to, which may come from another chat or forum topic.
|
||||
|
||||
Parameters:
|
||||
origin (:obj:`~pyrogram.types.MessageOrigin`, *optional*):
|
||||
Origin of the message replied to by the given message.
|
||||
|
||||
chat (:obj:`~pyrogram.types.Chat`, *optional*):
|
||||
Chat the original message belongs to.
|
||||
Available only if the chat is a supergroup or a channel.
|
||||
|
||||
message_id (``int``, *optional*):
|
||||
Unique message identifier inside the original chat.
|
||||
Available only if the original chat is a supergroup or a channel.
|
||||
|
||||
media (:obj:`~pyrogram.enums.MessageMediaType`, *optional*):
|
||||
The message is a media message.
|
||||
This field will contain the enumeration type of the media message.
|
||||
You can use ``media = getattr(message, message.media.value)`` to access the media message.
|
||||
|
||||
animation (:obj:`~pyrogram.types.Animation`, *optional*):
|
||||
Message is an animation, information about the animation.
|
||||
|
||||
audio (:obj:`~pyrogram.types.Audio`, *optional*):
|
||||
Message is an audio file, information about the file.
|
||||
|
||||
document (:obj:`~pyrogram.types.Document`, *optional*):
|
||||
Message is a general file, information about the file.
|
||||
|
||||
paid_media (:obj:`~pyrogram.types.PaidMediaInfo`, *optional*):
|
||||
Message contains paid media; information about the paid media.
|
||||
|
||||
photo (:obj:`~pyrogram.types.Photo`, *optional*):
|
||||
Message is a photo, information about the photo.
|
||||
|
||||
sticker (:obj:`~pyrogram.types.Sticker`, *optional*):
|
||||
Message is a sticker, information about the sticker.
|
||||
|
||||
story (:obj:`~pyrogram.types.Story`, *optional*):
|
||||
Message is a forwarded story.
|
||||
|
||||
video (:obj:`~pyrogram.types.Video`, *optional*):
|
||||
Message is a video, information about the video.
|
||||
|
||||
video_note (:obj:`~pyrogram.types.VideoNote`, *optional*):
|
||||
Message is a video note, information about the video message.
|
||||
|
||||
voice (:obj:`~pyrogram.types.Voice`, *optional*):
|
||||
Message is a voice message, information about the file.
|
||||
|
||||
has_media_spoiler (``bool``, *optional*):
|
||||
True, if the message media is covered by a spoiler animation.
|
||||
|
||||
contact (:obj:`~pyrogram.types.Contact`, *optional*):
|
||||
Message is a shared contact, information about the contact.
|
||||
|
||||
dice (:obj:`~pyrogram.types.Dice`, *optional*):
|
||||
A dice containing a value that is randomly generated by Telegram.
|
||||
|
||||
game (:obj:`~pyrogram.types.Game`, *optional*):
|
||||
Message is a game, information about the game.
|
||||
|
||||
giveaway (:obj:`~pyrogram.types.Giveaway`, *optional*):
|
||||
Message is a scheduled giveaway, information about the giveaway.
|
||||
|
||||
giveaway_result (:obj:`~pyrogram.types.GiveawayResult`, *optional*):
|
||||
Message is a giveaway result, information about the giveaway result.
|
||||
|
||||
invoice (:obj:`~pyrogram.types.Invoice`, *optional*):
|
||||
Message is a invoice, information about the invoice.
|
||||
`More about payments » <https://core.telegram.org/bots/api#payments>`_
|
||||
|
||||
location (:obj:`~pyrogram.types.Location`, *optional*):
|
||||
Message is a shared location, information about the location.
|
||||
|
||||
poll (:obj:`~pyrogram.types.Poll`, *optional*):
|
||||
Message is a native poll, information about the poll.
|
||||
|
||||
venue (:obj:`~pyrogram.types.Venue`, *optional*):
|
||||
Message is a venue, information about the venue.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
client: "pyrogram.Client" = None,
|
||||
origin: "types.MessageOrigin" = None,
|
||||
chat: "types.Chat" = None,
|
||||
message_id: int,
|
||||
media: Optional["enums.MessageMediaType"] = None,
|
||||
animation: Optional["types.Animation"] = None,
|
||||
audio: Optional["types.Audio"] = None,
|
||||
document: Optional["types.Document"] = None,
|
||||
paid_media: Optional["types.PaidMediaInfo"] = None,
|
||||
photo: Optional["types.Photo"] = None,
|
||||
sticker: Optional["types.Sticker"] = None,
|
||||
story: Optional["types.Story"] = None,
|
||||
video: Optional["types.Video"] = None,
|
||||
video_note: Optional["types.VideoNote"] = None,
|
||||
voice: Optional["types.Voice"] = None,
|
||||
has_media_spoiler: Optional[bool] = None,
|
||||
contact: Optional["types.Contact"] = None,
|
||||
dice: Optional["types.Dice"] = None,
|
||||
game: Optional["types.Game"] = None,
|
||||
giveaway: Optional["types.Giveaway"] = None,
|
||||
giveaway_result: Optional["types.GiveawayResult"] = None,
|
||||
invoice: Optional["types.Invoice"] = None,
|
||||
location: Optional["types.Location"] = None,
|
||||
poll: Optional["types.Poll"] = None,
|
||||
venue: Optional["types.Venue"] = None,
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
self.origin = origin
|
||||
self.chat = chat
|
||||
self.message_id = message_id
|
||||
self.media = media
|
||||
self.animation = animation
|
||||
self.audio = audio
|
||||
self.document = document
|
||||
self.paid_media = paid_media
|
||||
self.photo = photo
|
||||
self.sticker = sticker
|
||||
self.story = story
|
||||
self.video = video
|
||||
self.video_note = video_note
|
||||
self.voice = voice
|
||||
self.has_media_spoiler = has_media_spoiler
|
||||
self.contact = contact
|
||||
self.dice = dice
|
||||
self.game = game
|
||||
self.giveaway = giveaway
|
||||
self.giveaway_result = giveaway_result
|
||||
self.invoice = invoice
|
||||
self.location = location
|
||||
self.poll = poll
|
||||
self.venue = venue
|
||||
|
||||
@staticmethod
|
||||
async def _parse(
|
||||
client,
|
||||
reply: "raw.types.MessageReplyHeader",
|
||||
users: Dict[int, "raw.types.User"],
|
||||
chats: Dict[int, "raw.types.Chat"],
|
||||
) -> Optional["ExternalReplyInfo"]:
|
||||
if not isinstance(reply, raw.types.MessageReplyHeader):
|
||||
return None
|
||||
|
||||
if not reply.reply_from:
|
||||
return None
|
||||
|
||||
animation = None
|
||||
audio = None
|
||||
document = None
|
||||
paid_media = None
|
||||
photo = None
|
||||
sticker = None
|
||||
story = None
|
||||
video = None
|
||||
video_note = None
|
||||
voice = None
|
||||
contact = None
|
||||
dice = None
|
||||
game = None
|
||||
giveaway = None
|
||||
giveaway_result = None
|
||||
invoice = None
|
||||
location = None
|
||||
poll = None
|
||||
venue = None
|
||||
|
||||
media = reply.reply_media
|
||||
media_type = None
|
||||
has_media_spoiler = None
|
||||
|
||||
if media:
|
||||
if isinstance(media, raw.types.MessageMediaPhoto):
|
||||
photo = types.Photo._parse(client, media.photo, media.ttl_seconds)
|
||||
media_type = enums.MessageMediaType.PHOTO
|
||||
has_media_spoiler = media.spoiler
|
||||
elif isinstance(media, raw.types.MessageMediaGeo):
|
||||
location = types.Location._parse(client, media.geo)
|
||||
media_type = enums.MessageMediaType.LOCATION
|
||||
elif isinstance(media, raw.types.MessageMediaContact):
|
||||
contact = types.Contact._parse(client, media)
|
||||
media_type = enums.MessageMediaType.CONTACT
|
||||
elif isinstance(media, raw.types.MessageMediaVenue):
|
||||
venue = types.Venue._parse(client, media)
|
||||
media_type = enums.MessageMediaType.VENUE
|
||||
elif isinstance(media, raw.types.MessageMediaGame):
|
||||
game = types.Game._parse(client, media)
|
||||
media_type = enums.MessageMediaType.GAME
|
||||
elif isinstance(media, raw.types.MessageMediaGiveaway):
|
||||
giveaway = types.Giveaway._parse(client, reply, chats)
|
||||
media_type = enums.MessageMediaType.GIVEAWAY
|
||||
elif isinstance(media, raw.types.MessageMediaGiveawayResults):
|
||||
giveaway_result = await types.GiveawayResult._parse(client, media, users, chats)
|
||||
media_type = enums.MessageMediaType.GIVEAWAY_RESULT
|
||||
elif isinstance(media, raw.types.MessageMediaInvoice):
|
||||
invoice = types.Invoice._parse(media)
|
||||
media_type = enums.MessageMediaType.INVOICE
|
||||
elif isinstance(media, raw.types.MessageMediaStory):
|
||||
story = await types.Story._parse(client, media, media.peer)
|
||||
media_type = enums.MessageMediaType.STORY
|
||||
elif isinstance(media, raw.types.MessageMediaDocument):
|
||||
doc = media.document
|
||||
|
||||
if isinstance(doc, raw.types.Document):
|
||||
attributes = {type(i): i for i in doc.attributes}
|
||||
|
||||
file_name = getattr(
|
||||
attributes.get(
|
||||
raw.types.DocumentAttributeFilename, None
|
||||
), "file_name", None
|
||||
)
|
||||
|
||||
if raw.types.DocumentAttributeAnimated in attributes:
|
||||
video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
|
||||
animation = types.Animation._parse(client, doc, video_attributes, file_name)
|
||||
media_type = enums.MessageMediaType.ANIMATION
|
||||
has_media_spoiler = media.spoiler
|
||||
elif raw.types.DocumentAttributeSticker in attributes:
|
||||
sticker = await types.Sticker._parse(client, doc, attributes)
|
||||
media_type = enums.MessageMediaType.STICKER
|
||||
elif raw.types.DocumentAttributeVideo in attributes:
|
||||
video_attributes = attributes[raw.types.DocumentAttributeVideo]
|
||||
|
||||
if video_attributes.round_message:
|
||||
video_note = types.VideoNote._parse(client, doc, video_attributes)
|
||||
media_type = enums.MessageMediaType.VIDEO_NOTE
|
||||
else:
|
||||
video = types.Video._parse(
|
||||
client,
|
||||
doc,
|
||||
video_attributes,
|
||||
file_name,
|
||||
media.ttl_seconds,
|
||||
media.video_cover,
|
||||
media.video_timestamp
|
||||
)
|
||||
media_type = enums.MessageMediaType.VIDEO
|
||||
has_media_spoiler = media.spoiler
|
||||
elif raw.types.DocumentAttributeAudio in attributes:
|
||||
audio_attributes = attributes[raw.types.DocumentAttributeAudio]
|
||||
|
||||
if audio_attributes.voice:
|
||||
voice = types.Voice._parse(client, doc, audio_attributes)
|
||||
media_type = enums.MessageMediaType.VOICE
|
||||
else:
|
||||
audio = types.Audio._parse(client, doc, audio_attributes, file_name)
|
||||
media_type = enums.MessageMediaType.AUDIO
|
||||
else:
|
||||
document = types.Document._parse(client, doc, file_name)
|
||||
media_type = enums.MessageMediaType.DOCUMENT
|
||||
elif isinstance(media, raw.types.MessageMediaPoll):
|
||||
poll = types.Poll._parse(client, media, users)
|
||||
media_type = enums.MessageMediaType.POLL
|
||||
elif isinstance(media, raw.types.MessageMediaDice):
|
||||
dice = types.Dice._parse(client, media)
|
||||
media_type = enums.MessageMediaType.DICE
|
||||
elif isinstance(media, raw.types.MessageMediaPaidMedia):
|
||||
paid_media = types.PaidMedia._parse(client, media)
|
||||
media_type = enums.MessageMediaType.PAID_MEDIA
|
||||
else:
|
||||
media = None
|
||||
|
||||
return ExternalReplyInfo(
|
||||
origin=types.MessageOrigin._parse(
|
||||
client,
|
||||
reply.reply_from,
|
||||
users,
|
||||
chats,
|
||||
),
|
||||
chat=types.Chat._parse_chat(
|
||||
client,
|
||||
chats.get(utils.get_raw_peer_id(reply.reply_to_peer_id)),
|
||||
),
|
||||
message_id=reply.reply_to_msg_id,
|
||||
media=media_type,
|
||||
animation=animation,
|
||||
audio=audio,
|
||||
document=document,
|
||||
paid_media=paid_media,
|
||||
photo=photo,
|
||||
sticker=sticker,
|
||||
story=story,
|
||||
video=video,
|
||||
video_note=video_note,
|
||||
voice=voice,
|
||||
has_media_spoiler=has_media_spoiler,
|
||||
contact=contact,
|
||||
dice=dice,
|
||||
game=game,
|
||||
giveaway=giveaway,
|
||||
giveaway_result=giveaway_result,
|
||||
invoice=invoice,
|
||||
location=location,
|
||||
poll=poll,
|
||||
venue=venue
|
||||
)
|
||||
|
|
@ -69,12 +69,11 @@ class Game(Object):
|
|||
self.animation = animation
|
||||
|
||||
@staticmethod
|
||||
def _parse(client, message: "raw.types.Message") -> "Game":
|
||||
game: "raw.types.Game" = message.media.game
|
||||
def _parse(client, media: "raw.types.MessageMediaGame") -> "Game":
|
||||
animation = None
|
||||
|
||||
if game.document:
|
||||
attributes = {type(i): i for i in game.document.attributes}
|
||||
if media.game.document:
|
||||
attributes = {type(i): i for i in media.game.document.attributes}
|
||||
|
||||
file_name = getattr(
|
||||
attributes.get(
|
||||
|
|
@ -84,17 +83,17 @@ class Game(Object):
|
|||
|
||||
animation = types.Animation._parse(
|
||||
client,
|
||||
game.document,
|
||||
media.game.document,
|
||||
attributes.get(raw.types.DocumentAttributeVideo, None),
|
||||
file_name
|
||||
)
|
||||
|
||||
return Game(
|
||||
id=game.id,
|
||||
title=game.title,
|
||||
short_name=game.short_name,
|
||||
description=game.description,
|
||||
photo=types.Photo._parse(client, game.photo),
|
||||
id=media.game.id,
|
||||
title=media.game.title,
|
||||
short_name=media.game.short_name,
|
||||
description=media.game.description,
|
||||
photo=types.Photo._parse(client, media.game.photo),
|
||||
animation=animation,
|
||||
client=client
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ from datetime import datetime
|
|||
from pyrogram import raw, types, utils
|
||||
from pyrogram.errors import FloodWait
|
||||
from ..object import Object
|
||||
from typing import List
|
||||
from typing import List, Dict
|
||||
|
||||
|
||||
class Giveaway(Object):
|
||||
|
|
@ -73,7 +73,6 @@ class Giveaway(Object):
|
|||
stars: int = None,
|
||||
additional_price: str = None,
|
||||
allowed_countries: List[str] = None,
|
||||
private_channel_ids: List[int] = None,
|
||||
is_winners_hidden: bool = None
|
||||
):
|
||||
super().__init__(client)
|
||||
|
|
@ -86,28 +85,16 @@ class Giveaway(Object):
|
|||
self.new_subscribers = new_subscribers
|
||||
self.additional_price = additional_price
|
||||
self.allowed_countries = allowed_countries
|
||||
self.private_channel_ids = private_channel_ids
|
||||
self.is_winners_hidden = is_winners_hidden
|
||||
|
||||
@staticmethod
|
||||
async def _parse(client, message: "raw.types.Message") -> "Giveaway":
|
||||
async def _parse(
|
||||
client,
|
||||
message: "raw.types.Message",
|
||||
chats: Dict[int, "raw.types.Chat"] = None
|
||||
) -> "Giveaway":
|
||||
giveaway: "raw.types.MessageMediaGiveaway" = message.media
|
||||
chats = []
|
||||
private_ids = []
|
||||
for raw_chat_id in giveaway.channels:
|
||||
chat_id = utils.get_channel_id(raw_chat_id)
|
||||
try:
|
||||
chat = await client.invoke(
|
||||
raw.functions.channels.GetChannels(
|
||||
id=[await client.resolve_peer(chat_id)]
|
||||
)
|
||||
)
|
||||
except FloodWait as e:
|
||||
await asyncio.sleep(e.value)
|
||||
except Exception:
|
||||
private_ids.append(chat_id)
|
||||
else:
|
||||
chats.append(types.Chat._parse_chat(client, chat.chats[0]))
|
||||
chats = types.List([types.Chat._parse_channel_chat(client, chats.get(i)) for i in giveaway.channels])
|
||||
|
||||
return Giveaway(
|
||||
chats=chats,
|
||||
|
|
@ -118,7 +105,6 @@ class Giveaway(Object):
|
|||
new_subscribers=giveaway.only_new_subscribers,
|
||||
additional_price=giveaway.prize_description,
|
||||
allowed_countries=giveaway.countries_iso2 if len(giveaway.countries_iso2) > 0 else None,
|
||||
private_channel_ids=private_ids if len(private_ids) > 0 else None,
|
||||
is_winners_hidden=not giveaway.winners_are_visible,
|
||||
client=client
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import pyrogram
|
|||
from datetime import datetime
|
||||
from pyrogram import raw, types, utils
|
||||
from ..object import Object
|
||||
from typing import List, Union
|
||||
from typing import List, Union, Dict
|
||||
|
||||
|
||||
class GiveawayResult(Object):
|
||||
|
|
@ -104,7 +104,9 @@ class GiveawayResult(Object):
|
|||
"raw.types.MessageActionGiveawayResults",
|
||||
"raw.types.MessageMediaGiveawayResults"
|
||||
],
|
||||
hide_winners: bool = False
|
||||
hide_winners: bool = False,
|
||||
users: Dict[int, "raw.types.User"] = None,
|
||||
chats: Dict[int, "raw.types.Chat"] = None
|
||||
) -> "GiveawayResult":
|
||||
chat = None
|
||||
giveaway_message = None
|
||||
|
|
@ -112,17 +114,12 @@ class GiveawayResult(Object):
|
|||
winners = None
|
||||
if not hide_winners:
|
||||
chat_id = utils.get_channel_id(giveaway_result.channel_id)
|
||||
chat = await client.invoke(
|
||||
raw.functions.channels.GetChannels(
|
||||
id=[await client.resolve_peer(chat_id)]
|
||||
)
|
||||
)
|
||||
chat = types.Chat._parse_chat(client, chat.chats[0])
|
||||
chat = types.Chat._parse_channel_chat(client, chats.get(giveaway_result.channel_id))
|
||||
giveaway_message = await client.get_messages(chat_id, giveaway_result.launch_msg_id)
|
||||
expired_date = utils.timestamp_to_datetime(giveaway_result.until_date)
|
||||
winners = []
|
||||
for winner in giveaway_result.winners:
|
||||
winners.append(await client.get_users(winner))
|
||||
winners.append(types.User._parse(client, users.get(winner, None)))
|
||||
|
||||
stars = getattr(giveaway_result, "stars", None)
|
||||
|
||||
|
|
|
|||
|
|
@ -318,6 +318,9 @@ class Message(Object, Update):
|
|||
Messages sent from yourself to other chats are outgoing (*outgoing* is True).
|
||||
An exception is made for your own personal chat; messages sent there will be incoming.
|
||||
|
||||
external_reply (:obj:`~pyrogram.types.ExternalReplyInfo`, *optional*):
|
||||
Information about the message that is being replied to, which may come from another chat or forum topic.
|
||||
|
||||
matches (List of regex Matches, *optional*):
|
||||
A list containing all `Match Objects <https://docs.python.org/3/library/re.html#match-objects>`_ that match
|
||||
the text of this message. Only applicable when using :obj:`Filters.regex <pyrogram.Filters.regex>`.
|
||||
|
|
@ -507,6 +510,7 @@ class Message(Object, Update):
|
|||
forwards: int = None,
|
||||
via_bot: "types.User" = None,
|
||||
outgoing: bool = None,
|
||||
external_reply: Optional["types.ExternalReplyInfo"] = None,
|
||||
matches: List[Match] = None,
|
||||
command: List[str] = None,
|
||||
bot_allowed: "types.BotAllowed" = None,
|
||||
|
|
@ -546,8 +550,8 @@ class Message(Object, Update):
|
|||
self.sender_business_bot = sender_business_bot
|
||||
self.date = date
|
||||
self.chat = chat
|
||||
self.topic = topic
|
||||
self.forward_origin = forward_origin
|
||||
self.external_reply = external_reply
|
||||
self.is_topic_message = is_topic_message
|
||||
self.reply_to_chat_id = reply_to_chat_id
|
||||
self.reply_to_message_id = reply_to_message_id
|
||||
|
|
@ -848,7 +852,7 @@ class Message(Object, Update):
|
|||
giveaway_launched = types.GiveawayLaunched._parse(client, action)
|
||||
service_type = enums.MessageServiceType.GIVEAWAY_LAUNCHED
|
||||
elif isinstance(action, raw.types.MessageActionGiveawayResults):
|
||||
giveaway_result = await types.GiveawayResult._parse(client, action, True)
|
||||
giveaway_result = await types.GiveawayResult._parse(client, action, True, users, chats)
|
||||
service_type = enums.MessageServiceType.GIVEAWAY_RESULT
|
||||
elif isinstance(action, raw.types.MessageActionBoostApply):
|
||||
boosts_applied = action.boosts
|
||||
|
|
@ -1032,13 +1036,13 @@ class Message(Object, Update):
|
|||
venue = types.Venue._parse(client, media)
|
||||
media_type = enums.MessageMediaType.VENUE
|
||||
elif isinstance(media, raw.types.MessageMediaGame):
|
||||
game = types.Game._parse(client, message)
|
||||
game = types.Game._parse(client, media)
|
||||
media_type = enums.MessageMediaType.GAME
|
||||
elif isinstance(media, raw.types.MessageMediaGiveaway):
|
||||
giveaway = await types.Giveaway._parse(client, message)
|
||||
giveaway = await types.Giveaway._parse(client, message, chats)
|
||||
media_type = enums.MessageMediaType.GIVEAWAY
|
||||
elif isinstance(media, raw.types.MessageMediaGiveawayResults):
|
||||
giveaway_result = await types.GiveawayResult._parse(client, message.media)
|
||||
giveaway_result = await types.GiveawayResult._parse(client, message.media, users=users, chats=chats)
|
||||
media_type = enums.MessageMediaType.GIVEAWAY_RESULT
|
||||
elif isinstance(media, raw.types.MessageMediaStory):
|
||||
story = await types.MessageStory._parse(client, media)
|
||||
|
|
@ -1139,7 +1143,7 @@ class Message(Object, Update):
|
|||
from_user = types.User._parse(client, users.get(user_id, None))
|
||||
sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None
|
||||
|
||||
reactions = types.MessageReactions._parse(client, message.reactions, users)
|
||||
reactions = types.MessageReactions._parse(client, message.reactions, users, chats)
|
||||
|
||||
if message.via_business_bot_id:
|
||||
sender_business_bot = types.User._parse(client, users.get(message.via_business_bot_id, None))
|
||||
|
|
@ -1221,6 +1225,12 @@ class Message(Object, Update):
|
|||
parsed_message.sender_chat = sender_chat
|
||||
|
||||
if message.reply_to:
|
||||
parsed_message.external_reply = await types.ExternalReplyInfo._parse(
|
||||
client,
|
||||
message.reply_to,
|
||||
users,
|
||||
chats
|
||||
)
|
||||
if isinstance(message.reply_to, raw.types.MessageReplyHeader):
|
||||
if message.reply_to.quote:
|
||||
parsed_message.quote = types.TextQuote._parse(
|
||||
|
|
@ -1263,20 +1273,15 @@ class Message(Object, Update):
|
|||
|
||||
if replies:
|
||||
if parsed_message.reply_to_message_id:
|
||||
if rtci is not None and parsed_message.chat.id != reply_to_chat_id:
|
||||
key = (reply_to_chat_id, message.reply_to.reply_to_msg_id)
|
||||
reply_to_params = {"chat_id": key[0], 'message_ids': key[1]}
|
||||
else:
|
||||
key = (parsed_message.chat.id, parsed_message.reply_to_message_id)
|
||||
reply_to_params = {'chat_id': key[0], 'reply_to_message_ids': message.id}
|
||||
|
||||
try:
|
||||
key = (parsed_message.chat.id, parsed_message.reply_to_message_id)
|
||||
reply_to_message = client.message_cache[key]
|
||||
|
||||
if not reply_to_message:
|
||||
reply_to_message = await client.get_messages(
|
||||
replies=replies - 1,
|
||||
**reply_to_params
|
||||
parsed_message.chat.id,
|
||||
reply_to_message_ids=message.id,
|
||||
replies=replies - 1
|
||||
)
|
||||
if reply_to_message and not reply_to_message.forum_topic_created:
|
||||
parsed_message.reply_to_message = reply_to_message
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ class MessageReactions(Object):
|
|||
def _parse(
|
||||
client: "pyrogram.Client",
|
||||
message_reactions: Optional["raw.base.MessageReactions"] = None,
|
||||
users: Optional[Dict[int, "raw.types.User"]] = None
|
||||
users: Optional[Dict[int, "raw.types.User"]] = None,
|
||||
chats: Dict[int, "raw.types.Chat"] = None
|
||||
) -> Optional["MessageReactions"]:
|
||||
if not message_reactions:
|
||||
return None
|
||||
|
|
@ -63,7 +64,7 @@ class MessageReactions(Object):
|
|||
for reaction in message_reactions.results
|
||||
],
|
||||
top_reactors=[
|
||||
types.MessageReactor._parse(client, reactor, users)
|
||||
types.MessageReactor._parse(client, reactor, users, chats)
|
||||
for reactor in message_reactions.top_reactors
|
||||
]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ class MessageReactor(Object):
|
|||
|
||||
from_user (:obj:`~pyrogram.types.User`, *optional*):
|
||||
Information about the reactor.
|
||||
|
||||
sender_chat (:obj:`~pyrogram.types.Chat`, *optional*):
|
||||
Information about the sender chat.
|
||||
"""
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -51,7 +54,8 @@ class MessageReactor(Object):
|
|||
is_top: bool = None,
|
||||
is_my: bool = None,
|
||||
is_anonymous: bool = None,
|
||||
from_user: "types.User" = None
|
||||
from_user: "types.User" = None,
|
||||
sender_chat: "types.Chat" = None
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
|
|
@ -60,26 +64,39 @@ class MessageReactor(Object):
|
|||
self.is_my = is_my
|
||||
self.is_anonymous = is_anonymous
|
||||
self.from_user = from_user
|
||||
self.sender_chat = sender_chat
|
||||
|
||||
@staticmethod
|
||||
def _parse(
|
||||
client: "pyrogram.Client",
|
||||
message_reactor: Optional["raw.base.MessageReactor"] = None,
|
||||
users: Dict[int, "raw.types.User"] = None
|
||||
users: Dict[int, "raw.types.User"] = None,
|
||||
chats: Dict[int, "raw.types.Chat"] = None
|
||||
) -> Optional["MessageReactor"]:
|
||||
if not message_reactor:
|
||||
return None
|
||||
|
||||
is_anonymous = message_reactor.anonymous
|
||||
from_user = None
|
||||
sender_chat = None
|
||||
if not is_anonymous:
|
||||
from_user = types.User._parse(client, users.get(message_reactor.peer_id.user_id))
|
||||
|
||||
if isinstance(message_reactor.peer, raw.types.PeerUser):
|
||||
from_user = types.User._parse(
|
||||
client,
|
||||
users.get(message_reactor.peer_id.user_id)
|
||||
)
|
||||
elif isinstance(message_reactor.peer, raw.types.PeerChannel):
|
||||
sender_chat = types.Chat._parse_channel_chat(
|
||||
client,
|
||||
chats.get(message_reactor.peer_id.channel_id)
|
||||
)
|
||||
|
||||
return MessageReactor(
|
||||
client=client,
|
||||
amount=message_reactor.count,
|
||||
is_top=message_reactor.top,
|
||||
is_my=message_reactor.my,
|
||||
is_anonymous=is_anonymous,
|
||||
from_user=from_user
|
||||
from_user=from_user,
|
||||
sender_chat=sender_chat
|
||||
)
|
||||
|
|
|
|||
|
|
@ -121,9 +121,14 @@ async def parse_messages(
|
|||
|
||||
if replies:
|
||||
messages_with_replies = {
|
||||
i.id: i.reply_to
|
||||
i.id: i.reply_to.reply_to_msg_id
|
||||
for i in messages.messages
|
||||
if not isinstance(i, raw.types.MessageEmpty) and i.reply_to and isinstance(i.reply_to, raw.types.MessageReplyHeader)
|
||||
if (
|
||||
not isinstance(i, raw.types.MessageEmpty)
|
||||
and i.reply_to
|
||||
and isinstance(i.reply_to, raw.types.MessageReplyHeader)
|
||||
and i.reply_to.reply_to_msg_id is not None
|
||||
)
|
||||
}
|
||||
|
||||
message_reply_to_story = {
|
||||
|
|
@ -136,61 +141,27 @@ async def parse_messages(
|
|||
# We need a chat id, but some messages might be empty (no chat attribute available)
|
||||
# Scan until we find a message with a chat available (there must be one, because we are fetching replies)
|
||||
for m in parsed_messages:
|
||||
if not isinstance(m, types.Message):
|
||||
continue
|
||||
|
||||
if m.chat:
|
||||
chat_id = m.chat.id
|
||||
break
|
||||
else:
|
||||
chat_id = 0
|
||||
|
||||
is_all_within_chat = not any(
|
||||
value.reply_to_peer_id
|
||||
for value in messages_with_replies.values()
|
||||
reply_messages = await client.get_messages(
|
||||
chat_id,
|
||||
reply_to_message_ids=messages_with_replies.keys(),
|
||||
replies=replies - 1
|
||||
)
|
||||
reply_messages: List[pyrogram.types.Message] = []
|
||||
if is_all_within_chat:
|
||||
# fast path: fetch all messages within the same chat
|
||||
reply_messages = await client.get_messages(
|
||||
chat_id,
|
||||
reply_to_message_ids=messages_with_replies.keys(),
|
||||
replies=replies - 1
|
||||
)
|
||||
else:
|
||||
# slow path: fetch all messages individually
|
||||
for target_reply_to in messages_with_replies.values():
|
||||
to_be_added_msg = None
|
||||
the_chat_id = chat_id
|
||||
if target_reply_to.reply_to_peer_id:
|
||||
the_chat_id = get_channel_id(target_reply_to.reply_to_peer_id.channel_id)
|
||||
to_be_added_msg = await client.get_messages(
|
||||
chat_id=the_chat_id,
|
||||
message_ids=target_reply_to.reply_to_msg_id,
|
||||
replies=replies - 1
|
||||
)
|
||||
if isinstance(to_be_added_msg, list):
|
||||
for current_to_be_added in to_be_added_msg:
|
||||
reply_messages.append(current_to_be_added)
|
||||
elif to_be_added_msg:
|
||||
reply_messages.append(to_be_added_msg)
|
||||
|
||||
for message in parsed_messages:
|
||||
reply_to = messages_with_replies.get(message.id, None)
|
||||
if not reply_to:
|
||||
continue
|
||||
|
||||
reply_id = reply_to.reply_to_msg_id
|
||||
reply_id = messages_with_replies.get(message.id, None)
|
||||
|
||||
for reply in reply_messages:
|
||||
if reply.id == reply_id and not reply.forum_topic_created:
|
||||
message.reply_to_message = reply
|
||||
|
||||
if reply.id == reply_id:
|
||||
if not reply.forum_topic_created:
|
||||
message.reply_to_message = reply
|
||||
if message_reply_to_story:
|
||||
for m in parsed_messages:
|
||||
if not isinstance(m, types.Message):
|
||||
continue
|
||||
|
||||
if m.chat:
|
||||
chat_id = m.chat.id
|
||||
break
|
||||
|
|
@ -198,7 +169,7 @@ async def parse_messages(
|
|||
chat_id = 0
|
||||
|
||||
reply_messages = {}
|
||||
for msg_id in message_reply_to_story:
|
||||
for msg_id in message_reply_to_story.keys():
|
||||
reply_messages[msg_id] = await client.get_stories(
|
||||
message_reply_to_story[msg_id]['user_id'],
|
||||
message_reply_to_story[msg_id]['story_id']
|
||||
|
|
|
|||
Loading…
Reference in a new issue