mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add new methods for stories
This commit is contained in:
parent
ac6e5d6600
commit
444ada3b71
@ -18,9 +18,11 @@
|
|||||||
|
|
||||||
from .apply_boost import ApplyBoost
|
from .apply_boost import ApplyBoost
|
||||||
from .can_send_story import CanSendStory
|
from .can_send_story import CanSendStory
|
||||||
|
from .copy_story import CopyStory
|
||||||
from .delete_stories import DeleteStories
|
from .delete_stories import DeleteStories
|
||||||
from .edit_story import EditStory
|
from .edit_story import EditStory
|
||||||
from .export_story_link import ExportStoryLink
|
from .export_story_link import ExportStoryLink
|
||||||
|
from .forward_story import ForwardStory
|
||||||
from .get_all_stories import GetAllStories
|
from .get_all_stories import GetAllStories
|
||||||
from .get_peer_stories import GetPeerStories
|
from .get_peer_stories import GetPeerStories
|
||||||
from .get_pinned_stories import GetPinnedStories
|
from .get_pinned_stories import GetPinnedStories
|
||||||
@ -35,9 +37,11 @@ from .send_story import SendStory
|
|||||||
class Stories(
|
class Stories(
|
||||||
ApplyBoost,
|
ApplyBoost,
|
||||||
CanSendStory,
|
CanSendStory,
|
||||||
|
CopyStory,
|
||||||
DeleteStories,
|
DeleteStories,
|
||||||
EditStory,
|
EditStory,
|
||||||
ExportStoryLink,
|
ExportStoryLink,
|
||||||
|
ForwardStory,
|
||||||
GetAllStories,
|
GetAllStories,
|
||||||
GetPeerStories,
|
GetPeerStories,
|
||||||
GetPinnedStories,
|
GetPinnedStories,
|
||||||
|
117
pyrogram/methods/stories/copy_story.py
Normal file
117
pyrogram/methods/stories/copy_story.py
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
# 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/>.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Union, List, Optional
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import types, enums, utils
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class CopyStory:
|
||||||
|
async def copy_story(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
chat_id: Union[int, str],
|
||||||
|
from_chat_id: Union[int, str],
|
||||||
|
story_id: int,
|
||||||
|
caption: str = None,
|
||||||
|
parse_mode: Optional["enums.ParseMode"] = None,
|
||||||
|
caption_entities: List["types.MessageEntity"] = None,
|
||||||
|
period: int = None,
|
||||||
|
privacy: "enums.StoriesPrivacyRules" = None,
|
||||||
|
allowed_users: List[Union[int, str]] = None,
|
||||||
|
disallowed_users: List[Union[int, str]] = None,
|
||||||
|
protect_content: bool = None
|
||||||
|
) -> "types.Story":
|
||||||
|
"""Copy story.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users-bots.rst
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
chat_id (``int`` | ``str``):
|
||||||
|
Unique identifier (int) or username (str) of the target chat.
|
||||||
|
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
||||||
|
|
||||||
|
from_chat_id (``int`` | ``str``):
|
||||||
|
Unique identifier (int) or username (str) of the source chat where the original message was sent.
|
||||||
|
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
||||||
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
|
story_id (``int``):
|
||||||
|
Message identifier in the chat specified in *from_chat_id*.
|
||||||
|
|
||||||
|
caption (``string``, *optional*):
|
||||||
|
New caption for story, 0-1024 characters after entities parsing.
|
||||||
|
If not specified, the original caption is kept.
|
||||||
|
Pass "" (empty string) to remove the caption.
|
||||||
|
|
||||||
|
period (``int``, *optional*):
|
||||||
|
How long the story will posted, in secs.
|
||||||
|
only for premium users.
|
||||||
|
|
||||||
|
privacy (:obj:`~pyrogram.enums.StoriesPrivacyRules`, *optional*):
|
||||||
|
Story privacy.
|
||||||
|
Defaults to :obj:`~pyrogram.enums.StoriesPrivacyRules.PUBLIC`
|
||||||
|
|
||||||
|
allowed_users (List of ``int``, *optional*):
|
||||||
|
List of user_id or chat_id of chat users who are allowed to view stories.
|
||||||
|
Note: chat_id available only with :obj:`~pyrogram.enums.StoriesPrivacyRules.SELECTED_USERS`.
|
||||||
|
Works with :obj:`~pyrogram.enums.StoriesPrivacyRules.CLOSE_FRIENDS`
|
||||||
|
and :obj:`~pyrogram.enums.StoriesPrivacyRules.SELECTED_USERS` only
|
||||||
|
|
||||||
|
disallowed_users (List of ``int``, *optional*):
|
||||||
|
List of user_id whos disallow to view the stories.
|
||||||
|
Note: Works with :obj:`~pyrogram.enums.StoriesPrivacyRules.PUBLIC`
|
||||||
|
and :obj:`~pyrogram.enums.StoriesPrivacyRules.CONTACTS` only
|
||||||
|
|
||||||
|
protect_content (``bool``, *optional*):
|
||||||
|
Protects the contents of the sent story from forwarding and saving.
|
||||||
|
|
||||||
|
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 new caption, which can be specified instead of *parse_mode*.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
:obj:`~pyrogram.types.Story`: On success, the copied story is returned.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Copy a story
|
||||||
|
await app.copy_story(to_chat, from_chat, 123)
|
||||||
|
|
||||||
|
"""
|
||||||
|
story: types.Story = await self.get_stories(from_chat_id, story_id)
|
||||||
|
|
||||||
|
return await story.copy(
|
||||||
|
chat_id=chat_id,
|
||||||
|
caption=caption,
|
||||||
|
period=period,
|
||||||
|
protect_content=protect_content,
|
||||||
|
parse_mode=parse_mode,
|
||||||
|
caption_entities=caption_entities,
|
||||||
|
privacy=privacy,
|
||||||
|
allowed_users=allowed_users,
|
||||||
|
disallowed_users=disallowed_users
|
||||||
|
)
|
99
pyrogram/methods/stories/forward_story.py
Normal file
99
pyrogram/methods/stories/forward_story.py
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
# 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 datetime import datetime
|
||||||
|
from typing import Union, Optional
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw
|
||||||
|
from pyrogram import types
|
||||||
|
from pyrogram import utils
|
||||||
|
|
||||||
|
class ForwardStory:
|
||||||
|
async def forward_story(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
chat_id: Union[int, str],
|
||||||
|
from_chat_id: Union[int, str],
|
||||||
|
story_id: int,
|
||||||
|
disable_notification: bool = None,
|
||||||
|
message_thread_id: int = None,
|
||||||
|
schedule_date: datetime = None,
|
||||||
|
) -> Optional["types.Message"]:
|
||||||
|
"""Send story.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users-bots.rst
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
chat_id (``int`` | ``str``):
|
||||||
|
Unique identifier (int) or username (str) of the target chat.
|
||||||
|
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
||||||
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
|
from_chat_id (``int`` | ``str``):
|
||||||
|
Unique identifier (int) or username (str) of the target chat.
|
||||||
|
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
||||||
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
|
story_id (``int``):
|
||||||
|
Unique identifier of story.
|
||||||
|
|
||||||
|
disable_notification (``bool``, *optional*):
|
||||||
|
Sends the message silently.
|
||||||
|
Users will receive a notification with no sound.
|
||||||
|
|
||||||
|
message_thread_id (``int``, *optional*):
|
||||||
|
Unique identifier for the target message thread (topic) of the forum.
|
||||||
|
for forum supergroups only.
|
||||||
|
|
||||||
|
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
|
||||||
|
Date when the message will be automatically sent.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
:obj:`~pyrogram.types.Message`: On success, the sent stoty message is returned.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Send your story to chat_id
|
||||||
|
await app.forward_story(chat_id, "me", 1)
|
||||||
|
"""
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.messages.SendMedia(
|
||||||
|
peer=await self.resolve_peer(chat_id),
|
||||||
|
media=raw.types.InputMediaStory(
|
||||||
|
peer=await self.resolve_peer(from_chat_id),
|
||||||
|
id=story_id
|
||||||
|
),
|
||||||
|
silent=disable_notification or None,
|
||||||
|
random_id=self.rnd_id(),
|
||||||
|
schedule_date=utils.datetime_to_timestamp(schedule_date),
|
||||||
|
message="",
|
||||||
|
reply_to=utils.get_reply_to(message_thread_id=message_thread_id),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
for i in r.updates:
|
||||||
|
if isinstance(i, (raw.types.UpdateNewMessage,
|
||||||
|
raw.types.UpdateNewChannelMessage,
|
||||||
|
raw.types.UpdateNewScheduledMessage)):
|
||||||
|
return await types.Message._parse(
|
||||||
|
self, i.message,
|
||||||
|
{i.id: i for i in r.users},
|
||||||
|
{i.id: i for i in r.chats},
|
||||||
|
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage)
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user