Browse Source
Make fill() return a boolean based on whether items were added to the
buffer, and update __next__() accordingly
pull/69/head
Moses Miller
8 years ago
No known key found for this signature in database
GPG Key ID: A46D4C3CF5B1EA57
1 changed files with
8 additions and
5 deletions
-
disco/types/channel.py
|
|
@ -518,6 +518,8 @@ class MessageIterator(object): |
|
|
|
def fill(self): |
|
|
|
""" |
|
|
|
Fills the internal buffer up with :class:`disco.types.message.Message` objects from the API. |
|
|
|
|
|
|
|
Returns a boolean indicating whether items were added to the buffer. |
|
|
|
""" |
|
|
|
self._buffer = self.client.api.channels_messages_list( |
|
|
|
self.channel.id, |
|
|
@ -526,7 +528,7 @@ class MessageIterator(object): |
|
|
|
limit=self.chunk_size) |
|
|
|
|
|
|
|
if not len(self._buffer): |
|
|
|
return |
|
|
|
return False |
|
|
|
|
|
|
|
self.after = None |
|
|
|
self.before = None |
|
|
@ -538,6 +540,8 @@ class MessageIterator(object): |
|
|
|
self._buffer.reverse() |
|
|
|
self.after = self._buffer[-1].id |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
def next(self): |
|
|
|
return self.__next__() |
|
|
|
|
|
|
@ -546,10 +550,9 @@ class MessageIterator(object): |
|
|
|
|
|
|
|
def __next__(self): |
|
|
|
if not len(self._buffer): |
|
|
|
self.fill() |
|
|
|
|
|
|
|
if not len(self._buffer): |
|
|
|
raise StopIteration |
|
|
|
filled = self.fill() |
|
|
|
if not filled: |
|
|
|
raise StopIteration |
|
|
|
|
|
|
|
if self.bulk: |
|
|
|
res = self._buffer |
|
|
|