aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/backend
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/backend')
-rw-r--r--bot/exts/backend/branding/_cog.py20
-rw-r--r--bot/exts/backend/error_handler.py26
2 files changed, 24 insertions, 22 deletions
diff --git a/bot/exts/backend/branding/_cog.py b/bot/exts/backend/branding/_cog.py
index 0a4ddcc88..47c379a34 100644
--- a/bot/exts/backend/branding/_cog.py
+++ b/bot/exts/backend/branding/_cog.py
@@ -3,12 +3,13 @@ import contextlib
import logging
import random
import typing as t
-from datetime import datetime, time, timedelta
+from datetime import timedelta
from enum import Enum
from operator import attrgetter
import async_timeout
import discord
+from arrow import Arrow
from async_rediscache import RedisCache
from discord.ext import commands, tasks
@@ -57,6 +58,8 @@ def extract_event_duration(event: Event) -> str:
Extract a human-readable, year-agnostic duration string from `event`.
In the case that `event` is a fallback event, resolves to 'Fallback'.
+
+ For 1-day events, only the single date is shown, instead of a period.
"""
if event.meta.is_fallback:
return "Fallback"
@@ -65,6 +68,9 @@ def extract_event_duration(event: Event) -> str:
start_date = event.meta.start_date.strftime(fmt)
end_date = event.meta.end_date.strftime(fmt)
+ if start_date == end_date:
+ return start_date
+
return f"{start_date} - {end_date}"
@@ -208,7 +214,7 @@ class Branding(commands.Cog):
if success:
await self.cache_icons.increment(next_icon) # Push the icon into the next iteration.
- timestamp = datetime.utcnow().timestamp()
+ timestamp = Arrow.utcnow().timestamp()
await self.cache_information.set("last_rotation_timestamp", timestamp)
return success
@@ -229,8 +235,8 @@ class Branding(commands.Cog):
await self.rotate_icons()
return
- last_rotation = datetime.fromtimestamp(last_rotation_timestamp)
- difference = (datetime.utcnow() - last_rotation) + timedelta(minutes=5)
+ last_rotation = Arrow.utcfromtimestamp(last_rotation_timestamp)
+ difference = (Arrow.utcnow() - last_rotation) + timedelta(minutes=5)
log.trace(f"Icons last rotated at {last_rotation} (difference: {difference}).")
@@ -485,11 +491,11 @@ class Branding(commands.Cog):
await self.daemon_loop()
log.trace("Daemon before: calculating time to sleep before loop begins.")
- now = datetime.utcnow()
+ now = Arrow.utcnow()
# The actual midnight moment is offset into the future to prevent issues with imprecise sleep.
- tomorrow = now + timedelta(days=1)
- midnight = datetime.combine(tomorrow, time(minute=1))
+ tomorrow = now.shift(days=1)
+ midnight = tomorrow.replace(hour=0, minute=1, second=0, microsecond=0)
sleep_secs = (midnight - now).total_seconds()
log.trace(f"Daemon before: sleeping {sleep_secs} seconds before next-up midnight: {midnight}.")
diff --git a/bot/exts/backend/error_handler.py b/bot/exts/backend/error_handler.py
index 76ab7dfc2..d8de177f5 100644
--- a/bot/exts/backend/error_handler.py
+++ b/bot/exts/backend/error_handler.py
@@ -1,4 +1,3 @@
-import contextlib
import difflib
import logging
import typing as t
@@ -12,7 +11,7 @@ from bot.bot import Bot
from bot.constants import Colours, Icons, MODERATION_ROLES
from bot.converters import TagNameConverter
from bot.errors import InvalidInfractedUser, LockedResourceError
-from bot.utils.checks import InWhitelistCheckFailure
+from bot.utils.checks import ContextCheckFailure
log = logging.getLogger(__name__)
@@ -60,7 +59,7 @@ class ErrorHandler(Cog):
log.trace(f"Command {command} had its error already handled locally; ignoring.")
return
- if isinstance(e, errors.CommandNotFound) and not hasattr(ctx, "invoked_from_error_handler"):
+ if isinstance(e, errors.CommandNotFound) and not getattr(ctx, "invoked_from_error_handler", False):
if await self.try_silence(ctx):
return
# Try to look for a tag with the command's name
@@ -162,9 +161,8 @@ class ErrorHandler(Cog):
f"and the fallback tag failed validation in TagNameConverter."
)
else:
- with contextlib.suppress(ResponseCodeError):
- if await ctx.invoke(tags_get_command, tag_name=tag_name):
- return
+ if await ctx.invoke(tags_get_command, tag_name=tag_name):
+ return
if not any(role.id in MODERATION_ROLES for role in ctx.author.roles):
await self.send_command_suggestion(ctx, ctx.invoked_with)
@@ -214,32 +212,30 @@ class ErrorHandler(Cog):
* ArgumentParsingError: send an error message
* Other: send an error message and the help command
"""
- prepared_help_command = self.get_help_command(ctx)
-
if isinstance(e, errors.MissingRequiredArgument):
embed = self._get_error_embed("Missing required argument", e.param.name)
await ctx.send(embed=embed)
- await prepared_help_command
+ await self.get_help_command(ctx)
self.bot.stats.incr("errors.missing_required_argument")
elif isinstance(e, errors.TooManyArguments):
embed = self._get_error_embed("Too many arguments", str(e))
await ctx.send(embed=embed)
- await prepared_help_command
+ await self.get_help_command(ctx)
self.bot.stats.incr("errors.too_many_arguments")
elif isinstance(e, errors.BadArgument):
embed = self._get_error_embed("Bad argument", str(e))
await ctx.send(embed=embed)
- await prepared_help_command
+ await self.get_help_command(ctx)
self.bot.stats.incr("errors.bad_argument")
elif isinstance(e, errors.BadUnionArgument):
embed = self._get_error_embed("Bad argument", f"{e}\n{e.errors[-1]}")
await ctx.send(embed=embed)
- await prepared_help_command
+ await self.get_help_command(ctx)
self.bot.stats.incr("errors.bad_union_argument")
elif isinstance(e, errors.ArgumentParsingError):
embed = self._get_error_embed("Argument parsing error", str(e))
await ctx.send(embed=embed)
- prepared_help_command.close()
+ self.get_help_command(ctx).close()
self.bot.stats.incr("errors.argument_parsing_error")
else:
embed = self._get_error_embed(
@@ -247,7 +243,7 @@ class ErrorHandler(Cog):
"Something about your input seems off. Check the arguments and try again."
)
await ctx.send(embed=embed)
- await prepared_help_command
+ await self.get_help_command(ctx)
self.bot.stats.incr("errors.other_user_input_error")
@staticmethod
@@ -274,7 +270,7 @@ class ErrorHandler(Cog):
await ctx.send(
"Sorry, it looks like I don't have the permissions or roles I need to do that."
)
- elif isinstance(e, (InWhitelistCheckFailure, errors.NoPrivateMessage)):
+ elif isinstance(e, (ContextCheckFailure, errors.NoPrivateMessage)):
ctx.bot.stats.incr("errors.wrong_channel_or_dm_error")
await ctx.send(e)