Add new methods: add_chat_members, create_* and delete_* chats
- add_chat_members - create_group - create_channel - create_supergroup - delete_channel - delete_supergroup
This commit is contained in:
parent
184f851625
commit
036a73997a
@ -204,6 +204,12 @@ def pyrogram_api():
|
|||||||
update_chat_username
|
update_chat_username
|
||||||
archive_chats
|
archive_chats
|
||||||
unarchive_chats
|
unarchive_chats
|
||||||
|
add_chat_members
|
||||||
|
create_channel
|
||||||
|
create_group
|
||||||
|
create_supergroup
|
||||||
|
delete_channel
|
||||||
|
delete_supergroup
|
||||||
""",
|
""",
|
||||||
users="""
|
users="""
|
||||||
Users
|
Users
|
||||||
|
@ -16,8 +16,14 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from .add_chat_members import AddChatMembers
|
||||||
from .archive_chats import ArchiveChats
|
from .archive_chats import ArchiveChats
|
||||||
|
from .create_channel import CreateChannel
|
||||||
|
from .create_group import CreateGroup
|
||||||
|
from .create_supergroup import CreateSupergroup
|
||||||
|
from .delete_channel import DeleteChannel
|
||||||
from .delete_chat_photo import DeleteChatPhoto
|
from .delete_chat_photo import DeleteChatPhoto
|
||||||
|
from .delete_supergroup import DeleteSupergroup
|
||||||
from .export_chat_invite_link import ExportChatInviteLink
|
from .export_chat_invite_link import ExportChatInviteLink
|
||||||
from .get_chat import GetChat
|
from .get_chat import GetChat
|
||||||
from .get_chat_member import GetChatMember
|
from .get_chat_member import GetChatMember
|
||||||
@ -68,6 +74,12 @@ class Chats(
|
|||||||
RestrictChat,
|
RestrictChat,
|
||||||
GetDialogsCount,
|
GetDialogsCount,
|
||||||
ArchiveChats,
|
ArchiveChats,
|
||||||
UnarchiveChats
|
UnarchiveChats,
|
||||||
|
CreateGroup,
|
||||||
|
CreateSupergroup,
|
||||||
|
CreateChannel,
|
||||||
|
AddChatMembers,
|
||||||
|
DeleteChannel,
|
||||||
|
DeleteSupergroup
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
76
pyrogram/client/methods/chats/add_chat_members.py
Normal file
76
pyrogram/client/methods/chats/add_chat_members.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2019 Dan Tès <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 typing import Union, List
|
||||||
|
|
||||||
|
from pyrogram.api import functions, types
|
||||||
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class AddChatMembers(BaseClient):
|
||||||
|
def add_chat_members(
|
||||||
|
self,
|
||||||
|
chat_id: Union[int, str],
|
||||||
|
user_ids: Union[Union[int, str], List[Union[int, str]]],
|
||||||
|
forward_limit: int = 100
|
||||||
|
) -> bool:
|
||||||
|
"""Add new chat members to a group, supergroup or channel
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
chat_id (``int`` | ``str``):
|
||||||
|
The group, supergroup or channel id
|
||||||
|
|
||||||
|
user_ids (``int`` | ``str`` | List of ``int`` or ``str``):
|
||||||
|
Users to add in the chat
|
||||||
|
You can pass an ID (int), username (str) or phone number (str).
|
||||||
|
Multiple users can be added by passing a list of IDs, usernames or phone numbers.
|
||||||
|
|
||||||
|
forward_limit (``int``, *optional*):
|
||||||
|
How many of the latest messages you want to forward to the new members. Pass 0 to forward none of them.
|
||||||
|
Only applicable to basic groups (the argument is ignored for supergroups or channels).
|
||||||
|
Defaults to 100 (max amount).
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: On success, True is returned.
|
||||||
|
"""
|
||||||
|
peer = self.resolve_peer(chat_id)
|
||||||
|
|
||||||
|
if not isinstance(user_ids, list):
|
||||||
|
user_ids = [user_ids]
|
||||||
|
|
||||||
|
if isinstance(peer, types.InputPeerChat):
|
||||||
|
for user_id in user_ids:
|
||||||
|
self.send(
|
||||||
|
functions.messages.AddChatUser(
|
||||||
|
chat_id=peer.chat_id,
|
||||||
|
user_id=self.resolve_peer(user_id),
|
||||||
|
fwd_limit=forward_limit
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.send(
|
||||||
|
functions.channels.InviteToChannel(
|
||||||
|
channel=peer,
|
||||||
|
users=[
|
||||||
|
self.resolve_peer(user_id)
|
||||||
|
for user_id in user_ids
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
50
pyrogram/client/methods/chats/create_channel.py
Normal file
50
pyrogram/client/methods/chats/create_channel.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2019 Dan Tès <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 pyrogram
|
||||||
|
from pyrogram.api import functions
|
||||||
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class CreateChannel(BaseClient):
|
||||||
|
def create_channel(
|
||||||
|
self,
|
||||||
|
title: str,
|
||||||
|
description: str = ""
|
||||||
|
) -> "pyrogram.Chat":
|
||||||
|
"""Create a new broadcast channel.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
title (``title``):
|
||||||
|
The channel title.
|
||||||
|
|
||||||
|
description (``str``, *optional*):
|
||||||
|
The channel description.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
:obj:`Chat`: On success, a chat object is returned.
|
||||||
|
"""
|
||||||
|
r = self.send(
|
||||||
|
functions.channels.CreateChannel(
|
||||||
|
title=title,
|
||||||
|
about=description,
|
||||||
|
broadcast=True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return pyrogram.Chat._parse_chat(self, r.chats[0])
|
60
pyrogram/client/methods/chats/create_group.py
Normal file
60
pyrogram/client/methods/chats/create_group.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2019 Dan Tès <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 typing import Union, List
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram.api import functions
|
||||||
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class CreateGroup(BaseClient):
|
||||||
|
def create_group(
|
||||||
|
self,
|
||||||
|
title: str,
|
||||||
|
users: Union[Union[int, str], List[Union[int, str]]]
|
||||||
|
) -> "pyrogram.Chat":
|
||||||
|
"""Create a new basic group.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
If you want to create a new supergroup, use :meth:`~pyrogram.Client.create_supergroup` instead.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
title (``title``):
|
||||||
|
The group title.
|
||||||
|
|
||||||
|
users (``int`` | ``str`` | List of ``int`` or ``str``):
|
||||||
|
Users to create a chat with.
|
||||||
|
You must pass at least one user using their IDs (int), usernames (str) or phone numbers (str).
|
||||||
|
Multiple users can be invited by passing a list of IDs, usernames or phone numbers.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
:obj:`Chat`: On success, a chat object is returned.
|
||||||
|
"""
|
||||||
|
if not isinstance(users, list):
|
||||||
|
users = [users]
|
||||||
|
|
||||||
|
r = self.send(
|
||||||
|
functions.messages.CreateChat(
|
||||||
|
title=title,
|
||||||
|
users=[self.resolve_peer(u) for u in users]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return pyrogram.Chat._parse_chat(self, r.chats[0])
|
54
pyrogram/client/methods/chats/create_supergroup.py
Normal file
54
pyrogram/client/methods/chats/create_supergroup.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2019 Dan Tès <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 pyrogram
|
||||||
|
from pyrogram.api import functions
|
||||||
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class CreateSupergroup(BaseClient):
|
||||||
|
def create_supergroup(
|
||||||
|
self,
|
||||||
|
title: str,
|
||||||
|
description: str = ""
|
||||||
|
) -> "pyrogram.Chat":
|
||||||
|
"""Create a new supergroup.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
If you want to create a new basic group, use :meth:`~pyrogram.Client.create_group` instead.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
title (``title``):
|
||||||
|
The supergroup title.
|
||||||
|
|
||||||
|
description (``str``, *optional*):
|
||||||
|
The supergroup description.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
:obj:`Chat`: On success, a chat object is returned.
|
||||||
|
"""
|
||||||
|
r = self.send(
|
||||||
|
functions.channels.CreateChannel(
|
||||||
|
title=title,
|
||||||
|
about=description,
|
||||||
|
megagroup=True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return pyrogram.Chat._parse_chat(self, r.chats[0])
|
43
pyrogram/client/methods/chats/delete_channel.py
Normal file
43
pyrogram/client/methods/chats/delete_channel.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2019 Dan Tès <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 typing import Union
|
||||||
|
|
||||||
|
from pyrogram.api import functions
|
||||||
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteChannel(BaseClient):
|
||||||
|
def delete_channel(self, chat_id: Union[int, str]) -> bool:
|
||||||
|
"""Delete a channel.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
chat_id (``int`` | ``str``):
|
||||||
|
The id of the channel to be deleted.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: On success, True is returned.
|
||||||
|
"""
|
||||||
|
self.send(
|
||||||
|
functions.channels.DeleteChannel(
|
||||||
|
channel=self.resolve_peer(chat_id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
43
pyrogram/client/methods/chats/delete_supergroup.py
Normal file
43
pyrogram/client/methods/chats/delete_supergroup.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2019 Dan Tès <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 typing import Union
|
||||||
|
|
||||||
|
from pyrogram.api import functions
|
||||||
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteSupergroup(BaseClient):
|
||||||
|
def delete_supergroup(self, chat_id: Union[int, str]) -> bool:
|
||||||
|
"""Delete a supergroup.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
chat_id (``int`` | ``str``):
|
||||||
|
The id of the supergroup to be deleted.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
``bool``: On success, True is returned.
|
||||||
|
"""
|
||||||
|
self.send(
|
||||||
|
functions.channels.DeleteChannel(
|
||||||
|
channel=self.resolve_peer(chat_id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
Loading…
Reference in New Issue
Block a user