Example #1
0
async def _on_raw(_, m: BaseMessage, *__) -> None:
    if isinstance(m, UpdateGroupCallParticipants):
        # TODO: chat_id
        for participant in m.participants:
            if participant.is_self:
                group_call = await userge.send(
                    GetGroupCall(call=InputGroupCall(
                        access_hash=m.call.access_hash, id=m.call.id),
                                 limit=1))
                if participant.just_joined:
                    await _on_join(group_call.call)
                elif participant.left:
                    await _on_left(group_call.call)
                break
    raise ContinuePropagation
Example #2
0
 async def on_close(client, update, _, data2):
     if isinstance(update, UpdateGroupCall):
         if isinstance(update.call, GroupCallDiscarded):
             chat_id = int(f'-100{update.chat_id}')
             self._cache_full_chat[chat_id] = {
                 'last_update': int(time()),
                 'full_chat': None,
             }
         if isinstance(update.call, GroupCall):
             input_group_call = InputGroupCall(
                 access_hash=update.call.access_hash,
                 id=update.call.id,
             )
             chat_id = int(f'-100{update.chat_id}')
             self._cache_full_chat[chat_id] = {
                 'last_update': int(time()),
                 'full_chat': input_group_call,
             }
     if isinstance(update, UpdateChannel):
         chat_id = int(f'-100{update.channel_id}')
         if len(data2) > 0:
             if isinstance(
                     data2[update.channel_id],
                     ChannelForbidden,
             ):
                 for event in self._on_event_update[
                         'KICK_HANDLER']:
                     await event['callable'](chat_id, )
                 # noinspection PyBroadException
                 try:
                     self.leave_group_call(
                         chat_id,
                         'kicked_from_group',
                     )
                 except Exception:
                     pass
                 try:
                     del self._cache_user_peer[chat_id]
                 except Exception:
                     pass
     if isinstance(
             update,
             UpdateGroupCall,
     ):
         if isinstance(
                 update.call,
                 GroupCallDiscarded,
         ):
             chat_id = int(f'-100{update.chat_id}')
             for event in self._on_event_update[
                     'CLOSED_HANDLER']:
                 await event['callable'](chat_id, )
             # noinspection PyBroadException
             try:
                 self.leave_group_call(
                     chat_id,
                     'closed_voice_chat',
                 )
             except Exception:
                 pass
             try:
                 del self._cache_user_peer[chat_id]
             except Exception:
                 pass
     if isinstance(
             update,
             UpdateNewChannelMessage,
     ):
         try:
             if isinstance(
                     update.message.action,
                     MessageActionInviteToGroupCall,
             ):
                 for event in self._on_event_update[
                         'GROUP_CALL_HANDLER']:
                     await event['callable'](
                         client,
                         update.message,
                     )
         except Exception:
             pass
Example #3
0
 async def set_title(self, title):
     call = InputGroupCall(
         id=self.group_call.group_call.id,
         access_hash=self.group_call.group_call.access_hash)
     raw_fun = EditGroupCallTitle(call=call, title=title)
     await self.group_call.client.send(raw_fun)
Example #4
0
 async def on_update(_, update, __, data2):
     if isinstance(
             update,
             UpdateGroupCallParticipants,
     ):
         participants = update.participants
         for participant in participants:
             result = self._cache.set_participants_cache(
                 update.call.id,
                 self.chat_id(participant.peer),
                 participant.muted,
                 participant.volume,
                 participant.can_self_unmute,
                 participant.video is not None
                 or participant.presentation is not None,
                 participant.presentation is not None,
                 participant.video is not None,
                 participant.raise_hand_rating,
                 participant.left,
             )
             if result is not None:
                 if 'PARTICIPANTS_HANDLER' in self._handler:
                     await self._handler['PARTICIPANTS_HANDLER'](
                         self._cache.get_chat_id(update.call.id),
                         result,
                         participant.just_joined,
                         participant.left,
                     )
     if isinstance(
             update,
             UpdateGroupCall,
     ):
         chat_id = self.chat_id(data2[update.chat_id])
         if isinstance(
                 update.call,
                 GroupCall,
         ):
             if update.call.schedule_date is None:
                 self._cache.set_cache(
                     chat_id,
                     InputGroupCall(
                         access_hash=update.call.access_hash,
                         id=update.call.id,
                     ),
                 )
         if isinstance(
                 update.call,
                 GroupCallDiscarded,
         ):
             self._cache.drop_cache(chat_id)
             if 'CLOSED_HANDLER' in self._handler:
                 await self._handler['CLOSED_HANDLER'](chat_id, )
     if isinstance(
             update,
             UpdateChannel,
     ):
         chat_id = self.chat_id(update)
         if len(data2) > 0:
             if isinstance(
                     data2[update.channel_id],
                     ChannelForbidden,
             ):
                 self._cache.drop_cache(chat_id)
                 if 'KICK_HANDLER' in self._handler:
                     await self._handler['KICK_HANDLER'](chat_id, )
     if isinstance(
             update,
             UpdateNewChannelMessage,
     ) or isinstance(
             update,
             UpdateNewMessage,
     ):
         if isinstance(
                 update.message,
                 MessageService,
         ):
             if isinstance(
                     update.message.action,
                     MessageActionInviteToGroupCall,
             ):
                 if 'INVITE_HANDLER' in self._handler:
                     await self._handler['INVITE_HANDLER'](
                         update.message.action, )
             if isinstance(
                     update.message.action,
                     MessageActionChatDeleteUser,
             ):
                 if isinstance(
                         update.message.peer_id,
                         PeerChat,
                 ):
                     chat_id = self.chat_id(update.message.peer_id)
                     if isinstance(
                             data2[update.message.peer_id.chat_id],
                             ChatForbidden,
                     ):
                         self._cache.drop_cache(chat_id)
                         if 'KICK_HANDLER' in self._handler:
                             await self._handler['KICK_HANDLER'](
                                 chat_id, )
     if isinstance(
             data2,
             Dict,
     ):
         for group_id in data2:
             if isinstance(
                     update,
                     UpdateNewChannelMessage,
             ) or isinstance(
                     update,
                     UpdateNewMessage,
             ):
                 if isinstance(
                         update.message,
                         MessageService,
                 ):
                     if isinstance(
                             data2[group_id],
                             Channel,
                     ) or isinstance(
                             data2[group_id],
                             Chat,
                     ):
                         chat_id = self.chat_id(data2[group_id])
                         if data2[group_id].left:
                             self._cache.drop_cache(chat_id, )
                             if 'LEFT_HANDLER' in self._handler:
                                 await self._handler['LEFT_HANDLER'](
                                     chat_id, )
     raise ContinuePropagation()