Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwhitelist command #188

Merged
merged 6 commits into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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