示例#1
0
    def update_worker(self):
        name = threading.current_thread().name
        log.debug("{} started".format(name))

        while True:
            update = self.updates.get()

            if update is None:
                break

            try:
                users = {i.id: i for i in update[1]}
                chats = {i.id: i for i in update[2]}
                update = update[0]

                self.dispatch(update, users=users, chats=chats, is_raw=True)

                if isinstance(update, Dispatcher.MESSAGE_UPDATES):
                    if isinstance(update.message, types.MessageEmpty):
                        continue

                    message = utils.parse_messages(
                        self.client,
                        update.message,
                        users,
                        chats
                    )

                    is_edited_message = isinstance(update, Dispatcher.EDIT_MESSAGE_UPDATES)

                    self.dispatch(
                        pyrogram.Update(
                            message=((message if message.chat.type != "channel"
                                      else None) if not is_edited_message
                                     else None),
                            edited_message=((message if message.chat.type != "channel"
                                             else None) if is_edited_message
                                            else None),
                            channel_post=((message if message.chat.type == "channel"
                                           else None) if not is_edited_message
                                          else None),
                            edited_channel_post=((message if message.chat.type == "channel"
                                                  else None) if is_edited_message
                                                 else None)
                        )
                    )
                elif isinstance(update, types.UpdateBotCallbackQuery):
                    self.dispatch(
                        pyrogram.Update(
                            callback_query=utils.parse_callback_query(
                                self.client, update, users
                            )
                        )
                    )
                else:
                    continue
            except Exception as e:
                log.error(e, exc_info=True)

        log.debug("{} stopped".format(name))
示例#2
0
    def update_worker(self):
        name = threading.current_thread().name
        log.debug("{} started".format(name))

        while True:
            update = self.updates.get()

            if update is None:
                break

            try:
                users = {i.id: i for i in update[1]}
                chats = {i.id: i for i in update[2]}
                update = update[0]

                self.dispatch(update, users=users, chats=chats, is_raw=True)

                if isinstance(update, Dispatcher.ALLOWED_UPDATES):
                    if isinstance(update.message, types.Message):
                        parser = message_parser.parse_message
                    elif isinstance(update.message, types.MessageService):
                        parser = message_parser.parse_message_service
                    else:
                        continue

                    message = parser(self.client, update.message, users, chats)
                else:
                    continue

                is_edited_message = isinstance(update, Dispatcher.EDIT_UPDATES)

                self.dispatch(
                    pyrogram.Update(
                        update_id=0,
                        message=((message
                                  if message.chat.type != "channel" else None)
                                 if not is_edited_message else None),
                        edited_message=(
                            (message if message.chat.type != "channel" else
                             None) if is_edited_message else None),
                        channel_post=((message if message.chat.type
                                       == "channel" else None)
                                      if not is_edited_message else None),
                        edited_channel_post=((message if message.chat.type
                                              == "channel" else None)
                                             if is_edited_message else None)))
            except Exception as e:
                log.error(e, exc_info=True)

        log.debug("{} stopped".format(name))