mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-04 12:10:21 +03:00
squash em
This commit is contained in:
parent
a424b0c6b7
commit
2a933b0714
|
@ -3,7 +3,6 @@ import itertools
|
||||||
import string
|
import string
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .users import UserMethods
|
|
||||||
from .. import helpers, utils, hints
|
from .. import helpers, utils, hints
|
||||||
from ..requestiter import RequestIter
|
from ..requestiter import RequestIter
|
||||||
from ..tl import types, functions, custom
|
from ..tl import types, functions, custom
|
||||||
|
@ -345,7 +344,7 @@ class _ProfilePhotoIter(RequestIter):
|
||||||
self.request.offset_id = result.messages[-1].id
|
self.request.offset_id = result.messages[-1].id
|
||||||
|
|
||||||
|
|
||||||
class ChatMethods(UserMethods):
|
class ChatMethods:
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
|
@ -762,219 +761,4 @@ class ChatMethods(UserMethods):
|
||||||
return _ChatAction(
|
return _ChatAction(
|
||||||
self, entity, action, delay=delay, auto_cancel=auto_cancel)
|
self, entity, action, delay=delay, auto_cancel=auto_cancel)
|
||||||
|
|
||||||
async def edit_admin(
|
|
||||||
self: 'TelegramClient',
|
|
||||||
entity: 'hints.EntityLike',
|
|
||||||
user: 'hints.EntityLike',
|
|
||||||
*,
|
|
||||||
change_info: bool = None,
|
|
||||||
post_messages: bool = None,
|
|
||||||
edit_messages: bool = None,
|
|
||||||
delete_messages: bool = None,
|
|
||||||
ban_users: bool = None,
|
|
||||||
invite_users: bool = None,
|
|
||||||
pin_messages: bool = None,
|
|
||||||
add_admins: bool = None,
|
|
||||||
is_admin: bool = None) -> types.Updates:
|
|
||||||
"""
|
|
||||||
Edits admin permissions for someone in a chat.
|
|
||||||
|
|
||||||
Raises an error if wrong a combination of rights are given
|
|
||||||
(e.g. you don't have enough permissions to grant one).
|
|
||||||
|
|
||||||
Unless otherwise stated, permissions will work in channels and megagroups.
|
|
||||||
|
|
||||||
Arguments
|
|
||||||
entity (`entity`):
|
|
||||||
The channel, megagroup or chat where the promotion should happen.
|
|
||||||
|
|
||||||
user (`entity`):
|
|
||||||
The user to be promoted.
|
|
||||||
|
|
||||||
change_info (`bool`, optional):
|
|
||||||
Whether the user will be able to change info.
|
|
||||||
|
|
||||||
post_messages (`bool`, optional):
|
|
||||||
Whether the user will be able to post in the channel.
|
|
||||||
This will only work in broadcast channels.
|
|
||||||
|
|
||||||
edit_messages (`bool`, optional):
|
|
||||||
Whether the user will be able to edit messages in the channel.
|
|
||||||
This will only work in broadcast channels.
|
|
||||||
|
|
||||||
delete_messages (`bool`, optional):
|
|
||||||
Whether the user will be able to delete messages.
|
|
||||||
|
|
||||||
ban_users (`bool`, optional):
|
|
||||||
Whether the user will be able to ban users.
|
|
||||||
|
|
||||||
invite_users (`bool`, optional):
|
|
||||||
Whether the user will be able to invite users. Needs some testing.
|
|
||||||
|
|
||||||
pin_messages (`bool`, optional):
|
|
||||||
Whether the user will be able to pin messages.
|
|
||||||
|
|
||||||
add_admins (`bool`, optional):
|
|
||||||
Whether the user will be able to add admins.
|
|
||||||
|
|
||||||
is_admin (`bool`, optional):
|
|
||||||
Whether the user will be an admin in the chat.
|
|
||||||
This will only work in small group chats.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
The resulting :tl:`Updates` object.
|
|
||||||
|
|
||||||
Example
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
# Allowing `user` to pin messages in `chat`
|
|
||||||
client.edit_admin(chat, user, pin_messages=True)
|
|
||||||
"""
|
|
||||||
entity = await self.get_input_entity(entity)
|
|
||||||
user = await self.get_input_entity(user)
|
|
||||||
if not isinstance(user, types.InputPeerUser):
|
|
||||||
raise ValueError('You must pass a user entity')
|
|
||||||
|
|
||||||
if isinstance(entity, types.InputPeerChannel):
|
|
||||||
return await self(functions.channels.EditAdminRequest(
|
|
||||||
entity,
|
|
||||||
user,
|
|
||||||
types.ChatAdminRights(
|
|
||||||
change_info=change_info,
|
|
||||||
post_messages=post_messages,
|
|
||||||
edit_messages=edit_messages,
|
|
||||||
delete_messages=delete_messages,
|
|
||||||
ban_users=ban_users,
|
|
||||||
invite_users=invite_users,
|
|
||||||
pin_messages=pin_messages,
|
|
||||||
add_admins=add_admins
|
|
||||||
)
|
|
||||||
))
|
|
||||||
elif isinstance(entity, types.InputPeerChat):
|
|
||||||
return await self(functions.messages.EditChatAdminRequest(entity, user, is_admin=is_admin))
|
|
||||||
else:
|
|
||||||
raise ValueError('You must pass either a channel or a supergroup or a normal group')
|
|
||||||
|
|
||||||
async def edit_restriction(
|
|
||||||
self: 'TelegramClient',
|
|
||||||
entity: 'hints.EntityLike',
|
|
||||||
user: 'typing.Optional[hints.EntityLike]' = None,
|
|
||||||
until_date: 'hints.DateLike' = None,
|
|
||||||
*,
|
|
||||||
view_messages: bool = True,
|
|
||||||
send_messages: bool = True,
|
|
||||||
send_media: bool = True,
|
|
||||||
send_stickers: bool = True,
|
|
||||||
send_gifs: bool = True,
|
|
||||||
send_games: bool = True,
|
|
||||||
send_inline: bool = True,
|
|
||||||
send_polls: bool = True,
|
|
||||||
change_info: bool = True,
|
|
||||||
invite_users: bool = True,
|
|
||||||
pin_messages: bool = True) -> types.Updates:
|
|
||||||
"""
|
|
||||||
Edits user restrictions in a chat.
|
|
||||||
|
|
||||||
Raises an error if wrong a combination of rights are given
|
|
||||||
(e.g. you don't have enough permissions to revoke one).
|
|
||||||
|
|
||||||
Arguments
|
|
||||||
entity (`entity`):
|
|
||||||
The channel or megagroup where the restriction should happen.
|
|
||||||
|
|
||||||
user (`entity`, optional):
|
|
||||||
If specified, the permission will be changed for the specific user.
|
|
||||||
If left as ``None``, the default chat permissions will be updated.
|
|
||||||
|
|
||||||
until_date (`DateLike`, optional):
|
|
||||||
When the user will be unbanned.
|
|
||||||
|
|
||||||
If the due date or duration is longer than 366 days or shorter than
|
|
||||||
30 seconds, the ban will be forever. Defaults to ``0`` (ban forever).
|
|
||||||
|
|
||||||
view_messages (`bool`, optional):
|
|
||||||
Whether the user is able to view messages or not.
|
|
||||||
Forbidding someone from viewing messages equals to banning them.
|
|
||||||
This will only work if ``user`` is set.
|
|
||||||
|
|
||||||
send_messages (`bool`, optional):
|
|
||||||
Whether the user is able to send messages or not.
|
|
||||||
|
|
||||||
send_media (`bool`, optional):
|
|
||||||
Whether the user is able to send media or not.
|
|
||||||
|
|
||||||
send_stickers (`bool`, optional):
|
|
||||||
Whether the user is able to send stickers or not.
|
|
||||||
|
|
||||||
send_gifs (`bool`, optional):
|
|
||||||
Whether the user is able to send animated gifs or not.
|
|
||||||
|
|
||||||
send_games (`bool`, optional):
|
|
||||||
Whether the user is able to send games or not.
|
|
||||||
|
|
||||||
send_inline (`bool`, optional):
|
|
||||||
Whether the user is able to use inline bots or not.
|
|
||||||
|
|
||||||
send_polls (`bool`, optional):
|
|
||||||
Whether the user is able to send polls or not.
|
|
||||||
|
|
||||||
change_info (`bool`, optional):
|
|
||||||
Whether the user is able to change info or not.
|
|
||||||
|
|
||||||
invite_users (`bool`, optional):
|
|
||||||
Whether the user is able to invite other users or not.
|
|
||||||
|
|
||||||
pin_messages (`bool`, optional):
|
|
||||||
Whether the user is able to pin messages or not.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
The resulting :tl:`Updates` object.
|
|
||||||
|
|
||||||
Example
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
# Kicking `user` from `chat` for 1 minute
|
|
||||||
client.edit_permission(chat, user, timedelta(minutes=1),
|
|
||||||
view_messages=False)
|
|
||||||
|
|
||||||
# Banning `user` from `chat` forever
|
|
||||||
client.edit_permission(chat, user, view_messages=False)
|
|
||||||
"""
|
|
||||||
entity = await self.get_input_entity(entity)
|
|
||||||
if not isinstance(entity,types.InputPeerChannel):
|
|
||||||
raise ValueError('You must pass either a channel or a supergroup')
|
|
||||||
|
|
||||||
rights = types.ChatBannedRights(
|
|
||||||
until_date=until_date,
|
|
||||||
view_messages=not view_messages,
|
|
||||||
send_messages=not send_messages,
|
|
||||||
send_media=not send_media,
|
|
||||||
send_stickers=not send_stickers,
|
|
||||||
send_gifs=not send_gifs,
|
|
||||||
send_games=not send_games,
|
|
||||||
send_inline=not send_inline,
|
|
||||||
send_polls=not send_polls,
|
|
||||||
change_info=not change_info,
|
|
||||||
invite_users=not invite_users,
|
|
||||||
pin_messages=not pin_messages
|
|
||||||
)
|
|
||||||
|
|
||||||
if user is None:
|
|
||||||
return await self(functions.messages.EditChatDefaultBannedRightsRequest(
|
|
||||||
peer=entity,
|
|
||||||
banned_rights=rights
|
|
||||||
))
|
|
||||||
|
|
||||||
user = await self.get_input_entity(user)
|
|
||||||
if not isinstance(user, types.InputPeerUser):
|
|
||||||
raise ValueError('You must pass a user entity')
|
|
||||||
|
|
||||||
return await self(functions.channels.EditBannedRequest(
|
|
||||||
channel=entity,
|
|
||||||
user_id=user,
|
|
||||||
banned_rights=rights
|
|
||||||
))
|
|
||||||
|
|
||||||
# endregion
|
# endregion
|
Loading…
Reference in New Issue
Block a user