settlement and formating
This commit is contained in:
1 parent
9cd6f160f9
commit
7882ba4915
3 files changed
+31
-10
No files matched your search
+6
-1
@@ -1,3 +1,8 @@
|
|||||||
DISCORD_TOKEN=""
|
DISCORD_TOKEN=""
|
||||||
|
|
||||||
CREATE_CHANNEL_ID=
|
CREATE_MEETUP_CHANNEL_ID=
|
||||||
|
DE_MEETUP_CHANNEL_ID=
|
||||||
|
AT_MEETUP_CHANNEL_ID=
|
||||||
|
CH_MEETUP_CHANNEL_ID=
|
||||||
|
US_MEETUP_CHANNEL_ID=
|
||||||
|
UK_MEETUP_CHANNEL_ID=
|
||||||
+24
-7
@@ -11,7 +11,6 @@ from datetime import datetime
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
CREATE_CHANNEL_ID = os.getenv('CREATE_CHANNEL_ID')
|
|
||||||
|
|
||||||
class ConfirmInteractiveMenu(discord.ui.View):
|
class ConfirmInteractiveMenu(discord.ui.View):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -52,19 +51,31 @@ def get_state_from_postal_code(country_code: str, postal_code: str) -> str:
|
|||||||
"postalcode": postal_code,
|
"postalcode": postal_code,
|
||||||
"country": country_code
|
"country": country_code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = {
|
||||||
|
"state": "Error: State not found :c",
|
||||||
|
"settlement": "Error: settlement not found :c"
|
||||||
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
location = geolocator.geocode(query, addressdetails=True, timeout=10)
|
location = geolocator.geocode(query, addressdetails=True, timeout=10)
|
||||||
|
|
||||||
if location and "address" in location.raw:
|
if location and "address" in location.raw:
|
||||||
address = location.raw["address"]
|
address = location.raw["address"]
|
||||||
|
|
||||||
state_keys = ["state", "province", "state_district", "region"]
|
state_keys = ["state", "province", "state_district", "region"]
|
||||||
for key in state_keys:
|
for key in state_keys:
|
||||||
if key in address:
|
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:
|
except GeocoderTimedOut:
|
||||||
return "Error: Request timed out :c"
|
return "Error: Request timed out :c"
|
||||||
@@ -161,17 +172,23 @@ class CreateMeetupForm(discord.ui.Modal, title="Create a local meetup"):
|
|||||||
)
|
)
|
||||||
return
|
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(
|
await interaction.response.send_message(
|
||||||
content=(
|
content=(
|
||||||
"## Event Register Preview\n"
|
"## Event Register Preview\n"
|
||||||
f"**Country:** {self.chosen_country}\n"
|
f"**Country:** {self.chosen_country}\n"
|
||||||
f"**Postal Code:** {self.form_postal_code.value}\n"
|
|
||||||
f"**State:** {self.state}\n"
|
f"**State:** {self.state}\n"
|
||||||
|
|
||||||
|
f"**City:** {self.form_postal_code.value} {self.settlement}\n"
|
||||||
|
"> \n"
|
||||||
f"**Date:** {valid_date}\n"
|
f"**Date:** {valid_date}\n"
|
||||||
f"**Time:** {formatted_start} - {formatted_end}\n"
|
f"**Time:** {formatted_start} - {formatted_end}\n"
|
||||||
|
f"**Organizer:** {interaction.user.mention}\n"
|
||||||
f"**Location:** {self.form_location.value}\n"
|
f"**Location:** {self.form_location.value}\n"
|
||||||
|
"-# bla bla bla bla"
|
||||||
),
|
),
|
||||||
ephemeral=True, view=ConfirmInteractiveMenu()
|
ephemeral=True, view=ConfirmInteractiveMenu()
|
||||||
)
|
)
|
||||||
@@ -229,7 +246,7 @@ class CreateMeetup(commands.Cog):
|
|||||||
async def startup(self):
|
async def startup(self):
|
||||||
await self.bot.wait_until_ready()
|
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)
|
await channel.purge(limit=None, bulk=True)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from discord.ext import commands
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
TOKEN = os.getenv('DISCORD_TOKEN')
|
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
@@ -33,6 +32,6 @@ async def load_extensions():
|
|||||||
async def main():
|
async def main():
|
||||||
async with bot:
|
async with bot:
|
||||||
await load_extensions()
|
await load_extensions()
|
||||||
await bot.start(TOKEN)
|
await bot.start(os.getenv('DISCORD_TOKEN'))
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
Reference in new issue
Block a user