Add /hytale command for whitelist requests and improve bot configuration

This commit is contained in:
2026-01-13 16:30:09 -05:00
parent f0339058fc
commit f6cf24f338

141
bot.py
View File

@@ -41,6 +41,9 @@ OWNER_ID = int(os.getenv('OWNER_ID', '238728085342519296'))
REACTION_MESSAGE_ID = int(os.getenv('REACTION_MESSAGE_ID', '744047519696420914')) REACTION_MESSAGE_ID = int(os.getenv('REACTION_MESSAGE_ID', '744047519696420914'))
MINECRAFT_RCON_HOST = os.getenv('MINECRAFT_RCON_HOST', '10.10.10.67') MINECRAFT_RCON_HOST = os.getenv('MINECRAFT_RCON_HOST', '10.10.10.67')
MINECRAFT_RCON_PASSWORD = os.getenv('MINECRAFT_RCON_PASSWORD', '') MINECRAFT_RCON_PASSWORD = os.getenv('MINECRAFT_RCON_PASSWORD', '')
PELICAN_URL = os.getenv('PELICAN_URL', 'http://10.10.10.67')
PELICAN_API_KEY = os.getenv('PELICAN_API_KEY', '') # Client API key
HYTALE_SERVER_UUID = os.getenv('HYTALE_SERVER_UUID', '7a656836-c3f3-491e-ac55-66affe435e72')
STATUS_UPDATE_INTERVAL = int(os.getenv('STATUS_UPDATE_INTERVAL', '300')) # 5 minutes default STATUS_UPDATE_INTERVAL = int(os.getenv('STATUS_UPDATE_INTERVAL', '300')) # 5 minutes default
# Emoji to role mapping for reaction roles # Emoji to role mapping for reaction roles
@@ -52,7 +55,7 @@ EMOJI_ROLE_MAP = {
"CSGO": "(CSGO)", "CSGO": "(CSGO)",
"CivilizationVI": "(Civilization VI)", "CivilizationVI": "(Civilization VI)",
"Python": "Computer Nerd", "Python": "Computer Nerd",
"computer": "Computer Nerd", # Consistent handling for add/remove "computer": "Computer Nerd",
"Valorant": "(Valorant)", "Valorant": "(Valorant)",
"Ark": "(Ark Survival Evolved)", "Ark": "(Ark Survival Evolved)",
"AmongUs": "(Among Us)", "AmongUs": "(Among Us)",
@@ -506,6 +509,7 @@ async def help_command(interaction: discord.Interaction):
embed.add_field(name="/agent", value="Get a random Valorant agent with their role", inline=False) embed.add_field(name="/agent", value="Get a random Valorant agent with their role", inline=False)
embed.add_field(name="/champion", value="Get a random League of Legends champion with their lane", inline=False) embed.add_field(name="/champion", value="Get a random League of Legends champion with their lane", inline=False)
embed.add_field(name="/minecraft", value="Whitelists a player on the Minecraft server and shows server info", inline=False) embed.add_field(name="/minecraft", value="Whitelists a player on the Minecraft server and shows server info", inline=False)
embed.add_field(name="/hytale", value="Request whitelist on the Hytale server", inline=False)
embed.add_field(name="/problem", value="Express your opinion about Canada geese", inline=False) embed.add_field(name="/problem", value="Express your opinion about Canada geese", inline=False)
# Interaction Commands # Interaction Commands
@@ -653,6 +657,141 @@ async def minecraft(interaction: discord.Interaction, minecraft_username: str):
await interaction.followup.send("An error occurred.", ephemeral=True) await interaction.followup.send("An error occurred.", ephemeral=True)
@client.tree.command(name="hytale", description="Whitelist a player on the Hytale server")
@app_commands.describe(hytale_username="Hytale username to whitelist")
@has_role_check(MINECRAFT_ROLE_ID)
async def hytale(interaction: discord.Interaction, hytale_username: str):
"""
Whitelist a player on the Hytale server using Pelican Panel API
"""
try:
await interaction.response.defer()
if not PELICAN_API_KEY:
logger.error("PELICAN_API_KEY not configured")
await interaction.followup.send(
"Hytale server integration not configured. Contact an admin.",
ephemeral=True
)
return
# Send whitelist command to Hytale server via Pelican API
headers = {
"Authorization": f"Bearer {PELICAN_API_KEY}",
"Accept": "Application/vnd.pterodactyl.v1+json",
"Content-Type": "application/json"
}
command_data = {
"command": f"whitelist add {hytale_username}"
}
async with aiohttp.ClientSession() as session:
async with session.post(
f"{PELICAN_URL}/api/client/servers/{HYTALE_SERVER_UUID}/command",
headers=headers,
json=command_data
) as response:
if response.status == 204:
logger.info(f"Whitelisted {hytale_username} on Hytale server")
elif response.status == 403:
logger.error("Pelican API key lacks permissions")
await interaction.followup.send(
"Bot lacks permission to control Hytale server. Contact an admin.",
ephemeral=True
)
return
elif response.status == 404:
logger.error("Hytale server not found")
await interaction.followup.send(
"Hytale server not found. Contact an admin.",
ephemeral=True
)
return
else:
error_text = await response.text()
logger.error(f"Pelican API error {response.status}: {error_text}")
await interaction.followup.send(
f"Error communicating with Hytale server (Status: {response.status})",
ephemeral=True
)
return
# Create success embed
hytale_embed = discord.Embed(
color=discord.Color.from_rgb(152, 0, 0),
title="Hytale"
)
hytale_embed.set_author(
name="(Lotus Bot)",
icon_url="https://lotusguild.org/Lotus.png"
)
hytale_embed.add_field(
name="You",
value=f"have been whitelisted on the Hytale server!",
inline=False
)
hytale_embed.add_field(
name="Server Address",
value="hytale.lotusguild.org",
inline=False
)
hytale_embed.add_field(
name="Version",
value="Latest (2026-01-13)",
inline=False
)
hytale_embed.set_footer(text="Thanks for playing on Lotus Hytale Server!")
await interaction.followup.send(embed=hytale_embed)
except Exception as e:
logger.error(f"Error in hytale command: {e}", exc_info=True)
if not interaction.response.is_done():
await interaction.response.send_message("An error occurred.", ephemeral=True)
else:
await interaction.followup.send("An error occurred.", ephemeral=True)
@client.tree.command(name="hytale", description="Request whitelist on the Hytale server")
@app_commands.describe(hytale_username="Your Hytale username")
@has_role_check(MINECRAFT_ROLE_ID)
async def hytale(interaction: discord.Interaction, hytale_username: str):
"""Request whitelist on the Hytale server"""
try:
await interaction.response.defer()
# Validate username
if not hytale_username.replace('_', '').replace('-', '').isalnum():
await interaction.followup.send("Invalid username. Use only letters, numbers, _ and -", ephemeral=True)
return
if len(hytale_username) < 3 or len(hytale_username) > 16:
await interaction.followup.send("Username must be 3-16 characters", ephemeral=True)
return
# Log to audit
await send_audit_log(
f"🎮 Hytale Whitelist Request\nUser: {interaction.user.mention}\nUsername: `{hytale_username}`\nAction: Run `/whitelist add {hytale_username}`",
color=0x00ff00
)
# Response embed
embed = discord.Embed(color=discord.Color.from_rgb(152, 0, 0), title="Hytale")
embed.set_author(name="(Lotus Bot)", icon_url="https://photos.lotusguild.org/api/assets/3c4eb2da-0d06-407f-bdb7-c9e4cf795f0a/thumbnail?key=wd3-Z4zFdrR6WBUfXLnBN8RgeT9tivgQwT6iDN3T0AaBIOfyIuYrbEszABB8OvUplFM&size=preview&c=jUqDBQAWF9iId3J%2FyAeIcIAICEd4d3BzSA%3D%3D")
embed.add_field(name="Request Submitted", value=f"Whitelist request for `{hytale_username}` sent!", inline=False)
embed.add_field(name="Server Address", value="hytale.lotusguild.org", inline=False)
embed.add_field(name="Status", value="An admin will whitelist you shortly!", inline=False)
embed.set_footer(text="Welcome to Lotus Hytale Server!")
await interaction.followup.send(embed=embed)
logger.info(f"Hytale whitelist request: {hytale_username} by {interaction.user.name}")
except Exception as e:
logger.error(f"Error in hytale command: {e}", exc_info=True)
if not interaction.response.is_done():
await interaction.response.send_message("An error occurred.", ephemeral=True)
else:
await interaction.followup.send("An error occurred.", ephemeral=True)
# Track last usage per user # Track last usage per user
ask_cooldowns = {} ask_cooldowns = {}
COOLDOWN_MINUTES = 2 COOLDOWN_MINUTES = 2