commit b3508664d316dd0a657e1607bf702a5b71ade0bd Author: Soenke Date: Fri May 22 22:50:58 2026 +0200 basic setup diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..9edc9ad --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +DISCORD_TOKEN="" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b44597c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +__pycache__/ +*.py[cod] +*$py.class + +*.env \ No newline at end of file diff --git a/commands/__pycache__/create_meet.cpython-314.pyc b/commands/__pycache__/create_meet.cpython-314.pyc new file mode 100644 index 0000000..23ff0a5 Binary files /dev/null and b/commands/__pycache__/create_meet.cpython-314.pyc differ diff --git a/commands/__pycache__/meow.cpython-314.pyc b/commands/__pycache__/meow.cpython-314.pyc new file mode 100644 index 0000000..3bcf7db Binary files /dev/null and b/commands/__pycache__/meow.cpython-314.pyc differ diff --git a/commands/__pycache__/ping.cpython-314.pyc b/commands/__pycache__/ping.cpython-314.pyc new file mode 100644 index 0000000..abed46e Binary files /dev/null and b/commands/__pycache__/ping.cpython-314.pyc differ diff --git a/commands/create_meet.py b/commands/create_meet.py new file mode 100644 index 0000000..0888003 --- /dev/null +++ b/commands/create_meet.py @@ -0,0 +1,111 @@ +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)) \ No newline at end of file diff --git a/commands/meow.py b/commands/meow.py new file mode 100644 index 0000000..acf83a1 --- /dev/null +++ b/commands/meow.py @@ -0,0 +1,15 @@ +import discord +from discord.ext import commands +from discord import app_commands + +class Meow(commands.Cog): + def __init__(self, bot: commands.Bot): + self.bot = bot + + @app_commands.command(name="meow", description="MEOW!") + async def meow(self, interaction: discord.Interaction): + await interaction.response.send_message("MEOW :3") + + +async def setup(bot: commands.Bot): + await bot.add_cog(Meow(bot)) \ No newline at end of file diff --git a/commands/ping.py b/commands/ping.py new file mode 100644 index 0000000..a3ac09f --- /dev/null +++ b/commands/ping.py @@ -0,0 +1,16 @@ +import discord +from discord.ext import commands +from discord import app_commands + +class Ping(commands.Cog): + def __init__(self, bot: commands.Bot): + self.bot = bot + + @app_commands.command(name="ping", description='Responds with "pong!"') + async def ping(self, interaction: discord.Interaction): + latency = round(self.bot.latency * 1000) + await interaction.response.send_message(f"Pong! ({latency}ms)") + + +async def setup(bot: commands.Bot): + await bot.add_cog(Ping(bot)) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..238dee8 --- /dev/null +++ b/main.py @@ -0,0 +1,38 @@ +import os +import asyncio +import discord +from discord.ext import commands +from dotenv import load_dotenv + +load_dotenv() +TOKEN = os.getenv('DISCORD_TOKEN') + +intents = discord.Intents.default() +intents.message_content = True + +bot = commands.Bot(command_prefix="Warum Kann das nicht weg??? :C", intents=intents) + +@bot.event +async def on_ready(): + print(f'Logged in as {bot.user} (ID: {bot.user.id})') + print('------') + + try: + synced = await bot.tree.sync() + print(f"Synced {len(synced)} command(s) successfully!") + except Exception as e: + print(f"Failed to sync commands: {e}") + + +async def load_extensions(): + for filename in os.listdir('./commands'): + if filename.endswith('.py'): + await bot.load_extension(f'commands.{filename[:-3]}') + print(f'Loaded extension: commands.{filename[:-3]}') + +async def main(): + async with bot: + await load_extensions() + await bot.start(TOKEN) + +asyncio.run(main()) \ No newline at end of file