diff --git a/applicationbot.py b/applicationbot.py index 99b66e5..8f46c46 100644 --- a/applicationbot.py +++ b/applicationbot.py @@ -81,15 +81,22 @@ bot = commands.Bot(command_prefix=".", test_guilds=[int(os.getenv("GUILD_ID"))]) @bot.slash_command( name="whitelist", - description="Forceibly add a user to the whitelist", + description="Forceibly add or remove a user from the whitelist", ) -async def whitelist(inter: disnake.AppCmdInter, username:str, user:disnake.Member): +async def whitelist( + inter: disnake.AppCmdInter, + action: str = commands.Param(choices=["add", "remove"]), + username: str = commands.Param(name="minecraft-username"), + user: disnake.Member = commands.Param(name="discord-user")): await inter.response.defer() with Client(os.getenv("RCON_IP"), int(os.getenv("RCON_PORT")), passwd=os.getenv("RCON_PASSWORD")) as client: - response = client.run('whitelist', 'add', username) + response = client.run('whitelist', action, username) guild = bot.get_guild(int(os.getenv("GUILD_ID"))) role = guild.get_role(int(os.getenv("WHITELISTED_ROLE_ID"))) - await user.add_roles(role) + if action == "add": + await user.add_roles(role) + else: + await user.remove_roles(role) await inter.edit_original_response(content=f"Respose:\n```{response}```") @bot.slash_command( @@ -113,17 +120,34 @@ async def execute(inter: disnake.AppCmdInter, command:str): ) async def apply(inter: disnake.AppCmdInter): rules = os.getenv("RULES_LINK") - await inter.response.send_message(f"Ok! thank you for your interest, before we begin lets go over the rules by looking at this message {rules}\nwhen you are finished come back and press the button", ephemeral=True, components=[ + await inter.response.send_message(f"Ok! thank you for your interest, before we begin lets go over the rules by looking at this site {rules}\nwhen you are finished come back and press the button", ephemeral=True, components=[ + disnake.ui.Button(label="Apply", style=disnake.ButtonStyle.success, custom_id="Apply"), + ]) + +@bot.slash_command( + name="publicapply", + description="Creates a button to open the application menu", +) +async def apply(inter: disnake.AppCmdInter): + await inter.response.send_message(components=[ disnake.ui.Button(label="Apply", style=disnake.ButtonStyle.success, custom_id="Apply"), ]) @bot.listen("on_button_click") async def button_listener(inter: disnake.MessageInteraction): if inter.component.custom_id == "Apply": - await inter.response.send_modal(modal=ApplicationModal()) + guild = bot.get_guild(int(os.getenv("GUILD_ID"))) + approle = guild.get_role(int(os.getenv("APPLICANT_ROLE_ID"))) + whitelistedrole = guild.get_role(int(os.getenv("WHITELISTED_ROLE_ID"))) + member = await guild.fetch_member(inter.user.id) + if any(r in member.roles for r in (approle, whitelistedrole)): + await inter.response.send_message("You have already applied, you many not apply again!", ephemeral=True) + else: + await inter.response.send_modal(modal=ApplicationModal()) return ogmsg = inter.message.embeds embed = ogmsg[0] + dmstat = "" user = await bot.fetch_user(int(embed.fields[1].value)) if inter.component.custom_id == "Approve": with Client(os.getenv("RCON_IP"), int(os.getenv("RCON_PORT")), passwd=os.getenv("RCON_PASSWORD")) as client: @@ -134,16 +158,16 @@ async def button_listener(inter: disnake.MessageInteraction): try: await user.send("You have been Whitelisted, however your username is wrong, please ping a member of the whitelist team with the correct username") except: - pass + dmstat = ", Failed to DM user" else: try: await user.send("You have been Whitelisted!") except: - pass + dmstat = ", Failed to DM user" status = "Aprroved and Whitelisted" embed.add_field( name="Status", - value=status, + value=f"{status}{dmstat}", inline=False, ) guild = bot.get_guild(int(os.getenv("GUILD_ID"))) @@ -152,15 +176,15 @@ async def button_listener(inter: disnake.MessageInteraction): await member.add_roles(role) await inter.response.edit_message(embed=embed, components=[]) elif inter.component.custom_id == "Deny": + try: + await user.send("You have failed the application process, you may not reapply") + except: + dmstat = ", Failed to DM user" embed.add_field( name="Status", - value="Denied", + value=f"Denied{dmstat}", inline=False, ) - try: - await user.send("You have failed the application process, you may not reapply") - except: - pass await inter.response.edit_message(embed=embed, components=[]) bot.run(os.getenv("TOKEN")) \ No newline at end of file