Skip to content

Commit

Permalink
There
Browse files Browse the repository at this point in the history
  • Loading branch information
JDJGInc authored Jul 29, 2024
1 parent 4265f99 commit d54318d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 306 deletions.
38 changes: 24 additions & 14 deletions cogs/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import typing
import zoneinfo

from babel.numbers import format_decimal
import discord
from discord import app_commands
from discord.app_commands import Choice
from discord.ext import commands

from local_utils import Speed, Temperature, locale_choices
from local_utils import Speed, Temperature, locale_choices, get_locale_timezones
from utils import fuzzy

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -65,10 +66,11 @@ async def convert_temperature(
else:
color = 0xFF0000

temp_celsius = f"{temps.celsius:,}"
temp_fahrenheit = f"{temps.fahrenheit:,}"
temp_kelvin = f"{temps.kelvin:,}"
temp_rankine = f"{temps.rankine:,}"
cleaned_locale = interaction.locale.value.replace("-", "_")
temp_celsius = format_decimal(temps.celsius, format="#,##0.0", locale=cleaned_locale)
temp_fahrenheit = format_decimal(temps.fahrenheit, format="#,##0.0", locale=cleaned_locale)
temp_kelvin = format_decimal(temps.kelvin, format="#,##0.0", locale=cleaned_locale)
temp_rankine = format_decimal(temps.rankine, format="#,##0.0", locale=cleaned_locale)

temperature_unit_value = (
await interaction.client.tree.translator.translate_choice_name_from_locale_key(
Expand Down Expand Up @@ -171,12 +173,13 @@ async def convert_speed(self, interaction: discord.Interaction, speed_unit: app_
color = 0x0
# pure black for emphasis.

speeds_miles = f"{speeds.miles:,}"
speeds_kilometers = f"{speeds.kilometers:,}"
speeds_meters = f"{speeds.meters:,}"
speeds_feet = f"{speeds.feet:,}"
speeds_megameters = f"{speeds.megameters:,}"
speeds_light = f"{speeds.light:,}"
cleaned_locale = interaction.locale.value.replace("-", "_")
speeds_miles = format_decimal(speeds.miles, format="#,##0.0", locale=cleaned_locale)
speeds_kilometers = format_decimal(speeds.kilometers, format="#,##0.0", locale=cleaned_locale)
speeds_meters = format_decimal(speeds.meters, format="#,##0.0", locale=cleaned_locale)
speeds_feet = format_decimal(speeds.feet, format="#,##0.0", locale=cleaned_locale)
speeds_megameters = format_decimal(speeds.megameters, format="#,##0.00", locale=cleaned_locale)
speeds_light = format_decimal(speeds.light, format="#,##0.00", locale=cleaned_locale)

speed_unit_value = (
await interaction.client.tree.translator.translate_choice_name_from_locale_key(
Expand Down Expand Up @@ -261,13 +264,20 @@ async def convert_timezone(self, interaction: discord.Interaction, timezone: typ
async def convert_timezone_autocomplete(self, interaction: discord.Interaction, current: str) -> list[Choice]:

timezones = self.available_timezones
all_choices = [Choice(name=timezone, value=timezone) for timezone in timezones]
timezones_dictionary = dict([(timezone, timezone) for timezone in timezones])
localized_timezones = await asyncio.to_thread(get_locale_timezones, interaction.locale, timezones)
localized_timezones = localized_timezones | timezones_dictionary
# combines the two dictionaries

all_choices = [
Choice(name=timezone, value=timezone_value) for timezone, timezone_value in localized_timezones.items()
]

if not (current):
return all_choices[0:25]

filtered_results = fuzzy.finder(current, timezones)
results = [Choice(name=result, value=result) for result in filtered_results]
filtered_results = fuzzy.finder(current, localized_timezones.keys())
results = [Choice(name=result, value=localized_timezones[result]) for result in filtered_results]

return results[0:25]

Expand Down
292 changes: 0 additions & 292 deletions extra.py

This file was deleted.

0 comments on commit d54318d

Please sign in to comment.