コード例 #1
0
 def on_message(self, callback):
     for update in self.internal.updates.SeqUpdates(empty_pb2.Empty()):
         up = sequence_and_updates_pb2.UpdateSeqUpdate()
         up.ParseFromString(update.update.value)
         print(up.WhichOneof('update'), up.update_header)
         if up.update_header == 55:
             #up.WhichOneof('update')
             callback(up.updateMessage)
コード例 #2
0
def bot2_seq_handler():
    global downloaded
    for update in bot2.updates.SeqUpdates(empty_pb2.Empty()):
        up = sequence_and_updates_pb2.UpdateSeqUpdate()
        up.ParseFromString(update.update.value)
        if up.updateMessage.message.documentMessage.file_id != 0:
            file_id = up.updateMessage.message.documentMessage.file_id
            access_hash = up.updateMessage.message.documentMessage.access_hash
            bot2.download_file(file_id, access_hash)
            downloaded = True
            break
コード例 #3
0
    def on_message(self, callback):
        """Message receiving event handler.

        :param callback: function that will be called when message received
        :return: None
        """

        for update in self.internal.updates.SeqUpdates(empty_pb2.Empty()):
            up = sequence_and_updates_pb2.UpdateSeqUpdate()
            up.ParseFromString(update.update.value)
            if up.WhichOneof('update') == 'updateMessage':
                self.internal.thread_pool_executor.submit(
                    callback(up.updateMessage))
コード例 #4
0
 def __on_message_schedule(self,
                           callback,
                           interactive_media_callback=None,
                           raw_callback=None):
     try:
         self.internal.updates.GetState(
             sequence_and_updates_pb2.RequestGetState())
         if self.retry:
             logging.info("Server was unavailable {} seconds.".format(
                 int(self.timer)))
             self.timer = 0
             self.retry = 0
     except grpc.RpcError as e:
         raise e
     for update in self.internal.updates.SeqUpdates(empty_pb2.Empty()):
         up = sequence_and_updates_pb2.UpdateSeqUpdate()
         up.ParseFromString(update.update.value)
         if up.WhichOneof('update') == 'updateMessage':
             self.internal.messaging.MessageReceived(
                 messaging_pb2.RequestMessageReceived(
                     peer=self.manager.get_out_peer(up.updateMessage.peer),
                     date=up.updateMessage.date))
             self.internal.messaging.MessageRead(
                 messaging_pb2.RequestMessageRead(
                     peer=self.manager.get_out_peer(up.updateMessage.peer),
                     date=up.updateMessage.date))
             POOL.submit(callback(UpdateMessage.from_api(up.updateMessage)))
         elif up.WhichOneof('update') == 'updateInteractiveMediaEvent' and \
                 callable(interactive_media_callback):
             POOL.submit(
                 interactive_media_callback(
                     UpdateInteractiveMediaEvent.from_api(
                         up.updateInteractiveMediaEvent)))
         else:
             if callable(raw_callback):
                 POOL.submit(raw_callback(up))
コード例 #5
0
 def seq_update_handler(self):
     for update in self.updates.SeqUpdates(empty_pb2.Empty()):
         up = sequence_and_updates_pb2.UpdateSeqUpdate()
         up.ParseFromString(update.update.value)
         self.seq_update_queue.put(up)
         break