111 lines
3.8 KiB
Python
111 lines
3.8 KiB
Python
import discord
|
|
from discord.ext import commands
|
|
from discord import app_commands
|
|
from datetime import datetime
|
|
|
|
class InteractiveMenu(discord.ui.View):
|
|
def __init__(self):
|
|
super().__init__(timeout=60.0)
|
|
|
|
@discord.ui.button(label="Register Event!", 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"## Event Registered Successfully!")
|
|
|
|
|
|
class EventLookup(commands.Cog):
|
|
def __init__(self, bot: commands.Bot):
|
|
self.bot = bot
|
|
|
|
@app_commands.command(name="create_meet", description="Create a local meetup")
|
|
@app_commands.choices(country=[
|
|
app_commands.Choice(name="Deutschland", value="de"),
|
|
app_commands.Choice(name="United Kingdom", value="uk"),
|
|
app_commands.Choice(name="Österreich", value="at"),
|
|
app_commands.Choice(name="Switzerland", value="ch")
|
|
])
|
|
@app_commands.describe(
|
|
country="Select your country from the list",
|
|
postal_code="Enter the local postal code",
|
|
|
|
date="Enter the date (Format: YYYY-MM-DD)",
|
|
start_time="Enter start time (Format: HH:MM [UTC+00:00], e.g., 14:30)",
|
|
end_time="Enter end time (Format: HH:MM [UTC+00:00], e.g., 17:00)",
|
|
location="Enter the location or specific address"
|
|
)
|
|
async def create_meet(self,
|
|
interaction: discord.Interaction,
|
|
country: app_commands.Choice[str],
|
|
date: str,
|
|
start_time: str,
|
|
end_time: str,
|
|
postal_code: str,
|
|
location: str
|
|
):
|
|
|
|
|
|
try:
|
|
valid_date = datetime.strptime(date, "%Y-%m-%d").date()
|
|
formatted_date = valid_date.strftime("%B %d, %Y")
|
|
except ValueError:
|
|
await interaction.response.send_message(
|
|
f"❌ Invalid date format: `{date}`. Please use **YYYY-MM-DD**.",
|
|
ephemeral=True
|
|
)
|
|
return
|
|
|
|
|
|
if datetime.now().date() > valid_date:
|
|
await interaction.response.send_message(
|
|
"❌ The date cannot be in the past!",
|
|
ephemeral=True
|
|
)
|
|
return
|
|
|
|
|
|
try:
|
|
valid_start = datetime.strptime(start_time, "%H:%M").time()
|
|
valid_end = datetime.strptime(end_time, "%H:%M").time()
|
|
|
|
formatted_start = valid_start.strftime("%H:%M")
|
|
formatted_end = valid_end.strftime("%H:%M")
|
|
except ValueError:
|
|
await interaction.response.send_message(
|
|
f"❌ Invalid time format. Please use **HH:MM** in 24-hour format (e.g., `14:30`).",
|
|
ephemeral=True
|
|
)
|
|
return
|
|
|
|
|
|
if valid_start >= valid_end:
|
|
await interaction.response.send_message(
|
|
"❌ The start time must be earlier than the end time!",
|
|
ephemeral=True
|
|
)
|
|
return
|
|
|
|
|
|
country_labels = {
|
|
"de": "Deutschland",
|
|
"uk": "United Kingdom",
|
|
"at": "Österreich",
|
|
"ch": "Switzerland"
|
|
}
|
|
chosen_country = country_labels.get(country.value, country.name)
|
|
|
|
response_text = (
|
|
f"## Event Register Preview\n"
|
|
f"- **Country:** {chosen_country}\n"
|
|
f"- **Postal Code:** {postal_code}\n"
|
|
f"- **Date:** {formatted_date}\n"
|
|
f"- **Time:** {formatted_start} - {formatted_end}\n"
|
|
f"- **Location:** {location}\n"
|
|
)
|
|
|
|
await interaction.response.send_message(response_text, view=InteractiveMenu())
|
|
|
|
async def setup(bot: commands.Bot):
|
|
await bot.add_cog(EventLookup(bot)) |