Add slash command, support multiple restos & add date to embed

pull/95/head
Stijn De Clercq 2021-09-26 22:12:52 +02:00
parent aae5616488
commit 73cc6aa0e9
4 changed files with 95 additions and 22 deletions

View File

@ -1,4 +1,5 @@
from data import schedule
from data.embeds.food import Menu
from decorators import help
import discord
from discord.ext import commands
@ -21,27 +22,7 @@ class School(commands.Cog):
# @commands.check(checks.allowedChannels)
@help.Category(category=Category.School)
async def eten(self, ctx, day: str = None):
day_dt = les.find_target_date(day if day else None)
day_dt = skip_weekends(day_dt)
day = intToWeekday(day_dt.weekday())
# Create embed
menu = eten.etenScript(day_dt)
embed = discord.Embed(colour=discord.Colour.blue())
embed.set_author(name="Menu voor {}".format(day.lower()))
if "gesloten" in menu[0].lower():
embed.description = "Restaurant gesloten"
else:
embed.add_field(name="🥣 Soep:", value=menu[0], inline=False)
embed.add_field(name="🍴 Hoofdgerechten:", value=menu[1], inline=False)
if menu[2]:
embed.add_field(name="❄️ Koud:", value=menu[2], inline=False)
if menu[3]:
embed.add_field(name="🥦 Groenten:", value=menu[3], inline=False)
embed = Menu(day).to_embed()
await ctx.reply(embed=embed, mention_author=False)
@commands.command(name="Les", aliases=["Class", "Classes", "Sched", "Schedule"], usage="[Dag]*")

View File

@ -0,0 +1,37 @@
from discord.ext import commands
from dislash import SlashInteraction, slash_command, Option, OptionType, OptionChoice
from data.embeds.food import Menu, restos
from startup.didier import Didier
class SchoolSlash(commands.Cog):
def __init__(self, client: Didier):
self.client: Didier = client
@slash_command(
name="eten",
description="Menu voor een bepaalde resto op een bepaalde dag",
options=[
Option(
"dag",
description="Dag",
type=OptionType.STRING
),
Option(
"resto",
description="Resto",
type=OptionType.STRING,
choices=list(
OptionChoice(v, k) for k, v in restos.items()
)
)
]
)
async def _food_slash(self, interaction: SlashInteraction, dag: str = None, resto: str = "sterre"):
embed = Menu(dag, resto).to_embed()
await interaction.reply(embed=embed)
def setup(client: Didier):
client.add_cog(SchoolSlash(client))

View File

@ -0,0 +1,55 @@
from dataclasses import dataclass, field
from datetime import datetime
from typing import Optional, Tuple, Dict
import discord
from functions import les, eten
from functions.timeFormatters import skip_weekends, intToWeekday
from functions.stringFormatters import leading_zero as lz
restos: Dict[str, str] = {
"ardoyen": "Ardoyen",
"coupure": "Coupure",
"debrug": "De Brug",
"dunant": "Dunant",
"heymans": "Heymans",
"kantienberg": "Kantienberg",
"merelbeke": "Merelbeke",
"sterre": "Sterre"
}
@dataclass
class Menu:
day: Optional[str] = None
resto: str = "sterre"
_day: datetime = field(init=False)
_menu: Tuple[str, str, str, str] = field(init=False)
def __post_init__(self):
self._day = les.find_target_date(self.day if self.day else None)
self._day = skip_weekends(self._day)
self.day = intToWeekday(self._day.weekday())
self._menu = eten.etenScript(self._day)
def to_embed(self) -> discord.Embed:
embed = discord.Embed(colour=discord.Colour.blue())
date_formatted = f"{lz(self._day.day)}/{lz(self._day.month)}/{self._day.year}"
embed.set_author(name=f"Menu voor {self.day.lower()} {date_formatted}")
embed.title = f"Resto {restos[self.resto]}"
if "gesloten" in self._menu[0].lower():
embed.description = "Restaurant gesloten"
else:
embed.add_field(name="🥣 Soep:", value=self._menu[0], inline=False)
embed.add_field(name="🍴 Hoofdgerechten:", value=self._menu[1], inline=False)
if self._menu[2]:
embed.add_field(name="❄️ Koud:", value=self._menu[2], inline=False)
if self._menu[3]:
embed.add_field(name="🥦 Groenten:", value=self._menu[3], inline=False)
return embed

View File

@ -49,7 +49,7 @@ def etenScript(dag: datetime, resto: str = "sterre"):
for v in menu["vegetables"]:
menuGroenten += ("* {}\n".format(v))
except Exception as e:
except Exception:
menuSoep += "Restaurant gesloten"
menuGroenten += "Restaurant gesloten"
menuHoofdgerechten += "Restaurant gesloten"