Add more options to whitelist command, check user roles when applying
This commit is contained in:
parent
41e1794788
commit
5d1200c33a
1 changed files with 38 additions and 14 deletions
|
@ -81,15 +81,22 @@ bot = commands.Bot(command_prefix=".", test_guilds=[int(os.getenv("GUILD_ID"))])
|
||||||
|
|
||||||
@bot.slash_command(
|
@bot.slash_command(
|
||||||
name="whitelist",
|
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()
|
await inter.response.defer()
|
||||||
with Client(os.getenv("RCON_IP"), int(os.getenv("RCON_PORT")), passwd=os.getenv("RCON_PASSWORD")) as client:
|
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")))
|
guild = bot.get_guild(int(os.getenv("GUILD_ID")))
|
||||||
role = guild.get_role(int(os.getenv("WHITELISTED_ROLE_ID")))
|
role = guild.get_role(int(os.getenv("WHITELISTED_ROLE_ID")))
|
||||||
|
if action == "add":
|
||||||
await user.add_roles(role)
|
await user.add_roles(role)
|
||||||
|
else:
|
||||||
|
await user.remove_roles(role)
|
||||||
await inter.edit_original_response(content=f"Respose:\n```{response}```")
|
await inter.edit_original_response(content=f"Respose:\n```{response}```")
|
||||||
|
|
||||||
@bot.slash_command(
|
@bot.slash_command(
|
||||||
|
@ -113,17 +120,34 @@ async def execute(inter: disnake.AppCmdInter, command:str):
|
||||||
)
|
)
|
||||||
async def apply(inter: disnake.AppCmdInter):
|
async def apply(inter: disnake.AppCmdInter):
|
||||||
rules = os.getenv("RULES_LINK")
|
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"),
|
disnake.ui.Button(label="Apply", style=disnake.ButtonStyle.success, custom_id="Apply"),
|
||||||
])
|
])
|
||||||
|
|
||||||
@bot.listen("on_button_click")
|
@bot.listen("on_button_click")
|
||||||
async def button_listener(inter: disnake.MessageInteraction):
|
async def button_listener(inter: disnake.MessageInteraction):
|
||||||
if inter.component.custom_id == "Apply":
|
if inter.component.custom_id == "Apply":
|
||||||
|
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())
|
await inter.response.send_modal(modal=ApplicationModal())
|
||||||
return
|
return
|
||||||
ogmsg = inter.message.embeds
|
ogmsg = inter.message.embeds
|
||||||
embed = ogmsg[0]
|
embed = ogmsg[0]
|
||||||
|
dmstat = ""
|
||||||
user = await bot.fetch_user(int(embed.fields[1].value))
|
user = await bot.fetch_user(int(embed.fields[1].value))
|
||||||
if inter.component.custom_id == "Approve":
|
if inter.component.custom_id == "Approve":
|
||||||
with Client(os.getenv("RCON_IP"), int(os.getenv("RCON_PORT")), passwd=os.getenv("RCON_PASSWORD")) as client:
|
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:
|
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")
|
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:
|
except:
|
||||||
pass
|
dmstat = ", Failed to DM user"
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
await user.send("You have been Whitelisted!")
|
await user.send("You have been Whitelisted!")
|
||||||
except:
|
except:
|
||||||
pass
|
dmstat = ", Failed to DM user"
|
||||||
status = "Aprroved and Whitelisted"
|
status = "Aprroved and Whitelisted"
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Status",
|
name="Status",
|
||||||
value=status,
|
value=f"{status}{dmstat}",
|
||||||
inline=False,
|
inline=False,
|
||||||
)
|
)
|
||||||
guild = bot.get_guild(int(os.getenv("GUILD_ID")))
|
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 member.add_roles(role)
|
||||||
await inter.response.edit_message(embed=embed, components=[])
|
await inter.response.edit_message(embed=embed, components=[])
|
||||||
elif inter.component.custom_id == "Deny":
|
elif inter.component.custom_id == "Deny":
|
||||||
embed.add_field(
|
|
||||||
name="Status",
|
|
||||||
value="Denied",
|
|
||||||
inline=False,
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
await user.send("You have failed the application process, you may not reapply")
|
await user.send("You have failed the application process, you may not reapply")
|
||||||
except:
|
except:
|
||||||
pass
|
dmstat = ", Failed to DM user"
|
||||||
|
embed.add_field(
|
||||||
|
name="Status",
|
||||||
|
value=f"Denied{dmstat}",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
await inter.response.edit_message(embed=embed, components=[])
|
await inter.response.edit_message(embed=embed, components=[])
|
||||||
|
|
||||||
bot.run(os.getenv("TOKEN"))
|
bot.run(os.getenv("TOKEN"))
|
Loading…
Reference in a new issue