From b12dc509d5d249c5cd054511a99a9ecef3b43de6 Mon Sep 17 00:00:00 2001 From: Magic <82341152+MagicTheDev@users.noreply.github.com> Date: Sun, 24 Mar 2024 12:51:30 -0500 Subject: [PATCH] ClashKing v4 --- classes/bot.py | 24 +++++------------------- discord/events.py | 13 +++++++++++-- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/classes/bot.py b/classes/bot.py index 9c203ed5..87a78033 100644 --- a/classes/bot.py +++ b/classes/bot.py @@ -87,6 +87,7 @@ def __init__(self, config: Config, command_prefix: str, help_command, intents: d self.button_store: collection_class = self.looper_db.clashking.button_store self.legend_rankings: collection_class = self.new_looper.legend_rankings self.war_timers: collection_class = self.looper_db.looper.war_timer + self.number_emojis: collection_class = self.looper_db.clashking.number_emojis self.db_client = motor.motor_asyncio.AsyncIOMotorClient(self._config.static_mongodb) @@ -120,7 +121,6 @@ def __init__(self, config: Config, command_prefix: str, help_command, intents: d self.custom_bots: collection_class = self.db_client.usafam.custom_bots self.suggestions: collection_class = self.db_client.usafam.suggestions - self.tickets: collection_class = self.db_client.usafam.tickets self.open_tickets: collection_class = self.db_client.usafam.open_tickets self.custom_embeds: collection_class = self.db_client.usafam.custom_embeds @@ -154,6 +154,8 @@ def __init__(self, config: Config, command_prefix: str, help_command, intents: d self.EXTENSION_LIST = [] self.STARTED_CHUNK = set() + self.number_emoji_map = {} + def clean_string(self, text: str): text = emoji.replace_emoji(text) @@ -215,24 +217,8 @@ async def create_new_badge_emoji(self, url:str): def get_number_emoji(self, color: str, number: int) -> EmojiType: if not self.user.id == 808566437199216691 and not self.user.public_flags.verified_bot: color = "gold" - guild = None - if number <= 50: - if color == "white": - guild = self.get_guild(1042301258167484426) - elif color == "blue": - guild = self.get_guild(1042222078302109779) - elif color == "gold": - guild = self.get_guild(1042301195240357958) - elif number >= 51: - if color == "white": - guild = self.get_guild(1042635651562086430) - elif color == "blue": - guild = self.get_guild(1042635521890992158) - elif color == "gold": - guild = self.get_guild(1042635608088125491) - all_emojis = guild.emojis - emoji = disnake.utils.get(all_emojis, name=f"{number}_") - return EmojiType(emoji_string=f"<:{emoji.name}:{emoji.id}>") + emoji = self.number_emoji_map.get(color).get(number) + return EmojiType(emoji_string=emoji) async def track_clans(self, tags: list): diff --git a/discord/events.py b/discord/events.py index b4418481..c7c8d326 100644 --- a/discord/events.py +++ b/discord/events.py @@ -11,7 +11,7 @@ from classes.tickets import OpenTicket, TicketPanel, LOG_TYPE from classes.DatabaseClient.familyclient import FamilyClient from assets.emojiDictionary import switcher, emoji_class_dict - +from pymongo import UpdateOne class DiscordEvents(commands.Cog): @@ -25,8 +25,8 @@ async def on_connect(self): return global has_started if not has_started: + await asyncio.sleep(5) has_started = True - await asyncio.sleep(15) if self.bot.user.public_flags.verified_bot: for count, shard in self.bot.shards.items(): await self.bot.change_presence(activity=disnake.CustomActivity(state="Use Code ClashKing 👀", name="Custom Status"), shard_id=shard.id) @@ -44,6 +44,15 @@ async def on_connect(self): "lbboardChannel": None, "lbhour": None, }) + + number_emojis = await self.bot.number_emojis.find().to_list(length=None) + number_emojis_map = {"blue" : {}, "gold" : {}, "white" : {}} + for emoji in number_emojis: + number_emojis_map[emoji.get("color")][emoji.get("count")] = emoji.get("emoji_id") + self.bot.number_emoji_map = number_emojis_map + + + '''if not self.bot.user.public_flags.verified_bot and self.bot.user.id != 808566437199216691: largest_server = sorted(self.bot.guilds, key=lambda x: x.member_count, reverse=True)[0] for server in self.bot.guilds: