From 97f0ecc7c9b24ba246329148e7ab554082f6c069 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Mon, 2 Jan 2023 00:35:32 +0700 Subject: [PATCH] PyroFork: Add CloseGeneralTopic, EditGeneralTopic, ReopenGeneralTopic, HideGeneralTopic. UnhideGeneralTopic, and some cleanup Signed-off-by: wulan17 --- pyrogram/methods/chats/__init__.py | 10 ++++ pyrogram/methods/chats/close_forum_topic.py | 16 ++---- pyrogram/methods/chats/close_general_topic.py | 52 +++++++++++++++++ pyrogram/methods/chats/edit_forum_topic.py | 18 +++--- pyrogram/methods/chats/edit_general_topic.py | 56 +++++++++++++++++++ pyrogram/methods/chats/hide_general_topic.py | 52 +++++++++++++++++ pyrogram/methods/chats/reopen_forum_topic.py | 16 ++---- .../methods/chats/reopen_general_topic.py | 52 +++++++++++++++++ .../methods/chats/unhide_general_topic.py | 52 +++++++++++++++++ 9 files changed, 293 insertions(+), 31 deletions(-) create mode 100644 pyrogram/methods/chats/close_general_topic.py create mode 100644 pyrogram/methods/chats/edit_general_topic.py create mode 100644 pyrogram/methods/chats/hide_general_topic.py create mode 100644 pyrogram/methods/chats/reopen_general_topic.py create mode 100644 pyrogram/methods/chats/unhide_general_topic.py diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index cf13ea85..56e20892 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -24,13 +24,18 @@ from .create_forum_topic import CreateForumTopic from .create_group import CreateGroup from .create_supergroup import CreateSupergroup from .close_forum_topic import CloseForumTopic +from .close_general_topic import CloseGeneralTopic from .delete_channel import DeleteChannel from .delete_chat_photo import DeleteChatPhoto from .delete_forum_topic import DeleteForumTopic from .delete_supergroup import DeleteSupergroup from .delete_user_history import DeleteUserHistory from .edit_forum_topic import EditForumTopic +from .edit_general_topic import EditGeneralTopic from .reopen_forum_topic import ReopenForumTopic +from .reopen_general_topic import ReopenGeneralTopic +from .hide_general_topic import HideGeneralTopic +from .unhide_general_topic import UnhideGeneralTopic from .get_chat import GetChat from .get_chat_event_log import GetChatEventLog from .get_chat_member import GetChatMember @@ -90,12 +95,17 @@ class Chats( CreateChannel, CreateForumTopic, CloseForumTopic, + CloseGeneralTopic, AddChatMembers, DeleteChannel, DeleteForumTopic, DeleteSupergroup, EditForumTopic, + EditGeneralTopic, ReopenForumTopic, + ReopenGeneralTopic, + HideGeneralTopic, + UnhideGeneralTopic, GetNearbyChats, SetAdministratorTitle, SetSlowMode, diff --git a/pyrogram/methods/chats/close_forum_topic.py b/pyrogram/methods/chats/close_forum_topic.py index 513080f5..3eae116b 100644 --- a/pyrogram/methods/chats/close_forum_topic.py +++ b/pyrogram/methods/chats/close_forum_topic.py @@ -46,15 +46,11 @@ class CloseForumTopic: await app.close_forum_topic(chat_id, topic_id) """ - try: - await self.invoke( - raw.functions.channels.EditForumTopic( - channel=await self.resolve_peer(chat_id), - topic_id=topic_id, - closed=True - ) + await self.invoke( + raw.functions.channels.EditForumTopic( + channel=await self.resolve_peer(chat_id), + topic_id=topic_id, + closed=True ) - except Exception as e: - print(e) - return False + ) return True diff --git a/pyrogram/methods/chats/close_general_topic.py b/pyrogram/methods/chats/close_general_topic.py new file mode 100644 index 00000000..be5fd006 --- /dev/null +++ b/pyrogram/methods/chats/close_general_topic.py @@ -0,0 +1,52 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . +import pyrogram +from pyrogram import raw +from pyrogram import types +from typing import Union + + +class CloseGeneralTopic: + async def close_general_topic( + self: "pyrogram.Client", + chat_id: Union[int, str] + ) -> bool: + """Close a forum topic. + + .. include:: /_includes/usable-by/users-bots.rst + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + Returns: + `bool`: On success, a Boolean is returned. + + Example: + .. code-block:: python + + await app.close_forum_topic(chat_id, topic_id) + """ + await self.invoke( + raw.functions.channels.EditForumTopic( + channel=await self.resolve_peer(chat_id), + topic_id=1, + closed=True + ) + ) + return True diff --git a/pyrogram/methods/chats/edit_forum_topic.py b/pyrogram/methods/chats/edit_forum_topic.py index 95dd4f89..c37096d6 100644 --- a/pyrogram/methods/chats/edit_forum_topic.py +++ b/pyrogram/methods/chats/edit_forum_topic.py @@ -54,16 +54,12 @@ class EditForumTopic: await app.edit_forum_topic(chat_id,topic_id,"New Topic Title") """ - try: - await self.invoke( - raw.functions.channels.EditForumTopic( - channel=await self.resolve_peer(chat_id), - topic_id=topic_id, - title=title, - icon_emoji_id=icon_emoji_id - ) + await self.invoke( + raw.functions.channels.EditForumTopic( + channel=await self.resolve_peer(chat_id), + topic_id=topic_id, + title=title, + icon_emoji_id=icon_emoji_id ) - except Exception as e: - print(e) - return False + ) return True diff --git a/pyrogram/methods/chats/edit_general_topic.py b/pyrogram/methods/chats/edit_general_topic.py new file mode 100644 index 00000000..6dd8690d --- /dev/null +++ b/pyrogram/methods/chats/edit_general_topic.py @@ -0,0 +1,56 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . +import pyrogram +from pyrogram import raw +from pyrogram import types +from typing import Union + + +class EditGeneralTopic: + async def edit_general_topic( + self: "pyrogram.Client", + chat_id: Union[int, str], + title: str + ) -> bool: + """Edit a general forum topic. + + .. include:: /_includes/usable-by/users-bots.rst + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + title (``str``): + The general forum topic title. + + Returns: + `bool`: On success, a Boolean is returned. + + Example: + .. code-block:: python + + await app.edit_forum_topic(chat_id,topic_id,"New Topic Title") + """ + await self.invoke( + raw.functions.channels.EditForumTopic( + channel=await self.resolve_peer(chat_id), + topic_id=1, + title=title + ) + ) + return True diff --git a/pyrogram/methods/chats/hide_general_topic.py b/pyrogram/methods/chats/hide_general_topic.py new file mode 100644 index 00000000..43b076a5 --- /dev/null +++ b/pyrogram/methods/chats/hide_general_topic.py @@ -0,0 +1,52 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . +import pyrogram +from pyrogram import raw +from pyrogram import types +from typing import Union + + +class HideGeneralTopic: + async def hide_general_topic( + self: "pyrogram.Client", + chat_id: Union[int, str] + ) -> bool: + """hide a general forum topic. + + .. include:: /_includes/usable-by/users-bots.rst + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + Returns: + `bool`: On success, a Boolean is returned. + + Example: + .. code-block:: python + + await app.close_forum_topic(chat_id, topic_id) + """ + await self.invoke( + raw.functions.channels.EditForumTopic( + channel=await self.resolve_peer(chat_id), + topic_id=1, + hidden=True + ) + ) + return True diff --git a/pyrogram/methods/chats/reopen_forum_topic.py b/pyrogram/methods/chats/reopen_forum_topic.py index 1baa8ffb..a70cb1ee 100644 --- a/pyrogram/methods/chats/reopen_forum_topic.py +++ b/pyrogram/methods/chats/reopen_forum_topic.py @@ -46,15 +46,11 @@ class ReopenForumTopic: await app.reopen_forum_topic(chat_id, topic_id) """ - try: - await self.invoke( - raw.functions.channels.EditForumTopic( - channel=await self.resolve_peer(chat_id), - topic_id=topic_id, - closed=False - ) + await self.invoke( + raw.functions.channels.EditForumTopic( + channel=await self.resolve_peer(chat_id), + topic_id=topic_id, + closed=False ) - except Exception as e: - print(e) - return False + ) return True diff --git a/pyrogram/methods/chats/reopen_general_topic.py b/pyrogram/methods/chats/reopen_general_topic.py new file mode 100644 index 00000000..4589b9b8 --- /dev/null +++ b/pyrogram/methods/chats/reopen_general_topic.py @@ -0,0 +1,52 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . +import pyrogram +from pyrogram import raw +from pyrogram import types +from typing import Union + + +class ReopenGeneralTopic: + async def reopen_general_topic( + self: "pyrogram.Client", + chat_id: Union[int, str] + ) -> bool: + """Reopen a forum topic. + + .. include:: /_includes/usable-by/users-bots.rst + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + Returns: + `bool`: On success, a Boolean is returned. + + Example: + .. code-block:: python + + await app.reopen_forum_topic(chat_id, topic_id) + """ + await self.invoke( + raw.functions.channels.EditForumTopic( + channel=await self.resolve_peer(chat_id), + topic_id=1, + closed=False + ) + ) + return True diff --git a/pyrogram/methods/chats/unhide_general_topic.py b/pyrogram/methods/chats/unhide_general_topic.py new file mode 100644 index 00000000..1cda8f46 --- /dev/null +++ b/pyrogram/methods/chats/unhide_general_topic.py @@ -0,0 +1,52 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . +import pyrogram +from pyrogram import raw +from pyrogram import types +from typing import Union + + +class UnhideGeneralTopic: + async def unhide_general_topic( + self: "pyrogram.Client", + chat_id: Union[int, str] + ) -> bool: + """unhide a general forum topic. + + .. include:: /_includes/usable-by/users-bots.rst + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + Returns: + `bool`: On success, a Boolean is returned. + + Example: + .. code-block:: python + + await app.close_forum_topic(chat_id, topic_id) + """ + await self.invoke( + raw.functions.channels.EditForumTopic( + channel=await self.resolve_peer(chat_id), + topic_id=1, + hidden=False + ) + ) + return True