Skip to content

Commit

Permalink
Fixed dodgy check, removed yelling and changd response format
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajiejackie committed Dec 15, 2023
1 parent c89d01c commit 25b457b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions uqcsbot/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ async def mcwhitelist(self, interaction: discord.Interaction, username: str):

@app_commands.command()
@app_commands.describe(username="Minecraft username to unwhitelist.")
@yelling_exemptor(input_args=["username"])
async def mcunwhitelist(self, interaction: discord.Interaction, username: str):
"""Removes a username from the whitelist for the UQCS server."""
db_session = self.bot.create_db_session()
Expand All @@ -108,7 +107,7 @@ async def mcunwhitelist(self, interaction: discord.Interaction, username: str):
)

# If the user has already whitelisted someone, and they aren't an admin deny it.
if not is_user_admin and query.count() > 0:
if not is_user_admin:
await interaction.response.send_message(
"You've already whitelisted an account."
)
Expand All @@ -123,21 +122,26 @@ async def mcunwhitelist(self, interaction: discord.Interaction, username: str):
response_kick = await self.send_rcon_command(f"kick {username}")
logging.info(f"[MINECRAFT] kick {username}: {response_kick}")

# If the responses indicate successful removal and kick, remove the database item
if "Removed" in response_remove[0] and "Kicked" in response_kick[0]:
query.delete()
# Check this else statement

# If the responses indicate successful removal, remove from the database item
if "Removed" in response_remove[0]:
query = (
db_session.query(MCWhitelist)
.filter(MCWhitelist.mc_username == username)
.delete()
)
db_session.commit()

await self.bot.admin_alert(
title="Minecraft Server Unwhitelist",
description=f"{response_remove[0]}\n{response_kick[0]}",
description=response_remove[0],
footer=f"Action performed by {interaction.user}",
colour=Colour.red(), # Use red to indicate removal
colour=Colour.red(),
)

await interaction.response.send_message(
f"{response_remove[0]}\n{response_kick[0]}"
)
# Display the response to the user in Discord
await interaction.response.send_message(response_remove[0])

db_session.close()

Expand Down Expand Up @@ -167,6 +171,7 @@ async def mcadmin(self, interaction: discord.Interaction, command: str):
for split in split_response[1:]:
await interaction.followup.send(f"```{split}```")

# Just to be safe, send this to the admin log channel as well.
await self.bot.admin_alert(
title="Minecraft Server Admin Command",
fields=[
Expand Down

0 comments on commit 25b457b

Please sign in to comment.