diff --git a/didier/cogs/school.py b/didier/cogs/school.py index 5aca554..f8a0d1b 100644 --- a/didier/cogs/school.py +++ b/didier/cogs/school.py @@ -44,9 +44,6 @@ class School(commands.Cog): Menus are Dutch, as a lot of dishes have very weird translations """ - if day_dt is None: - day_dt = date.today() - async with ctx.typing(): try: menu = await fetch_menu(self.client.http_session, day_dt) diff --git a/didier/data/embeds/google/google_search.py b/didier/data/embeds/google/google_search.py index f2a58b1..dd0383b 100644 --- a/didier/data/embeds/google/google_search.py +++ b/didier/data/embeds/google/google_search.py @@ -5,7 +5,6 @@ from overrides import overrides from didier.data.embeds.base import EmbedBaseModel from didier.data.scrapers.google import SearchData -from didier.utils.discord.colours import google_blue __all__ = ["GoogleSearch"] @@ -37,7 +36,7 @@ class GoogleSearch(EmbedBaseModel): if not self.data.results or self.data.status_code != HTTPStatus.OK: return self._error_embed() - embed = discord.Embed(title="Google Search", colour=google_blue()) + embed = discord.Embed(title="Google Search", colour=discord.Colour.blue()) embed.set_footer(text=self.data.result_stats or None) # Add all results into the description diff --git a/didier/data/embeds/hydra/menu.py b/didier/data/embeds/hydra/menu.py index 9212d70..8d1e8d4 100644 --- a/didier/data/embeds/hydra/menu.py +++ b/didier/data/embeds/hydra/menu.py @@ -94,17 +94,12 @@ class Menu(EmbedPydantic): return embed def _regular_embed(self, embed: discord.Embed) -> discord.Embed: - if soups := self._get_soups(): - embed.add_field(name="🥣 Soep", value=soups, inline=False) + 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) - if mains := self._get_main_courses(): - embed.add_field(name="🍴 Hoofdgerechten", value=mains, inline=False) - - if cold := self._get_cold_meals(): - embed.add_field(name="❄️Koud", value=cold, inline=False) - - if vegetables := "\n".join(list(sorted(self.vegetables))): - embed.add_field(name="🥦 Groenten", value=vegetables, inline=False) + vegetables = "\n".join(list(sorted(self.vegetables))) + embed.add_field(name="🥦 Groenten", value=vegetables, inline=False) return embed diff --git a/didier/utils/discord/colours.py b/didier/utils/discord/colours.py index 5e69d3e..7c26769 100644 --- a/didier/utils/discord/colours.py +++ b/didier/utils/discord/colours.py @@ -1,6 +1,6 @@ import discord -__all__ = ["ghent_university_blue", "ghent_university_yellow", "google_blue", "urban_dictionary_green"] +__all__ = ["ghent_university_blue", "ghent_university_yellow", "urban_dictionary_green"] def ghent_university_blue() -> discord.Colour: @@ -11,9 +11,5 @@ def ghent_university_yellow() -> discord.Colour: return discord.Colour.from_rgb(255, 210, 0) -def google_blue() -> discord.Colour: - return discord.Colour.from_rgb(66, 133, 244) - - def urban_dictionary_green() -> discord.Colour: return discord.Colour.from_rgb(220, 255, 0) diff --git a/didier/utils/discord/converters/time.py b/didier/utils/discord/converters/time.py index 2a328f9..6fbad9a 100644 --- a/didier/utils/discord/converters/time.py +++ b/didier/utils/discord/converters/time.py @@ -5,7 +5,7 @@ from typing import Optional, Union import discord from discord import app_commands -from discord.ext import commands +from discord.ext.commands import ArgumentParsingError from overrides import overrides from didier.utils.discord.autocompletion.time import autocomplete_day @@ -15,7 +15,7 @@ from didier.utils.types.datetime import ( str_to_weekday, ) -__all__ = ["date_converter", "DateTransformer"] +__all__ = ["date_converter"] def date_converter(argument: Optional[str]) -> date: @@ -50,13 +50,12 @@ def date_converter(argument: Optional[str]) -> date: return parse_dm_string(argument) # Unparseable - raise commands.ArgumentParsingError(f"Unable to interpret `{original_argument}` as a date.") + raise ArgumentParsingError(f"Unable to interpret `{original_argument}` as a date.") class DateTransformer(app_commands.Transformer): """Application commands transformer for dates""" - @overrides async def autocomplete( self, interaction: discord.Interaction, value: Union[int, float, str] ) -> list[app_commands.Choice[Union[int, float, str]]]: diff --git a/didier/utils/types/datetime.py b/didier/utils/types/datetime.py index 7372118..07ad29a 100644 --- a/didier/utils/types/datetime.py +++ b/didier/utils/types/datetime.py @@ -25,7 +25,7 @@ def forward_to_next_weekday(day_dt: DateType, target_weekday: int, *, allow_toda raise ValueError # Skip at least one day - if not allow_today and day_dt.weekday() == target_weekday: + if not allow_today: day_dt += datetime.timedelta(days=1) while day_dt.weekday() != target_weekday: @@ -69,16 +69,16 @@ def parse_dm_string(argument: str) -> datetime.date: raise ValueError # Day Month - match = re.search(r"\d+", spl[0]) + match = re.search(r"\d+", spl[0]).group() if match is not None: - day = int(match.group()) + day = int(match) month = str_to_month(spl[1]) return datetime.date(day=day, month=month, year=today.year) # Month Day - match = re.search(r"\d+", spl[1]) + match = re.search(r"\d+", spl[0]).group() if match is not None: - day = int(match.group()) + day = int(match) month = str_to_month(spl[0]) return datetime.date(day=day, month=month, year=today.year) diff --git a/readme.md b/readme.md index 0fad8b6..e2340c6 100644 --- a/readme.md +++ b/readme.md @@ -38,8 +38,6 @@ docker compose -f docker-compose.test.yml up -d ### Commands -_All of these are Python tools. Depending on your OS and configuration, you may have to prefix them with `python3 -m`._ - ```shell # Starting Didier python3 main.py diff --git a/requirements.txt b/requirements.txt index b064107..d72584a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ aiohttp==3.8.1 alembic==1.8.0 asyncpg==0.25.0 beautifulsoup4==4.11.1 -discord.py==2.0.1 +discord.py==2.0.0 environs==9.5.0 feedparser==6.0.10 markdownify==0.11.2 diff --git a/tests/test_didier/test_utils/test_discord/test_converters/test_time.py b/tests/test_didier/test_utils/test_discord/test_converters/test_time.py deleted file mode 100644 index 8407ea4..0000000 --- a/tests/test_didier/test_utils/test_discord/test_converters/test_time.py +++ /dev/null @@ -1,131 +0,0 @@ -from datetime import date - -from freezegun import freeze_time - -from didier.utils.discord.converters.time import date_converter - - -@freeze_time("2022-08-20") -def test_date_converter_empty_returns_today(): - """Test that the date converter returns today by default""" - result = date_converter(None) - assert result == date.today() - - result = date_converter("") - assert result == date.today() - - -@freeze_time("2022-08-20") -def test_date_converter_keywords_tomorrow(): - """Test that the date converter works correctly for +1-offset keywords""" - result = date_converter("tomorrow") - assert (result.day, result.month, result.year) == (21, 8, 2022) - - result = date_converter("tmrw") - assert (result.day, result.month, result.year) == (21, 8, 2022) - - result = date_converter("morgen") - assert (result.day, result.month, result.year) == (21, 8, 2022) - - -@freeze_time("2022-08-20") -def test_date_converter_keywords_two_days(): - """Test that the date converter works correctly for +2-offset keywords""" - result = date_converter("overmorgen") - assert (result.day, result.month, result.year) == (22, 8, 2022) - - -@freeze_time("2022-08-20") # This is a Saturday -def test_date_converter_weekdays_english(): - """Test that the date converter works correctly for weekdays (English version)""" - # Full - result = date_converter("monday") - assert (result.day, result.month, result.year) == (22, 8, 2022) - - result = date_converter("tuesday") - assert (result.day, result.month, result.year) == (23, 8, 2022) - - result = date_converter("wednesday") - assert (result.day, result.month, result.year) == (24, 8, 2022) - - result = date_converter("thursday") - assert (result.day, result.month, result.year) == (25, 8, 2022) - - result = date_converter("friday") - assert (result.day, result.month, result.year) == (26, 8, 2022) - - result = date_converter("saturday") - assert (result.day, result.month, result.year) == (27, 8, 2022) - - result = date_converter("sunday") - assert (result.day, result.month, result.year) == (21, 8, 2022) - - # Abbreviated - result = date_converter("mon") - assert (result.day, result.month, result.year) == (22, 8, 2022) - - result = date_converter("tue") - assert (result.day, result.month, result.year) == (23, 8, 2022) - - result = date_converter("wed") - assert (result.day, result.month, result.year) == (24, 8, 2022) - - result = date_converter("thu") - assert (result.day, result.month, result.year) == (25, 8, 2022) - - result = date_converter("fri") - assert (result.day, result.month, result.year) == (26, 8, 2022) - - result = date_converter("sat") - assert (result.day, result.month, result.year) == (27, 8, 2022) - - result = date_converter("sun") - assert (result.day, result.month, result.year) == (21, 8, 2022) - - -@freeze_time("2022-08-20") # This is a Saturday -def test_date_converter_weekdays_dutch(): - """Test that the date converter works correctly for weekdays (Dutch version)""" - # Full - result = date_converter("maandag") - assert (result.day, result.month, result.year) == (22, 8, 2022) - - result = date_converter("dinsdag") - assert (result.day, result.month, result.year) == (23, 8, 2022) - - result = date_converter("woensdag") - assert (result.day, result.month, result.year) == (24, 8, 2022) - - result = date_converter("donderdag") - assert (result.day, result.month, result.year) == (25, 8, 2022) - - result = date_converter("vrijdag") - assert (result.day, result.month, result.year) == (26, 8, 2022) - - result = date_converter("zaterdag") - assert (result.day, result.month, result.year) == (27, 8, 2022) - - result = date_converter("zondag") - assert (result.day, result.month, result.year) == (21, 8, 2022) - - # Abbreviated - result = date_converter("ma") - assert (result.day, result.month, result.year) == (22, 8, 2022) - - result = date_converter("di") - assert (result.day, result.month, result.year) == (23, 8, 2022) - - result = date_converter("woe") - assert (result.day, result.month, result.year) == (24, 8, 2022) - - result = date_converter("do") - assert (result.day, result.month, result.year) == (25, 8, 2022) - - result = date_converter("vrij") - assert (result.day, result.month, result.year) == (26, 8, 2022) - - result = date_converter("za") - assert (result.day, result.month, result.year) == (27, 8, 2022) - - result = date_converter("zo") - assert (result.day, result.month, result.year) == (21, 8, 2022) diff --git a/tests/test_didier/test_utils/test_types/test_datetime.py b/tests/test_didier/test_utils/test_types/test_datetime.py index 289285b..ecb1973 100644 --- a/tests/test_didier/test_utils/test_types/test_datetime.py +++ b/tests/test_didier/test_utils/test_types/test_datetime.py @@ -1,55 +1,8 @@ import datetime import pytest -from freezegun import freeze_time -from didier.utils.types.datetime import parse_dm_string, str_to_date - - -@freeze_time("2022-08-20") -def test_parse_dm_string_ddmm(): - """Test parsing DD/MM""" - result = parse_dm_string("23/08") - assert (result.day, result.month, result.year) == (23, 8, 2022) - - result = parse_dm_string("8/9") - assert (result.day, result.month, result.year) == (8, 9, 2022) - - -def test_parse_dm_string_dm_too_long_raises(): - """Test parsing DD/MM format when something longer is passed in""" - with pytest.raises(ValueError): - parse_dm_string("23/08/2022") - - -def test_parse_dm_string_dm_garbage(): - """Test parsing DD/MM format when something invalid is passed in""" - with pytest.raises(ValueError): - parse_dm_string("AC/DC") - - -def test_parse_dm_string_semantic(): - """Test parsing date strings in the [DAY] [MONTH] and [MONTH] [DAY] formats""" - result = parse_dm_string("23rd november") - assert (result.day, result.month, result.year) == (23, 11, 2022) - - result = parse_dm_string("23 nov") - assert (result.day, result.month, result.year) == (23, 11, 2022) - - result = parse_dm_string("23ste november") - assert (result.day, result.month, result.year) == (23, 11, 2022) - - result = parse_dm_string("november 23rd") - assert (result.day, result.month, result.year) == (23, 11, 2022) - - result = parse_dm_string("nov 23") - assert (result.day, result.month, result.year) == (23, 11, 2022) - - -def test_parse_dm_string_unparseable_raises(): - """Test that any other input raises an error""" - with pytest.raises(ValueError): - parse_dm_string("WhateverThisMayBe") +from didier.utils.types.datetime import str_to_date def test_str_to_date_single_valid():