-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcustom_dpy_overrides.py
More file actions
41 lines (28 loc) · 1.33 KB
/
custom_dpy_overrides.py
File metadata and controls
41 lines (28 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from discord.abc import Messageable
from discord.iterators import HistoryIterator
from discord_components.dpy_overrides import *
# Override the channel.history() method include message components
class CustomHistoryIterator(HistoryIterator):
def __init__(self, messageable, limit,
before=None, after=None, around=None, oldest_first=None):
super().__init__(messageable, limit, before, after, around, oldest_first)
async def fill_messages(self):
if not hasattr(self, 'channel'):
# do the required set up
channel = await self.messageable._get_channel()
self.channel = channel
if self._get_retrieve():
data = await self._retrieve_messages(self.retrieve)
if len(data) < 100:
self.limit = 0 # terminate the infinite loop
if self.reverse:
data = reversed(data)
if self._filter:
data = filter(self._filter, data)
channel = self.channel
for element in data:
await self.messages.put(ComponentMessage(state=self.state, channel=channel, data=element))
# Returns a modified async iterator
def history(channel, *args, **kwargs) -> HistoryIterator:
return CustomHistoryIterator(channel, *args, **kwargs)
Messageable.history = history