Skip to content

Commit

Permalink
Prevent rate limit on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
0x16c3 committed Apr 18, 2022
1 parent 7624138 commit 1284fdd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cogs/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ class Controller(commands.Cog):
def __init__(self, client):
self.client = client
self.feeds: List[Activity] = []
self.loaded = False

async def on_ready(self):
"""Loads saved feeds from the database."""
Expand All @@ -365,7 +366,7 @@ async def on_ready(self):

error_channel_ids = []

for item in items:
for i, item in enumerate(items):
channel: discord.TextChannel = self.client.get_channel(int(item["channel"]))

if item in self.feeds:
Expand Down Expand Up @@ -427,6 +428,10 @@ async def on_ready(self):

self.feeds.append(user)

# wait 60 seconds after every 40 feed to prevent rate limiting
if i % 40 == 0:
await asyncio.sleep(30)

for user in self.feeds:
user: Activity

Expand All @@ -442,13 +447,18 @@ async def on_ready(self):
)

logger.info(f"Loaded {len(self.feeds)}.")
self.loaded = True
del error_channel_ids

async def process(self):
"""Processes all feeds with the specified interval in the config file."""

while True:

if not self.loaded:
await asyncio.sleep(5)
continue

await asyncio.sleep(int(config["INTERVAL"]))

for user in self.feeds:
Expand Down

0 comments on commit 1284fdd

Please sign in to comment.