Skip to content

Commit

Permalink
fix: tracking, emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTheDev committed Mar 31, 2024
1 parent 6000039 commit 85419f6
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions discord/events.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import asyncio
import datetime
import random
import io
import aiohttp
import disnake

from loguru import logger
from disnake.ext import commands
from classes.bot import CustomClient
from utility.war import create_reminders, send_or_update_war_end, send_or_update_war_start
from utility.constants import USE_CODE_TEXT
has_started = False

from classes.tickets import OpenTicket, TicketPanel, LOG_TYPE
from classes.DatabaseClient.familyclient import FamilyClient
from assets.emojis import SharedEmojis
from collections import deque
from commands.reminders.send_reminders import clan_games_reminder, clan_capital_reminder, inactivity_reminder, roster_reminder

has_started = False
has_readied = False

class DiscordEvents(commands.Cog):

def __init__(self, bot: CustomClient):
Expand Down Expand Up @@ -80,13 +81,19 @@ async def on_connect(self):
self.bot.scheduler.add_job(inactivity_reminder, trigger='interval', args=[self.bot], minutes=30, misfire_grace_time=None)
self.bot.scheduler.add_job(roster_reminder, trigger='interval', args=[self.bot], minutes=2, misfire_grace_time=None)

print('We have connected')
logger.info('We have connected')


@commands.Cog.listener()
async def on_ready(self):
global has_started
if not has_started:
await asyncio.sleep(5)
has_started = True
else:
return
await asyncio.sleep(5)
print("ready")
logger.info("ready")
#will remove later, if is a custom bot, remove ourselves from every server but one
if not self.bot.user.public_flags.verified_bot and self.bot.user.id != 808566437199216691:
if self.bot.guilds:
Expand All @@ -102,7 +109,7 @@ async def on_ready(self):
if number <= 50:
SharedEmojis.all_emojis[f"{number}_"] = emoji_id

print(len(SharedEmojis.all_emojis), "emojis that we have")
logger.info(len(SharedEmojis.all_emojis), "emojis that we have")
if not self.bot.user.public_flags.verified_bot:
our_emoji_servers = [server for server in self.bot.guilds if server.owner_id == self.bot.user.id and server.name != "ckcustombotbadges"]
if len(our_emoji_servers) < 8:
Expand All @@ -113,11 +120,11 @@ async def on_ready(self):
else:
guild = await self.bot.create_guild(name="ckcustombotbadges")

print(", ".join([g.name for g in self.bot.guilds]))
print(", ".join([str(len(g.emojis)) for g in self.bot.guilds]))
print(sum([(len(g.emojis)) for g in self.bot.guilds]) - 254, "emojis installed")
logger.info(", ".join([g.name for g in self.bot.guilds]))
logger.info(", ".join([str(len(g.emojis)) for g in self.bot.guilds]))
logger.info(sum([(len(g.emojis)) for g in self.bot.guilds]) - 254, "emojis installed")

print(len(our_emoji_servers), "servers")
logger.info(len(our_emoji_servers), "servers")
our_emoji_servers = deque(our_emoji_servers)

id_to_lookup_name_map = {}
Expand All @@ -139,14 +146,14 @@ async def on_ready(self):
continue
all_our_emojis[lookup_name] = f"<:{emoji.name}:{emoji.id}>"

print(deleted, "emojis deleted")
logger.info(deleted, "emojis deleted")

to_create = 0
for emoji_name, emoji_string in SharedEmojis.all_emojis.items():
if emoji_name not in all_our_emojis:
to_create += 1

print(f"{to_create} emojis to create")
logger.info(f"{to_create} emojis to create")
for emoji_name, emoji_string in SharedEmojis.all_emojis.items():
if emoji_name not in all_our_emojis:
server = our_emoji_servers[0]
Expand All @@ -165,14 +172,14 @@ async def on_ready(self):
await session.close()
emoji = await server.create_custom_emoji(name=str(main_bot_emoji.id), image=bytes_image)
lookup_name = id_to_lookup_name_map.get(emoji.name)
print(f"created {lookup_name}")
logger.info(f"created {lookup_name}")
all_our_emojis[lookup_name] = f"<:{emoji.name}:{emoji.id}>"
our_emoji_servers.rotate(1)

for emoji_name, emoji_string in all_our_emojis.items():
SharedEmojis.all_emojis[emoji_name] = emoji_string

print("done with emoji creation")
logger.info("done with emoji creation")


@commands.Cog.listener()
Expand Down

0 comments on commit 85419f6

Please sign in to comment.