basic setup
This commit is contained in:
commit
b3508664d3
9 files changed
+186
No files matched your search
@@ -0,0 +1 @@
|
||||
DISCORD_TOKEN=""
|
||||
@@ -0,0 +1,5 @@
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
*.env
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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))
|
||||
@@ -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))
|
||||
@@ -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))
|
||||
@@ -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())
|
||||
Reference in new issue
Block a user