Files
fembot/commands/create_meet.py
T
2026-05-24 17:28:05 +02:00

143 lines
4.7 KiB
Python

import os
import discord
from discord.ext import commands, tasks
from discord import app_commands
from datetime import datetime
from dotenv import load_dotenv
load_dotenv()
CREATE_CHANNEL_ID = os.getenv('CREATE_CHANNEL_ID')
class ConfirmInteractiveMenu(discord.ui.View):
def __init__(self):
super().__init__(timeout=60.0)
@discord.ui.button(label="Register Meetup!", style=discord.ButtonStyle.success)
async def primary_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
for child in self.children:
child.disabled = True
await interaction.response.edit_message(view=self)
await interaction.followup.send(f"## Meetup Registered Successfully!", ephemeral=True)
class CreateMeetupForm(discord.ui.Modal, title="Create a local meetup"):
def __init__(self, chosen_country: str):
super().__init__()
self.chosen_country = chosen_country
print("1")
form_postal_code = discord.ui.TextInput(
label="Enter the local postal code",
style=discord.TextStyle.short,
placeholder="",
required=True,
max_length=10
)
form_date = discord.ui.TextInput(
label="Enter the date (Format: YYYY-MM-DD)",
style=discord.TextStyle.short,
placeholder="YYYY-MM-DD",
required=True,
max_length=10
)
form_start_time = discord.ui.TextInput(
label="Enter the start time (Format: HH:MM [UTC]",
style=discord.TextStyle.short,
placeholder="HH:MM",
required=True,
max_length=5
)
form_end_time = discord.ui.TextInput(
label="Enter the end time (Format: HH:MM [UTC])",
style=discord.TextStyle.short,
placeholder="HH:MM",
required=False,
max_length=5
)
form_location = discord.ui.TextInput(
label="Enter the location or specific",
style=discord.TextStyle.paragraph,
placeholder="",
required=True,
max_length=200
)
async def on_submit(self, interaction: discord.Interaction):
await interaction.response.send_message(
content=(
"## Event Register Preview\n"
f"**Country:** {self.chosen_country}\n"
f"**Postal Code:** {self.form_postal_code.value}\n"
f"**Date:** {self.form_date.value}\n"
f"**Time:** {self.form_start_time.value} - {self.form_end_time.value}\n"
f"**Location:** {self.form_location.value}\n"
),
ephemeral=True, view=ConfirmInteractiveMenu()
)
class CountrySelect(discord.ui.Select):
def __init__(self):
options = [
discord.SelectOption(label="Deutschland", value="de", emoji="🇩🇪"),
discord.SelectOption(label="Österreich", value="at", emoji="🇦🇹"),
discord.SelectOption(label="Switzerland", value="ch", emoji="🇨🇭"),
discord.SelectOption(label="United Kingdom", value="uk", emoji="🇬🇧"),
discord.SelectOption(label="United States", value="us", emoji="🇺🇸"),
]
super().__init__(placeholder="Select your country...", min_values=1, max_values=1, options=options)
async def callback(self, interaction: discord.Interaction):
await interaction.response.send_modal(CreateMeetupForm(chosen_country=self.values[0]))
await interaction.delete_original_response()
class CountryDropdownView(discord.ui.View):
def __init__(self):
super().__init__(timeout=60)
self.add_item(CountrySelect())
class MainInteractiveMenu(discord.ui.View):
def __init__(self):
super().__init__()
@discord.ui.button(label="Register a Meetup", style=discord.ButtonStyle.success)
async def primary_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message(
content="Please select your country below to continue:",
view=CountryDropdownView(),
ephemeral=True
)
class CreateMeetup(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
async def cog_load(self):
self.startup.start()
def cog_unload(self):
self.startup.cancel()
@tasks.loop(count=1)
async def startup(self):
await self.bot.wait_until_ready()
channel = await self.bot.fetch_channel(CREATE_CHANNEL_ID)
await channel.purge(limit=None, bulk=True)
await channel.send("""
# Create a local meetup
bla bla bla
bla bla bla
-# bla bla bla
""", view=MainInteractiveMenu())
async def setup(bot: commands.Bot):
await bot.add_cog(CreateMeetup(bot))