From 7882ba4915575643822d2cbb83bb6924e5c730a6 Mon Sep 17 00:00:00 2001 From: Soenke Date: Sun, 24 May 2026 23:00:37 +0200 Subject: [PATCH] settlement and formating --- .env.example | 7 ++++++- commands/create_meet.py | 31 ++++++++++++++++++++++++------- main.py | 3 +-- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 8036305..ecf4da1 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,8 @@ DISCORD_TOKEN="" -CREATE_CHANNEL_ID= \ No newline at end of file +CREATE_MEETUP_CHANNEL_ID= +DE_MEETUP_CHANNEL_ID= +AT_MEETUP_CHANNEL_ID= +CH_MEETUP_CHANNEL_ID= +US_MEETUP_CHANNEL_ID= +UK_MEETUP_CHANNEL_ID= \ No newline at end of file diff --git a/commands/create_meet.py b/commands/create_meet.py index f0c3c4d..7ea6528 100644 --- a/commands/create_meet.py +++ b/commands/create_meet.py @@ -11,7 +11,6 @@ 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): @@ -52,19 +51,31 @@ def get_state_from_postal_code(country_code: str, postal_code: str) -> str: "postalcode": postal_code, "country": country_code } + + result = { + "state": "Error: State not found :c", + "settlement": "Error: settlement not found :c" + } try: location = geolocator.geocode(query, addressdetails=True, timeout=10) if location and "address" in location.raw: address = location.raw["address"] - + state_keys = ["state", "province", "state_district", "region"] for key in state_keys: if key in address: - return address[key] + result["state"] = address[key] + break + + settlement_keys = ["village", "hamlet", "suburb", "town", "city", "municipality"] + for key in settlement_keys: + if key in address: + result["settlement"] = address[key] + break - return "Error: State not found :c" + return result except GeocoderTimedOut: return "Error: Request timed out :c" @@ -161,17 +172,23 @@ class CreateMeetupForm(discord.ui.Modal, title="Create a local meetup"): ) return - self.state = get_state_from_postal_code(self.chosen_country, self.form_postal_code.value) + result = get_state_from_postal_code(self.chosen_country, self.form_postal_code.value) + self.state = result["state"] + self.settlement = result["settlement"] 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"**State:** {self.state}\n" + + f"**City:** {self.form_postal_code.value} {self.settlement}\n" + "> \n" f"**Date:** {valid_date}\n" f"**Time:** {formatted_start} - {formatted_end}\n" + f"**Organizer:** {interaction.user.mention}\n" f"**Location:** {self.form_location.value}\n" + "-# bla bla bla bla" ), ephemeral=True, view=ConfirmInteractiveMenu() ) @@ -229,7 +246,7 @@ class CreateMeetup(commands.Cog): async def startup(self): await self.bot.wait_until_ready() - channel = await self.bot.fetch_channel(CREATE_CHANNEL_ID) + channel = await self.bot.fetch_channel(os.getenv('CREATE_MEETUP_CHANNEL_ID')) await channel.purge(limit=None, bulk=True) diff --git a/main.py b/main.py index 238dee8..710b577 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,6 @@ 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 @@ -33,6 +32,6 @@ async def load_extensions(): async def main(): async with bot: await load_extensions() - await bot.start(TOKEN) + await bot.start(os.getenv('DISCORD_TOKEN')) asyncio.run(main()) \ No newline at end of file