Skip to content

Commit

Permalink
fix: application command sync ratelimits
Browse files Browse the repository at this point in the history
  • Loading branch information
Skelmis committed Jan 4, 2024
1 parent 061e111 commit df5984f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions suggestions/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ async def dispatch_initial_ready(self):
def total_cluster_count(self) -> int:
return math.ceil(self.total_shards / 10)

@property
def is_primary_cluster(self) -> bool:
return bool(os.environ.get("IS_PRIMARY_CLUSTER", False))

def error_embed(
self,
title: str,
Expand Down Expand Up @@ -701,6 +697,24 @@ async def process_update_bot_listings():
state.add_background_task(task_1)
log.info("Setup bot list updates")

@property
def is_primary_cluster(self) -> bool:
if not self.is_prod:
# Non-prod is always single cluster
return True

shard_id = self.get_shard_id(self.main_guild_id)
return shard_id in self.shard_ids

async def _sync_application_commands(self) -> None:
# In order to reduce getting rate-limited because every cluster
# decided it wants to sync application commands when it aint required
if not self.is_primary_cluster:
log.warning("Not syncing application commands as not primary cluster")
return

await super()._sync_application_commands()

def get_shard_id(self, guild_id: Optional[int]) -> int:
# DM's go to shard 0
shard_id = 0
Expand Down

0 comments on commit df5984f

Please sign in to comment.