mirror of https://github.com/stijndcl/didier
Menu message & slash commands
parent
0186a0793a
commit
b581c3e5dc
|
@ -33,14 +33,19 @@ class School(commands.Cog):
|
|||
await ctx.reply(embed=embed, mention_author=False, ephemeral=False)
|
||||
|
||||
@commands.hybrid_command(
|
||||
name="menu", description="Show the menu in the Ghent University restaurants", aliases=["Eten", "Food"]
|
||||
name="menu",
|
||||
description="Show the menu in the Ghent University restaurants.",
|
||||
aliases=["Eten", "Food"],
|
||||
)
|
||||
async def menu(self, ctx: commands.Context, day: Optional[str] = None):
|
||||
"""Get the menu for a given day in the restaurants"""
|
||||
"""Show the menu in the Ghent University restaurants.
|
||||
|
||||
Menus are Dutch, as a lot of dishes have very weird translations
|
||||
"""
|
||||
# TODO time converter (transformer) for [DAY]
|
||||
# TODO autocompletion for [DAY]
|
||||
async with ctx.typing():
|
||||
day_dt = datetime.now()
|
||||
day_dt = datetime(year=2022, month=8, day=29)
|
||||
|
||||
try:
|
||||
menu = await fetch_menu(self.client.http_session, day_dt)
|
||||
|
|
|
@ -1,25 +1,40 @@
|
|||
from datetime import datetime
|
||||
from typing import Literal, Optional, cast
|
||||
from enum import Enum
|
||||
from typing import Optional, cast
|
||||
|
||||
import discord
|
||||
from overrides import overrides
|
||||
from pydantic import BaseModel
|
||||
|
||||
from didier.data.embeds.base import EmbedPydantic
|
||||
from didier.utils.discord.colours import ghent_university_blue
|
||||
from didier.utils.discord.colours import ghent_university_blue, ghent_university_yellow
|
||||
from didier.utils.types.datetime import int_to_weekday
|
||||
from didier.utils.types.string import leading
|
||||
|
||||
__all__ = ["Menu", "no_menu_found"]
|
||||
|
||||
|
||||
class _MealKind(str, Enum):
|
||||
FISH = "fish"
|
||||
MEAT = "meat"
|
||||
SOUP = "soup"
|
||||
VEGAN = "vegan"
|
||||
VEGETARIAN = "vegetarian"
|
||||
|
||||
|
||||
class _MealType(str, Enum):
|
||||
COLD = "cold"
|
||||
MAIN = "main"
|
||||
SIDE = "side"
|
||||
|
||||
|
||||
class _Meal(BaseModel):
|
||||
"""Model for an item on the menu"""
|
||||
|
||||
kind: Literal["meat", "fish", "soup", "vegetarian", "vegan"]
|
||||
kind: _MealKind
|
||||
name: str
|
||||
price: str
|
||||
type: Literal["cold", "main", "side"]
|
||||
type: _MealType
|
||||
|
||||
|
||||
class Menu(EmbedPydantic):
|
||||
|
@ -30,6 +45,64 @@ class Menu(EmbedPydantic):
|
|||
vegetables: list[str] = []
|
||||
message: Optional[str] = None
|
||||
|
||||
def _get_dutch_meal_prefix(self, meal: _Meal) -> str:
|
||||
if meal.kind == _MealKind.MEAT:
|
||||
prefix = "Vlees"
|
||||
elif meal.kind == _MealKind.FISH:
|
||||
prefix = "Vis"
|
||||
elif meal.kind == _MealKind.VEGETARIAN:
|
||||
prefix = "Vegetarisch"
|
||||
else:
|
||||
prefix = "Vegan"
|
||||
|
||||
return prefix
|
||||
|
||||
def _get_soups(self) -> str:
|
||||
acc = ""
|
||||
|
||||
for meal in self.meals:
|
||||
if meal.kind == _MealKind.SOUP:
|
||||
acc += f"{meal.name} ({meal.price})\n"
|
||||
|
||||
return acc.strip()
|
||||
|
||||
def _get_main_courses(self) -> str:
|
||||
acc = ""
|
||||
|
||||
for meal in self.meals:
|
||||
if meal.type != _MealType.MAIN:
|
||||
continue
|
||||
|
||||
prefix = self._get_dutch_meal_prefix(meal)
|
||||
|
||||
acc += f"* {prefix}: {meal.name} ({meal.price})\n"
|
||||
|
||||
return acc.strip()
|
||||
|
||||
def _get_cold_meals(self) -> str:
|
||||
acc = ""
|
||||
|
||||
for meal in self.meals:
|
||||
if meal.type == _MealType.COLD:
|
||||
acc += f"* {self._get_dutch_meal_prefix(meal)}: {meal.name} ({meal.price})\n"
|
||||
|
||||
return acc.strip()
|
||||
|
||||
def _closed_embed(self, embed: discord.Embed) -> discord.Embed:
|
||||
embed.colour = ghent_university_yellow()
|
||||
embed.description = "The restaurants are closed today."
|
||||
return embed
|
||||
|
||||
def _regular_embed(self, embed: discord.Embed) -> discord.Embed:
|
||||
embed.add_field(name="🥣 Soep", value=self._get_soups(), inline=False)
|
||||
embed.add_field(name="🍴 Hoofdgerechten", value=self._get_main_courses(), inline=False)
|
||||
embed.add_field(name="❄️Koud", value=self._get_cold_meals(), inline=False)
|
||||
|
||||
vegetables = "\n".join(list(sorted(self.vegetables)))
|
||||
embed.add_field(name="🥦 Groenten", value=vegetables, inline=False)
|
||||
|
||||
return embed
|
||||
|
||||
@overrides
|
||||
def to_embed(self, **kwargs) -> discord.Embed:
|
||||
day_dt: datetime = cast(datetime, kwargs.get("day_dt"))
|
||||
|
@ -38,6 +111,11 @@ class Menu(EmbedPydantic):
|
|||
|
||||
embed = discord.Embed(title=f"Menu - {weekday} {formatted_date}", colour=ghent_university_blue())
|
||||
|
||||
embed = self._regular_embed(embed) if self.open else self._closed_embed(embed)
|
||||
|
||||
if self.message:
|
||||
embed.add_field(name="📣 Extra Mededeling", value=self.message, inline=False)
|
||||
|
||||
return embed
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue