Skip to content

Commit

Permalink
Update to layer 122
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Dec 11, 2020
1 parent 1cd1139 commit 0a4d54f
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 12 deletions.
23 changes: 17 additions & 6 deletions telethon/client/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,17 @@ class _AdminLogIter(RequestIter):
async def _init(
self, entity, admins, search, min_id, max_id,
join, leave, invite, restrict, unrestrict, ban, unban,
promote, demote, info, settings, pinned, edit, delete
promote, demote, info, settings, pinned, edit, delete,
group_call
):
if any((join, leave, invite, restrict, unrestrict, ban, unban,
promote, demote, info, settings, pinned, edit, delete)):
promote, demote, info, settings, pinned, edit, delete,
group_call)):
events_filter = types.ChannelAdminLogEventsFilter(
join=join, leave=leave, invite=invite, ban=restrict,
unban=unrestrict, kick=ban, unkick=unban, promote=promote,
demote=demote, info=info, settings=settings, pinned=pinned,
edit=edit, delete=delete
edit=edit, delete=delete, group_call=group_call
)
else:
events_filter = None
Expand Down Expand Up @@ -495,7 +497,8 @@ def iter_admin_log(
settings: bool = None,
pinned: bool = None,
edit: bool = None,
delete: bool = None) -> _AdminLogIter:
delete: bool = None,
group_call: bool = None) -> _AdminLogIter:
"""
Iterator over the admin log for the specified channel.
Expand Down Expand Up @@ -582,6 +585,9 @@ def iter_admin_log(
delete (`bool`):
If `True`, events of message deletions will be returned.
group_call (`bool`):
If `True`, events related to group calls will be returned.
Yields
Instances of `AdminLogEvent <telethon.tl.custom.adminlogevent.AdminLogEvent>`.
Expand Down Expand Up @@ -613,7 +619,8 @@ def iter_admin_log(
settings=settings,
pinned=pinned,
edit=edit,
delete=delete
delete=delete,
group_call=group_call
)

async def get_admin_log(
Expand Down Expand Up @@ -811,6 +818,7 @@ async def edit_admin(
invite_users: bool = None,
pin_messages: bool = None,
add_admins: bool = None,
manage_call: bool = True,
anonymous: bool = None,
is_admin: bool = None,
title: str = None) -> types.Updates:
Expand Down Expand Up @@ -855,6 +863,9 @@ async def edit_admin(
add_admins (`bool`, optional):
Whether the user will be able to add admins.
manage_call (`bool`, optional):
Whether the user will be able to manage group calls.
anonymous (`bool`, optional):
Whether the user will remain anonymous when sending messages.
The sender of the anonymous messages becomes the group itself.
Expand Down Expand Up @@ -907,7 +918,7 @@ async def edit_admin(
perm_names = (
'change_info', 'post_messages', 'edit_messages', 'delete_messages',
'ban_users', 'invite_users', 'pin_messages', 'add_admins',
'anonymous',
'anonymous', 'manage_call',
)

ty = helpers._entity_type(entity)
Expand Down
61 changes: 61 additions & 0 deletions telethon/tl/custom/adminlogevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def old(self):
return ori.message
elif isinstance(ori, types.ChannelAdminLogEventActionDefaultBannedRights):
return ori.prev_banned_rights
elif isinstance(ori, types.ChannelAdminLogEventActionDiscardGroupCall):
return ori.call

@property
def new(self):
Expand Down Expand Up @@ -125,6 +127,15 @@ def new(self):
return ori.new_banned_rights
elif isinstance(ori, types.ChannelAdminLogEventActionStopPoll):
return ori.message
elif isinstance(ori, types.ChannelAdminLogEventActionStartGroupCall):
return ori.call
elif isinstance(ori, (
types.ChannelAdminLogEventActionParticipantMute,
types.ChannelAdminLogEventActionParticipantUnmute,
)):
return ori.participant
elif isinstance(ori, types.ChannelAdminLogEventActionToggleGroupCallSetting):
return ori.join_muted

@property
def changed_about(self):
Expand Down Expand Up @@ -327,6 +338,56 @@ def stopped_poll(self):
return isinstance(self.original.action,
types.ChannelAdminLogEventActionStopPoll)

@property
def started_group_call(self):
"""
Whether a group call was started or not.
If `True`, `new` will be present as :tl:`InputGroupCall`.
"""
return isinstance(self.original.action,
types.ChannelAdminLogEventActionStartGroupCall)

@property
def discarded_group_call(self):
"""
Whether a group call was started or not.
If `True`, `old` will be present as :tl:`InputGroupCall`.
"""
return isinstance(self.original.action,
types.ChannelAdminLogEventActionDiscardGroupCall)

@property
def user_muted(self):
"""
Whether a participant was muted in the ongoing group call or not.
If `True`, `new` will be present as :tl:`GroupCallParticipant`.
"""
return isinstance(self.original.action,
types.ChannelAdminLogEventActionParticipantMute)

@property
def user_unmutted(self):
"""
Whether a participant was unmuted from the ongoing group call or not.
If `True`, `new` will be present as :tl:`GroupCallParticipant`.
"""
return isinstance(self.original.action,
types.ChannelAdminLogEventActionParticipantUnmute)

@property
def changed_call_settings(self):
"""
Whether the group call settings were changed or not.
If `True`, `new` will be `True` if new users are muted on join.
"""
return isinstance(self.original.action,
types.ChannelAdminLogEventActionToggleGroupCallSetting)

def __str__(self):
return str(self.original)

Expand Down
11 changes: 11 additions & 0 deletions telethon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,17 @@ def get_input_message(message):
_raise_cast_fail(message, 'InputMedia')


def get_input_group_call(call):
"""Similar to :meth:`get_input_peer`, but for input calls."""
try:
if call.SUBCLASS_OF_ID == 0x58611ab1: # crc32(b'InputGroupCall')
return call
elif call.SUBCLASS_OF_ID == 0x20b4f320: # crc32(b'GroupCall')
return types.InputGroupCall(id=call.id, access_hash=call.access_hash)
except AttributeError:
_raise_cast_fail(call, 'InputGroupCall')


def _get_entity_pair(entity_id, entities, cache,
get_input_peer=get_input_peer):
"""
Expand Down
Loading

0 comments on commit 0a4d54f

Please sign in to comment.