Create remove_user command.

This commit is contained in:
alwayscompiling
2022-08-13 21:46:41 -04:00
parent 652533d071
commit d2f33959ed
2 changed files with 55 additions and 1 deletions
+45
View File
@@ -6,6 +6,8 @@ from nextcord.ext import commands
import nextcord
from highscores import highscores_data # pylint: disable=import-error
from utilities.utils import send_highscore_message # pylint: disable=import-error
from .views.update_username_verify import UpdateUsernameVerifyView
@@ -53,6 +55,49 @@ class DataManagementCog(commands.Cog, name="Table Management"):
"You shouldn't be using this message.", ephemeral=True
)
@nextcord.slash_command(
description="Removes all of a user's scores. Warning: data is destroyed, use with case.",
default_member_permissions=nextcord.Permissions(administrator=True),
)
async def remove_user(
self,
interaction: nextcord.Interaction,
username: str = nextcord.SlashOption(
description="User to remove scores for. Note: This is not always a user's discord name."
),
):
"""
Searches all of guild's scores data for any score from the user. Removes. Updates table
message is user was removed from that table.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command
username (str): User to remove from highscores
"""
guild = highscores_data.get_guild(interaction.guild_id)
user_was_found: bool = False
# remove user from all tables and categories
for table in guild.tables:
table_updated: bool = False
for category in table.categories:
# user has a score in category
if category.remove_score(username):
user_was_found = True
table_updated = True
if table_updated:
await send_highscore_message(
interaction.guild.get_channel(guild.highscore_channel), guild, table
)
if not user_was_found:
await interaction.send(f'User "{username}" was not found.', ephemeral=True)
else:
await interaction.send(f'User "{username}" was removed from all tables.')
highscores_data.save_guild_data(guild)
@nextcord.slash_command(description="Request a username update. Admins must approve.")
async def update_username(
self,
+10 -1
View File
@@ -54,6 +54,8 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
content += f"\nApproved by <@{interaction.user.id}>."
await interaction.edit(content=content, view=None)
user_was_found: bool = False
# update username in all tables and categories
for table in guild.tables:
table_updated: bool = False
@@ -64,10 +66,17 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
score.user = new_username
category.add_score(score)
table_updated = True
user_was_found = True
if table_updated:
await send_highscore_message(
interaction.guild.get_channel(guild.highscore_channel), guild, table
)
highscores_data.save_guild_data(guild)
if not user_was_found:
await interaction.send(
f'User "{old_username}" was not found. Inform user to correct username.',
ephemeral=True,
)
else:
highscores_data.save_guild_data(guild)