From 0e117b45121a581204ecd845cfabf2696783a602 Mon Sep 17 00:00:00 2001 From: kwzrd Date: Mon, 30 Mar 2020 19:48:00 +0200 Subject: Deseasonify: move current month resolver to utils The function is useful to other modules as well - not only decorators. This declares it as public and moves it to a more accessible place. --- bot/utils/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'bot/utils/__init__.py') diff --git a/bot/utils/__init__.py b/bot/utils/__init__.py index cb5c9fbe..69bff4de 100644 --- a/bot/utils/__init__.py +++ b/bot/utils/__init__.py @@ -2,14 +2,29 @@ import asyncio import contextlib import re import string +from datetime import datetime from typing import List import discord from discord.ext.commands import BadArgument, Context +from bot.constants import Client, Month from bot.utils.pagination import LinePaginator +def resolve_current_month() -> Month: + """ + Determine current month w.r.t. `Client.month_override` env var. + + If the env variable was set, current month always resolves to the configured value. + Otherwise, the current UTC month is given. + """ + if Client.month_override is not None: + return Month(Client.month_override) + else: + return Month(datetime.utcnow().month) + + async def disambiguate( ctx: Context, entries: List[str], *, timeout: float = 30, entries_per_page: int = 20, empty: bool = False, embed: discord.Embed = None -- cgit v1.2.3