Skip to content

Commit

Permalink
Merge branch 'main' into patch-aocmissingping
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewj-brown authored Dec 23, 2023
2 parents 1476053 + 3cc856b commit d6ae866
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions uqcsbot/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,51 @@ async def mcwhitelist(self, interaction: discord.Interaction, username: str):

db_session.close()

@app_commands.command()
@app_commands.describe(username="Minecraft username to unwhitelist.")
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()
is_user_admin = (
isinstance(interaction.user, Member)
and interaction.user.guild_permissions.manage_guild
)

# If the user has already whitelisted someone, and they aren't an admin deny it.
if not is_user_admin:
await interaction.response.send_message(
"You've already whitelisted an account."
)
else:
# Send the RCON command to remove the user from the whitelist
response_remove = await self.send_rcon_command(
f"whitelist remove {username}"
)
logging.info(f"[MINECRAFT] whitelist remove {username}: {response_remove}")

# Send the RCON command to kick the player from the server
response_kick = await self.send_rcon_command(f"kick {username}")
logging.info(f"[MINECRAFT] kick {username}: {response_kick}")

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

await self.bot.admin_alert(
title="Minecraft Server Unwhitelist",
description=response_remove[0],
footer=f"Action performed by {interaction.user}",
colour=Colour.red(),
)

# Display the response to the user in Discord
await interaction.response.send_message(response_remove[0])

db_session.close()

mcadmin_group = app_commands.Group(
name="mcadmin", description="Commands for managing the UQCS Minecraft server"
)
Expand Down

0 comments on commit d6ae866

Please sign in to comment.