aboutsummaryrefslogtreecommitdiffstats
path: root/bot/utils/__init__.py
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2020-03-30 19:48:00 +0200
committerGravatar kwzrd <[email protected]>2020-03-30 19:48:00 +0200
commit0e117b45121a581204ecd845cfabf2696783a602 (patch)
tree24c6b3302c821ae1cffa9e8ca667e750ea94d7bd /bot/utils/__init__.py
parentDeseasonify: remove `autostart` env var (diff)
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.
Diffstat (limited to 'bot/utils/__init__.py')
-rw-r--r--bot/utils/__init__.py15
1 files changed, 15 insertions, 0 deletions
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