Ejemplo n.º 1
0
 def append(self, *others):
     for other in others:
         if not other:
             continue
         if isinstance(other, Frag) or \
            type(other) == type(()) or \
            type(other) == type([]):
             List.extend(self, other)
         else:
             List.append(self, other)
Ejemplo n.º 2
0
Archivo: Util.py Proyecto: billynip/map
 def extend(self, other):
     UserList.extend(self, other)
     self.unique = False
Ejemplo n.º 3
0
 def extend(self, other):
     UserList.extend(self, other)
     self.unique = False
Ejemplo n.º 4
0
	def extend(self, other):
		UserList.extend(self, other)
		self._changed()
Ejemplo n.º 5
0
    def get_message_history(self,
                            entity,
                            limit=20,
                            offset_date=None,
                            offset_id=0,
                            max_id=0,
                            min_id=0,
                            add_offset=0):
        """
        Gets the message history for the specified entity

        Args:
            entity (:obj:`entity`):
                The entity from whom to retrieve the message history.

            limit (:obj:`int` | :obj:`None`, optional):
                Number of messages to be retrieved. Due to limitations with
                the API retrieving more than 3000 messages will take longer
                than half a minute (or even more based on previous calls).
                The limit may also be ``None``, which would eventually return
                the whole history.

            offset_date (:obj:`datetime`):
                Offset date (messages *previous* to this date will be
                retrieved). Exclusive.

            offset_id (:obj:`int`):
                Offset message ID (only messages *previous* to the given
                ID will be retrieved). Exclusive.

            max_id (:obj:`int`):
                All the messages with a higher (newer) ID or equal to this will
                be excluded

            min_id (:obj:`int`):
                All the messages with a lower (older) ID or equal to this will
                be excluded.

            add_offset (:obj:`int`):
                Additional message offset (all of the specified offsets +
                this offset = older messages).

        Returns:
            A list of messages with extra attributes:

                * ``.total`` = (on the list) total amount of messages sent.
                * ``.sender`` = entity of the sender.
                * ``.fwd_from.sender`` = if fwd_from, who sent it originally.
                * ``.fwd_from.channel`` = if fwd_from, original channel.
                * ``.to`` = entity to which the message was sent.
        """
        entity = self.get_input_entity(entity)
        limit = float('inf') if limit is None else int(limit)
        if limit == 0:
            # No messages, but we still need to know the total message count
            result = self(
                GetHistoryRequest(peer=entity,
                                  limit=1,
                                  offset_date=None,
                                  offset_id=0,
                                  max_id=0,
                                  min_id=0,
                                  add_offset=0))
            return getattr(result, 'count', len(result.messages)), [], []

        total_messages = 0
        messages = UserList()
        entities = {}
        while len(messages) < limit:
            # Telegram has a hard limit of 100
            real_limit = min(limit - len(messages), 100)
            result = self(
                GetHistoryRequest(peer=entity,
                                  limit=real_limit,
                                  offset_date=offset_date,
                                  offset_id=offset_id,
                                  max_id=max_id,
                                  min_id=min_id,
                                  add_offset=add_offset,
                                  hash=0))
            messages.extend(m for m in result.messages
                            if not isinstance(m, MessageEmpty))
            total_messages = getattr(result, 'count', len(result.messages))

            # TODO We can potentially use self.session.database, but since
            # it might be disabled, use a local dictionary.
            for u in result.users:
                entities[utils.get_peer_id(u)] = u
            for c in result.chats:
                entities[utils.get_peer_id(c)] = c

            if len(result.messages) < real_limit:
                break

            offset_id = result.messages[-1].id
            offset_date = result.messages[-1].date

            # Telegram limit seems to be 3000 messages within 30 seconds in
            # batches of 100 messages each request (since the FloodWait was
            # of 30 seconds). If the limit is greater than that, we will
            # sleep 1s between each request.
            if limit > 3000:
                time.sleep(1)

        # Add a few extra attributes to the Message to make it friendlier.
        messages.total = total_messages
        for m in messages:
            # TODO Better way to return a total without tuples?
            m.sender = (None if not m.from_id else entities[utils.get_peer_id(
                m.from_id)])

            if getattr(m, 'fwd_from', None):
                m.fwd_from.sender = (None if not m.fwd_from.from_id else
                                     entities[utils.get_peer_id(
                                         m.fwd_from.from_id)])
                m.fwd_from.channel = (None if not m.fwd_from.channel_id else
                                      entities[utils.get_peer_id(
                                          PeerChannel(m.fwd_from.channel_id))])

            m.to = entities[utils.get_peer_id(m.to_id)]

        return messages
Ejemplo n.º 6
0
 def extend(self, other):
     UserList.extend(self, other)
     self.send(extend=other)
Ejemplo n.º 7
0
 def extend(self, other):
     UserList.extend(self, other)
     self.notify()