Skip to content

Commit

Permalink
use messages in info
Browse files Browse the repository at this point in the history
  • Loading branch information
solumath committed Apr 11, 2024
1 parent 29f27e2 commit b91695a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
26 changes: 12 additions & 14 deletions cogs/info/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ async def weather(self, inter: disnake.ApplicationCommandInteraction, place: str

place = place[:100]
if "&" in place:
await inter.edit_original_response("Takhle se žádné město určitě nejmenuje.")
await inter.edit_original_response(MessagesCZ.invalid_name)
return

url = f"http://api.openweathermap.org/data/2.5/weather?q={place}&units=metric&lang=cz&appid={token}"

res = requests.get(url, timeout=10).json()

if str(res["cod"]) == "200":
description = f"Aktuální počasí v městě {res['name']}, {res['sys']['country']}"
description = MessagesCZ.weather_description(city=res["name"], country=res["sys"]["country"])
embed = disnake.Embed(title="Počasí", description=description)
image = f"http://openweathermap.org/img/w/{res['weather'][0]['icon']}.png"
embed.set_thumbnail(url=image)
Expand All @@ -109,26 +109,24 @@ async def weather(self, inter: disnake.ApplicationCommandInteraction, place: str
wind = f"{res['wind']['speed']}m/s"
clouds = f"{res['clouds']['all']}%"
visibility = f"{res['visibility'] / 1000} km" if "visibility" in res else "bez dat"
embed.add_field(name="Počasí", value=weather, inline=False)
embed.add_field(name="Teplota", value=temp, inline=True)
embed.add_field(name="Pocitová teplota", value=feels_temp, inline=True)
embed.add_field(name="Vlhkost", value=humidity, inline=True)
embed.add_field(name="Vítr", value=wind, inline=True)
embed.add_field(name="Oblačnost", value=clouds, inline=True)
embed.add_field(name="Viditelnost", value=visibility, inline=True)
embed.add_field(name=MessagesCZ.weather, value=weather, inline=False)
embed.add_field(name=MessagesCZ.temperature, value=temp, inline=True)
embed.add_field(name=MessagesCZ.feels_like, value=feels_temp, inline=True)
embed.add_field(name=MessagesCZ.humidity, value=humidity, inline=True)
embed.add_field(name=MessagesCZ.wind, value=wind, inline=True)
embed.add_field(name=MessagesCZ.clouds, value=clouds, inline=True)
embed.add_field(name=MessagesCZ.visibility, value=visibility, inline=True)

utils.add_author_footer(embed, inter.author)

await inter.edit_original_response(embed=embed)

elif str(res["cod"]) == "404":
await inter.edit_original_response("Město nenalezeno")
await inter.edit_original_response(MessagesCZ.city_not_found)
elif str(res["cod"]) == "401":
await inter.edit_original_response("Rip token -> Rebel pls fix")
await inter.edit_original_response(MessagesCZ.token_error)
else:
await inter.edit_original_response(
f"Město nenalezeno! <:pepeGun:484470874246742018> ({res['message']})"
)
await inter.edit_original_response(MessagesCZ.no_city(result=res["message"]))

@commands.slash_command(name="kreditovy_strop", description=MessagesCZ.credit_limit_brief)
async def kreditovy_strop(self, inter: disnake.ApplicationCommandInteraction) -> None:
Expand Down
16 changes: 15 additions & 1 deletion cogs/info/messages_cz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@ class MessagesCZ(GlobalMessages):
urban_brief = "Vyhledávaní výrazu v urban slovníku"
urban_not_found = "Pro daný výraz neexistuje záznam <:sadcat:576171980118687754>"

weather_brief = "Vypíše informace o počasí ve zvoleném městě. Výchozí město je Brno."
credit_limit_brief = "Vypíše, jak to funguje s ročním kreditovým stropem."
credit_limit_info = """```cs
if ("pokazil jsem volitelný" or "Pokazil jsem aspoň 2 povinné") \n return 65
if ("Pokazil jsem 1 povinný" or "Mám průměr 2.0 nebo více než 2.0") \n return 70
if ("Mám průměr pod 1.5") \n return 80
if ("Mám průměr pod 2.0") \n return 75
```"""

# Weather / Počasí
weather_brief = "Vypíše informace o počasí ve zvoleném městě. Výchozí město je Brno."
weather_description = "Aktuální počasí v městě {city}, {country}"
invalid_name = "Takhle se žádné město určitě nejmenuje."
city_not_found = "Město nenalezeno"
token_error = "Rip token -> Rebel pls fix"
no_city = "Město nenalezeno! <:pepeGun:484470874246742018> ({result})"
weather = "Počasí"
temperature = "Teplota"
feels_like = "Pocitová teplota"
humidity = "Vlhkost"
wind = "Vítr"
clouds = "Oblačnost"
visibility = "Viditelnost"

0 comments on commit b91695a

Please sign in to comment.