From 252afd229748d83cfd00cddb533ed85c51731f32 Mon Sep 17 00:00:00 2001 From: Moses Miller Date: Thu, 4 Jan 2018 16:23:28 -0800 Subject: [PATCH] Make fill() return a boolean based on whether items were added to the buffer, and update __next__() accordingly --- disco/types/channel.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/disco/types/channel.py b/disco/types/channel.py index ef0c17e..edaaef1 100644 --- a/disco/types/channel.py +++ b/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