Start working on food, make embeds prefer title instead of author, add custom colour for ghent university blue

pull/128/head
stijndcl 2022-08-28 20:16:36 +02:00
parent 6f0ac487cc
commit 654fbcd46b
11 changed files with 72 additions and 19 deletions

View File

@ -45,8 +45,7 @@ class Currency(commands.Cog):
async with self.client.postgres_session as session: async with self.client.postgres_session as session:
bank = await crud.get_bank(session, ctx.author.id) bank = await crud.get_bank(session, ctx.author.id)
embed = discord.Embed(colour=discord.Colour.blue()) embed = discord.Embed(title=f"{ctx.author.display_name}'s Bank", colour=discord.Colour.blue())
embed.set_author(name=f"{ctx.author.display_name}'s Bank")
embed.set_thumbnail(url=ctx.author.avatar.url) embed.set_thumbnail(url=ctx.author.avatar.url)
embed.add_field(name="Interest level", value=bank.interest_level) embed.add_field(name="Interest level", value=bank.interest_level)
@ -61,8 +60,7 @@ class Currency(commands.Cog):
async with self.client.postgres_session as session: async with self.client.postgres_session as session:
bank = await crud.get_bank(session, ctx.author.id) bank = await crud.get_bank(session, ctx.author.id)
embed = discord.Embed(colour=discord.Colour.blue()) embed = discord.Embed(title="Bank upgrades", colour=discord.Colour.blue())
embed.set_author(name="Bank upgrades")
embed.add_field( embed.add_field(
name=f"Interest ({bank.interest_level})", value=str(interest_upgrade_price(bank.interest_level)) name=f"Interest ({bank.interest_level})", value=str(interest_upgrade_price(bank.interest_level))

View File

@ -10,13 +10,12 @@ from didier import Didier
class CustomHelpCommand(commands.MinimalHelpCommand): class CustomHelpCommand(commands.MinimalHelpCommand):
"""Customised Help command to override the default implementation """Customised Help command to override the default implementation
The default is ugly as hell so we do some fiddling with it The default is ugly as hell, so we do some fiddling with it
""" """
def _help_embed_base(self, title: str) -> discord.Embed: def _help_embed_base(self, title: str) -> discord.Embed:
"""Create the base structure for the embeds that get sent with the Help commands""" """Create the base structure for the embeds that get sent with the Help commands"""
embed = discord.Embed(colour=discord.Colour.blue()) embed = discord.Embed(title=title, colour=discord.Colour.blue())
embed.set_author(name=title)
embed.set_footer(text="Syntax: Didier Help [Categorie] of Didier Help [Commando]") embed.set_footer(text="Syntax: Didier Help [Categorie] of Didier Help [Commando]")
return embed return embed

View File

@ -0,0 +1,15 @@
from datetime import datetime
from aiohttp import ClientSession
from didier.data.embeds.hydra import Menu
from didier.utils.http.requests import ensure_get
__all__ = ["fetch_menu"]
async def fetch_menu(http_session: ClientSession, day_dt: datetime) -> Menu:
"""Fetch the menu for a given day"""
endpoint = f"https://hydra.ugent.be/api/2.0/resto/menu/nl/{day_dt.year}/{day_dt.month}/{day_dt.day}.json"
async with ensure_get(http_session, endpoint) as response:
return Menu.parse_obj(response)

View File

@ -23,8 +23,7 @@ class Deadlines(EmbedBaseModel):
@overrides @overrides
def to_embed(self, **kwargs: dict) -> discord.Embed: def to_embed(self, **kwargs: dict) -> discord.Embed:
embed = discord.Embed(colour=discord.Colour.dark_gold()) embed = discord.Embed(title="Upcoming Deadlines", colour=discord.Colour.dark_gold())
embed.set_author(name="Upcoming Deadlines")
now = tz_aware_now() now = tz_aware_now()
has_active_deadlines = False has_active_deadlines = False

View File

@ -37,8 +37,7 @@ def create_error_embed(ctx: commands.Context, exception: Exception) -> discord.E
invocation = f"{ctx.author.display_name} in {origin}" invocation = f"{ctx.author.display_name} in {origin}"
embed = discord.Embed(colour=discord.Colour.red()) embed = discord.Embed(title="Error", colour=discord.Colour.red())
embed.set_author(name="Error")
embed.add_field(name="Command", value=f"{ctx.message.content}", inline=True) embed.add_field(name="Command", value=f"{ctx.message.content}", inline=True)
embed.add_field(name="Context", value=invocation, inline=True) embed.add_field(name="Context", value=invocation, inline=True)
embed.add_field(name="Exception", value=abbreviate(str(exception), Limits.EMBED_FIELD_VALUE_LENGTH), inline=False) embed.add_field(name="Exception", value=abbreviate(str(exception), Limits.EMBED_FIELD_VALUE_LENGTH), inline=False)

View File

@ -19,8 +19,7 @@ class GoogleSearch(EmbedBaseModel):
def _error_embed(self) -> discord.Embed: def _error_embed(self) -> discord.Embed:
"""Custom embed for unsuccessful requests""" """Custom embed for unsuccessful requests"""
embed = discord.Embed(colour=discord.Colour.red()) embed = discord.Embed(title="Google Search", colour=discord.Colour.red())
embed.set_author(name="Google Search")
# Empty embed # Empty embed
if not self.data.results: if not self.data.results:
@ -37,8 +36,7 @@ class GoogleSearch(EmbedBaseModel):
if not self.data.results or self.data.status_code != HTTPStatus.OK: if not self.data.results or self.data.status_code != HTTPStatus.OK:
return self._error_embed() return self._error_embed()
embed = discord.Embed(colour=discord.Colour.blue()) embed = discord.Embed(title="Google Search", colour=discord.Colour.blue())
embed.set_author(name="Google Search")
embed.set_footer(text=self.data.result_stats or None) embed.set_footer(text=self.data.result_stats or None)
# Add all results into the description # Add all results into the description

View File

@ -0,0 +1,3 @@
from .menu import Menu
__all__ = ["Menu"]

View File

@ -0,0 +1,34 @@
from typing import Literal, Optional
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
__all__ = ["Menu"]
class _Meal(BaseModel):
"""Model for an item on the menu"""
kind: Literal["meat", "fish", "soup", "vegetarian", "vegan"]
name: str
price: str
type: Literal["main", "side"]
class Menu(EmbedPydantic):
"""Embed that shows the menu in Ghent University restaurants"""
meals: list[_Meal] = []
open: bool
vegetables: list[str] = []
message: Optional[str] = None
@overrides
def to_embed(self, **kwargs: dict) -> discord.Embed:
embed = discord.Embed(title="Menu", colour=ghent_university_blue())
return embed

View File

@ -15,6 +15,7 @@ import settings
from database.crud import ufora_announcements as crud from database.crud import ufora_announcements as crud
from database.schemas.relational import UforaCourse from database.schemas.relational import UforaCourse
from didier.data.embeds.base import EmbedBaseModel from didier.data.embeds.base import EmbedBaseModel
from didier.utils.discord.colours import ghent_university_blue
from didier.utils.types.datetime import int_to_weekday from didier.utils.types.datetime import int_to_weekday
from didier.utils.types.string import leading from didier.utils.types.string import leading
@ -49,7 +50,7 @@ class UforaNotification(EmbedBaseModel):
def to_embed(self, **kwargs: dict) -> discord.Embed: def to_embed(self, **kwargs: dict) -> discord.Embed:
"""Turn the notification into an embed""" """Turn the notification into an embed"""
embed = discord.Embed(colour=discord.Colour.from_rgb(30, 100, 200)) embed = discord.Embed(title=self._title, colour=ghent_university_blue())
embed.set_author(name=self.course.name) embed.set_author(name=self.course.name)
embed.title = self._title embed.title = self._title

View File

@ -47,8 +47,7 @@ class Definition(EmbedPydantic):
@overrides @overrides
def to_embed(self, **kwargs: dict) -> discord.Embed: def to_embed(self, **kwargs: dict) -> discord.Embed:
embed = discord.Embed(colour=colours.urban_dictionary_green()) embed = discord.Embed(title="Urban Dictionary", colour=colours.urban_dictionary_green())
embed.set_author(name="Urban Dictionary")
embed.add_field(name="Term", value=self.word, inline=True) embed.add_field(name="Term", value=self.word, inline=True)
embed.add_field(name="Author", value=self.author, inline=True) embed.add_field(name="Author", value=self.author, inline=True)

View File

@ -1,6 +1,14 @@
import discord import discord
__all__ = ["urban_dictionary_green"] __all__ = ["ghent_university_blue", "ghent_university_yellow", "urban_dictionary_green"]
def ghent_university_blue() -> discord.Colour:
return discord.Colour.from_rgb(30, 100, 200)
def ghent_university_yellow() -> discord.Colour:
return discord.Colour.from_rgb(255, 210, 0)
def urban_dictionary_green() -> discord.Colour: def urban_dictionary_green() -> discord.Colour: