Skip to content

Commit

Permalink
Add emoji and caption parameter to send_sticker
Browse files Browse the repository at this point in the history
Closes #86
  • Loading branch information
KurimuzonAkuma committed Nov 27, 2024
1 parent ba49bbf commit cd239fc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
41 changes: 31 additions & 10 deletions pyrogram/methods/messages/send_sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ async def send_sticker(
self: "pyrogram.Client",
chat_id: Union[int, str],
sticker: Union[str, BinaryIO],
emoji: str = "",
caption: str = "",
parse_mode: Optional["enums.ParseMode"] = None,
caption_entities: List["types.MessageEntity"] = None,
disable_notification: bool = None,
message_thread_id: int = None,
effect_id: int = None,
reply_to_message_id: int = None,
reply_to_chat_id: Union[int, str] = None,
reply_to_story_id: int = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
quote_entities: List["types.MessageEntity"] = None,
quote_offset: int = None,
schedule_date: datetime = None,
Expand Down Expand Up @@ -76,6 +79,19 @@ async def send_sticker(
pass a file path as string to upload a new sticker that exists on your local machine, or
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
emoji (``str``, *optional*):
Emoji associated with this sticker.
caption (``str``, *optional*):
Sticker caption, 0-1024 characters.
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
disable_notification (``bool``, *optional*):
Sends the message silently.
Users will receive a notification with no sound.
Expand All @@ -100,10 +116,6 @@ async def send_sticker(
quote_text (``str``, *optional*):
Text of the quote to be sent.
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
quote_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
List of special entities that appear in quote text, which can be specified instead of *parse_mode*.
Expand Down Expand Up @@ -175,7 +187,11 @@ async def send_sticker(
mime_type=self.guess_mime_type(sticker) or "image/webp",
file=file,
attributes=[
raw.types.DocumentAttributeFilename(file_name=os.path.basename(sticker))
raw.types.DocumentAttributeFilename(file_name=os.path.basename(sticker)),
raw.types.DocumentAttributeSticker(
alt=emoji,
stickerset=raw.types.InputStickerSetEmpty()
),
]
)
elif re.match("^https?://", sticker):
Expand All @@ -190,7 +206,11 @@ async def send_sticker(
mime_type=self.guess_mime_type(sticker.name) or "image/webp",
file=file,
attributes=[
raw.types.DocumentAttributeFilename(file_name=sticker.name)
raw.types.DocumentAttributeFilename(file_name=sticker.name),
raw.types.DocumentAttributeSticker(
alt=emoji,
stickerset=raw.types.InputStickerSetEmpty()
),
]
)

Expand Down Expand Up @@ -218,8 +238,8 @@ async def send_sticker(
noforwards=protect_content,
allow_paid_floodskip=allow_paid_broadcast,
reply_markup=await reply_markup.write(self) if reply_markup else None,
message="",
effect=effect_id
effect=effect_id,
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
),
business_connection_id=business_connection_id
)
Expand All @@ -236,7 +256,8 @@ async def send_sticker(
{i.id: i for i in r.users},
{i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
business_connection_id=getattr(i, "connection_id", None)
business_connection_id=getattr(i, "connection_id", None),
raw_reply_to_message=getattr(i, "reply_to_message", None),
)
except StopTransmission:
return None
27 changes: 21 additions & 6 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3234,12 +3234,15 @@ async def reply_sticker(
self,
sticker: Union[str, BinaryIO],
quote: bool = None,
emoji: str = "",
caption: str = "",
parse_mode: Optional["enums.ParseMode"] = None,
caption_entities: List["types.MessageEntity"] = None,
disable_notification: bool = None,
message_thread_id: int = None,
effect_id: int = None,
reply_to_message_id: int = None,
quote_text: str = None,
parse_mode: Optional["enums.ParseMode"] = None,
quote_entities: List["types.MessageEntity"] = None,
business_connection_id: str = None,
allow_paid_broadcast: bool = None,
Expand Down Expand Up @@ -3280,6 +3283,19 @@ async def reply_sticker(
If *reply_to_message_id* is passed, this parameter will be ignored.
Defaults to ``True`` in group chats and ``False`` in private chats.
emoji (``str``, *optional*):
Emoji associated with this sticker.
caption (``str``, *optional*):
Sticker caption, 0-1024 characters.
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
disable_notification (``bool``, *optional*):
Sends the message silently.
Users will receive a notification with no sound.
Expand All @@ -3298,10 +3314,6 @@ async def reply_sticker(
quote_text (``str``):
Text of the quote to be sent.
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
quote_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in quote text, which can be specified instead of *parse_mode*.
Expand Down Expand Up @@ -3363,12 +3375,15 @@ async def reply_sticker(
return await self._client.send_sticker(
chat_id=self.chat.id,
sticker=sticker,
emoji=emoji,
caption=caption,
parse_mode=parse_mode,
caption_entities=caption_entities,
disable_notification=disable_notification,
message_thread_id=message_thread_id,
effect_id=effect_id,
reply_to_message_id=reply_to_message_id,
quote_text=quote_text,
parse_mode=parse_mode,
quote_entities=quote_entities,
business_connection_id=business_connection_id,
allow_paid_broadcast=allow_paid_broadcast,
Expand Down

0 comments on commit cd239fc

Please sign in to comment.