Skip to content

Commit

Permalink
fix: try to fix the websocket lag
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTheDev committed Apr 1, 2024
1 parent 6c1119b commit 9925eb5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 100 deletions.
54 changes: 0 additions & 54 deletions background/tasks/emoji_refresh.py

This file was deleted.

15 changes: 1 addition & 14 deletions classes/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def __init__(self, config: Config, command_prefix: str, help_command, intents: d
self.STARTED_CHUNK = set()

self.number_emoji_map = {}
self.clan_badge_emoji_map = {}
self.BADGE_GUILDS = BADGE_GUILDS

@property
Expand All @@ -175,20 +174,8 @@ def __init__(self, unix_time):
return TimeStamp(unix_time)

async def create_new_badge_emoji(self, url:str):
if not self.user.public_flags.verified_bot and self.user.id != 808566437199216691:
return self.emoji.blank.emoji_string
return self.emoji.blank.emoji_string

new_url = url.replace(".png", "")

found_emoji = self.clan_badge_emoji_map.get(new_url[-15:].replace("-", ""))
if found_emoji is not None:
return self.clan_badge_emoji_map.get(new_url[-15:].replace("-", ""))

img = urlopen(url).read()
self.BADGE_GUILDS.rotate(1)
guild = await self.getch_guild(self.BADGE_GUILDS[0])
emoji = await guild.create_custom_emoji(name=new_url[-15:].replace("-", ""), image=img)
return f"<:{emoji.name}:{emoji.id}>"


def get_number_emoji(self, color: str, number: int) -> EmojiType:
Expand Down
16 changes: 1 addition & 15 deletions discord/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ async def on_guild_join(self, guild:disnake.Guild):




@commands.Cog.listener()
async def on_guild_remove(self, guild):
if not self.bot.user.public_flags.verified_bot:
Expand Down Expand Up @@ -265,23 +264,10 @@ async def on_application_command(self, ctx: disnake.ApplicationCommandInteractio
except Exception:
pass'''

await self.bot.command_stats.insert_one({
"user": ctx.author.id,
"command_name" : ctx.application_command.qualified_name,
"server": ctx.guild.id if ctx.guild is not None else None,
"server_name" : ctx.guild.name if ctx.guild is not None else None,
"time" : int(datetime.datetime.now().timestamp()),
"guild_size" : ctx.guild.member_count if ctx.guild is not None else 0,
"channel" : ctx.channel_id,
"channel_name" : ctx.channel.name if ctx.channel is not None else None,
"len_mutual" : len(ctx.user.mutual_guilds),
"is_bot_dev" : ctx.user.public_flags.verified_bot_developer,
"bot" : ctx.bot.user.id
})


@commands.Cog.listener()
async def on_raw_member_remove(self, payload: disnake.RawGuildMemberRemoveEvent):
return
tickets = await self.bot.open_tickets.find({"$and": [{"server": payload.guild_id}, {"user": payload.user.id}, {"status": {"$ne": "delete"}}]}).to_list(length=None)
if not tickets:
return
Expand Down
12 changes: 5 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"discord.converters",
#"background.features.refresh_boards",
"exceptions.handler",
"background.tasks.emoji_refresh",
#"background.logs.join_leave_events"
#"background.logs.legend_events"
#"background.logs.player_upgrade_events"
#"background.logs.reminders"
]


Expand Down Expand Up @@ -125,10 +125,8 @@ def before_send(event, hint):
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=1.0,
_experiments={
"profiles_sample_rate": 1.0,
},
traces_sample_rate=0.5,
profiles_sample_rate=0.5,
before_send=before_send
)
initial_extensions += load()
Expand All @@ -138,7 +136,7 @@ def before_send(event, hint):
except Exception as extension:
traceback.print_exc()
bot.EXTENSION_LIST.extend(initial_extensions)
if not config.is_beta:
bot.loop.create_task(kafka_events(bot))
#if not config.is_beta:
#bot.loop.create_task(kafka_events(bot))

bot.run(config.bot_token)
14 changes: 4 additions & 10 deletions utility/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ async def family_names(bot: CustomClient, query: str, guild):
]
results = await bot.player_search.aggregate(pipeline=pipeline).to_list(length=None)
for document in results:
league = document.get("league")
if league == "Unknown":
league = "Unranked"
league = league.replace(" League", "")
names.append(f'{create_superscript(document.get("th"))}{document.get("name")} ({league})' + " | " + document.get("tag"))
clan = document.get("clan_name")
names.append(f'{create_superscript(document.get("th"))}{document.get("name")} ({clan})' + " | " + document.get("tag"))
return names


Expand All @@ -103,11 +100,8 @@ async def all_names(bot: CustomClient, query: str):
]
results = await bot.player_search.aggregate(pipeline=pipeline).to_list(length=None)
for document in results:
league = document.get("league")
if league == "Unknown":
league = "Unranked"
league = league.replace(" League", "")
names.append(f'{create_superscript(document.get("th"))}{document.get("name")} ({league})' + " | " + document.get("tag"))
clan = document.get("clan_name")
names.append(f'{create_superscript(document.get("th"))}{document.get("name")} ({clan})' + " | " + document.get("tag"))
return names


Expand Down

0 comments on commit 9925eb5

Please sign in to comment.