application-bot/applicationbot.py

85 lines
No EOL
3.3 KiB
Python

import disnake
from disnake.ext import commands
from disnake import TextInputStyle
from dotenv import load_dotenv
import os
load_dotenv()
class ApplicationModal(disnake.ui.Modal):
def __init__(self):
# The details of the modal, and its components
components = [
disnake.ui.TextInput(
label="Username (Minecraft)",
placeholder="DraconicDragon3",
custom_id="Username",
style=TextInputStyle.short,
max_length=16,
),
disnake.ui.TextInput(
label="Tell us a bit about yourself",
placeholder="Three Sentence Minimum Please!",
custom_id="Tell us a bit about yourself",
style=TextInputStyle.paragraph,
),
disnake.ui.TextInput(
label="The secret phrase",
placeholder="",
custom_id="The secret phrase",
style=TextInputStyle.short,
max_length=32,
),
]
super().__init__(title="Apply to join the server", components=components)
# The callback received when the user input is completed.
async def callback(self, inter: disnake.ModalInteraction):
embed_color = 0x00ff00
embed_title = "New Application"
applicationdenied = False
application = inter.text_values.items()
for key, value in application:
if key == "The secret phrase" and value != os.getenv("PHRASE"):
applicationdenied = True
embed_color = disnake.Colour.red()
embed_title = "Auto-Denied Application"
embed = disnake.Embed(title=embed_title, color=embed_color)
embed.add_field(
name="User",
value=f"<@{inter.user.id}> ({inter.user.id})",
inline=False,
)
for key, value in application:
embed.add_field(
name=key,
value=value,
inline=False,
)
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)
else:
await inter.response.send_message("Your Application has been successfully submitted, you will receive your response eventually", ephemeral=True)
await bot.get_channel(int(os.getenv("LOG_CHANNEL"))).send(embed=embed, components=[
disnake.ui.Button(label="Approve", style=disnake.ButtonStyle.success, custom_id="Approve"),
disnake.ui.Button(label="Deny", style=disnake.ButtonStyle.danger, custom_id="Deny"),
],)
bot = commands.Bot(command_prefix=".", test_guilds=[int(os.getenv("GUILD_ID"))])
@bot.slash_command()
async def apply(inter: disnake.AppCmdInter):
await inter.response.send_modal(modal=ApplicationModal())
@bot.listen("on_button_click")
async def button_listener(inter: disnake.MessageInteraction):
if inter.component.custom_id == "Approve":
print(await inter.response.message())
await inter.response.edit_message("Status: Whitelisted!", components=[])
elif inter.component.custom_id == "Deny":
await inter.response.edit_message("Status: Blacklisted!", components=[])
bot.run(os.getenv("TOKEN"))