fix(moderation): fixed history embeds taking 3 years to process

This commit is contained in:
Seaswimmer 2023-12-14 14:24:00 -05:00
parent a67b1f8ccb
commit be565f9458
Signed by: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -243,7 +243,9 @@ class Moderation(commands.Cog):
async def fetch_user_dict(self, interaction: discord.Interaction, user_id: str): async def fetch_user_dict(self, interaction: discord.Interaction, user_id: str):
"""This method returns a dictionary containing either user information or a standard deleted user template.""" """This method returns a dictionary containing either user information or a standard deleted user template."""
try: try:
user = await interaction.client.fetch_user(user_id) user = interaction.client.get_user(user_id)
if user is None:
user = await interaction.client.fetch_user(user_id)
user_dict = { user_dict = {
'id': user.id, 'id': user.id,
'name': user.name, 'name': user.name,
@ -387,6 +389,10 @@ class Moderation(commands.Cog):
except discord.errors.Forbidden: except discord.errors.Forbidden:
return return
#######################################################################################################################
### COMMANDS
#######################################################################################################################
@app_commands.command(name="note") @app_commands.command(name="note")
async def note(self, interaction: discord.Interaction, target: discord.User, reason: str, silent: bool = None): async def note(self, interaction: discord.Interaction, target: discord.User, reason: str, silent: bool = None):
"""Add a note to a user. """Add a note to a user.
@ -777,7 +783,7 @@ class Moderation(commands.Cog):
for case in result_dict_list[start_index:end_index]: for case in result_dict_list[start_index:end_index]:
target_user = await self.fetch_user_dict(interaction, case['target_id']) target_user = await self.fetch_user_dict(interaction, case['target_id'])
moderator_user = await self.fetch_user_dict(interaction, case['moderator_id']) moderator_user = await self.fetch_user_dict(interaction, case['moderator_id'])
target_name = f"`{target_user['name']}`" if target_user['discriminator'] == "0" else f"`{target_user['name']}#{target_user['discriminator']}`" target_name = target_user['name'] if target_user['discriminator'] == "0" else f"{target_user['name']}#{target_user['discriminator']}"
moderator_name = moderator_user['name'] if moderator_user['discriminator'] == "0" else f"{moderator_user['name']}#{moderator_user['discriminator']}" moderator_name = moderator_user['name'] if moderator_user['discriminator'] == "0" else f"{moderator_user['name']}#{moderator_user['discriminator']}"
field_name = f"Case #{case['moderation_id']} ({str.title(case['moderation_type'])})" field_name = f"Case #{case['moderation_id']} ({str.title(case['moderation_type'])})"
field_value = f"**Target:** `{target_name}` ({target_user['id']})\n**Moderator:** `{moderator_name}` ({moderator_user['id']})\n**Reason:** `{str(case['reason'])[:150]}`" field_value = f"**Target:** `{target_name}` ({target_user['id']})\n**Moderator:** `{moderator_name}` ({moderator_user['id']})\n**Reason:** `{str(case['reason'])[:150]}`"