Skip to content

Commit

Permalink
ClashKing v4
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTheDev committed Mar 24, 2024
1 parent 8995913 commit f39fd3c
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions background/tasks/emoji_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ def __init__(self, bot: CustomClient):

@tasks.loop(seconds=600)
async def refresh(self):
emoji_map = {}
for guild_id in BADGE_GUILDS:
guild = await self.bot.getch_guild(guild_id)
if guild is not None:
while len(guild.emojis) >= 46:
num_to_delete = random.randint(1, 5)
for emoji in guild.emojis[:num_to_delete]:
await guild.delete_emoji(emoji=emoji)
for emoji in guild.emojis:
emoji_map[emoji.name] = f"<:{emoji.name}:{emoji.id}>"
self.bot.clan_badge_emoji_map = emoji_map
if self.bot.user.public_flags.verified_bot:
emoji_map = {}
for guild_id in BADGE_GUILDS:
guild = await self.bot.getch_guild(guild_id)
if guild is not None:
#only shard one needs to worry about deleting
if self.bot.shard_id == 1 and len(guild.emojis) >= 46 :
num_to_delete = len(guild.emojis) - 45
#sort from newest to oldest to remove the old ones
guild_emojis = sorted(guild.emojis, key=lambda x : x.id, reverse=True)
for emoji in guild_emojis[(-1 * num_to_delete):]:
await emoji.delete()

for emoji in guild.emojis:
emoji_map[emoji.name] = f"<:{emoji.name}:{emoji.id}>"
self.bot.clan_badge_emoji_map = emoji_map


def setup(bot: CustomClient):
Expand Down

0 comments on commit f39fd3c

Please sign in to comment.