Finish Logic

This commit is contained in:
insert 2023-11-24 22:46:45 -05:00
parent e336f680a1
commit 60da68bd97

View file

@ -2,6 +2,7 @@ import disnake
from disnake.ext import commands
from disnake import TextInputStyle
from dotenv import load_dotenv
from rcon.source import Client
import os
load_dotenv()
@ -48,7 +49,12 @@ class ApplicationModal(disnake.ui.Modal):
embed = disnake.Embed(title=embed_title, color=embed_color)
embed.add_field(
name="User",
value=f"<@{inter.user.id}> ({inter.user.id})",
value=f"<@{inter.user.id}>",
inline=False,
)
embed.add_field(
name="User ID",
value=inter.user.id,
inline=False,
)
for key, value in application:
@ -57,6 +63,10 @@ class ApplicationModal(disnake.ui.Modal):
value=value,
inline=False,
)
guild = bot.get_guild(int(os.getenv("GUILD_ID")))
role = guild.get_role(int(os.getenv("APPLICANT_ROLE_ID")))
member = await guild.fetch_member(inter.user.id)
await member.add_roles(role)
if applicationdenied:
await inter.response.send_message("Your Application has been denied, you may not reapply", ephemeral=True)
await bot.get_channel(int(os.getenv("LOG_CHANNEL"))).send(embed=embed)
@ -69,17 +79,88 @@ class ApplicationModal(disnake.ui.Modal):
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",
)
async def whitelist(inter: disnake.AppCmdInter, username:str, user:disnake.Member):
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)
guild = bot.get_guild(int(os.getenv("GUILD_ID")))
role = guild.get_role(int(os.getenv("WHITELISTED_ROLE_ID")))
await user.add_roles(role)
await inter.edit_original_response(content=f"Respose:\n```{response}```")
@bot.slash_command()
@bot.slash_command(
name="execute",
description="Execute a command on the server",
)
async def execute(inter: disnake.AppCmdInter, command:str):
await inter.response.defer()
if inter.user.id != int(os.getenv("ADMIN_ID")):
await inter.edit_original_response(content="Only the server admin may run this command")
return
with Client(os.getenv("RCON_IP"), int(os.getenv("RCON_PORT")), passwd=os.getenv("RCON_PASSWORD")) as client:
response = client.run(command)
if response == "":
response = "No Response"
await inter.edit_original_response(content=f"Respose:\n```{response}```")
@bot.slash_command(
name="apply",
description="Apply to join the server",
)
async def apply(inter: disnake.AppCmdInter):
await inter.response.send_modal(modal=ApplicationModal())
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=[
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())
return
ogmsg = inter.message.embeds
embed = ogmsg[0]
user = await bot.fetch_user(int(embed.fields[1].value))
if inter.component.custom_id == "Approve":
print(await inter.response.message())
await inter.response.edit_message("Status: Whitelisted!", components=[])
with Client(os.getenv("RCON_IP"), int(os.getenv("RCON_PORT")), passwd=os.getenv("RCON_PASSWORD")) as client:
response = client.run('whitelist', 'add', embed.fields[2].value)
print(response)
if response == "That player does not exist":
status = "Error: Player Doesn't Exist"
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
else:
try:
await user.send("You have been Whitelisted!")
except:
pass
status = "Aprroved and Whitelisted"
embed.add_field(
name="Status",
value=status,
inline=False,
)
guild = bot.get_guild(int(os.getenv("GUILD_ID")))
role = guild.get_role(int(os.getenv("WHITELISTED_ROLE_ID")))
member = await guild.fetch_member(int(embed.fields[1].value))
await member.add_roles(role)
await inter.response.edit_message(embed=embed, components=[])
elif inter.component.custom_id == "Deny":
await inter.response.edit_message("Status: Blacklisted!", components=[])
embed.add_field(
name="Status",
value="Denied",
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"))