settlement and formating
This commit is contained in:
1 parent
9cd6f160f9
commit
7882ba4915
3 files changed
+31
-10
No files matched your search
+24
-7
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user