Skip to content

Commit c2f6644

Browse files
authored
Merge pull request #1463 from kwzrd/kwzrd/branding
2 parents 5f4dc42 + b778c25 commit c2f6644

12 files changed

+766
-669
lines changed

Pipfile

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ lxml = "~=4.4"
2323
markdownify = "==0.5.3"
2424
more_itertools = "~=8.2"
2525
python-dateutil = "~=2.8"
26+
python-frontmatter = "~=1.0.0"
2627
pyyaml = "~=5.1"
2728
requests = "~=2.22"
2829
sentry-sdk = "~=0.19"

Pipfile.lock

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bot/decorators.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import functools
23
import logging
34
import typing as t
45
from contextlib import suppress
@@ -8,7 +9,7 @@
89
from discord.ext import commands
910
from discord.ext.commands import Cog, Context
1011

11-
from bot.constants import Channels, RedirectOutput
12+
from bot.constants import Channels, DEBUG_MODE, RedirectOutput
1213
from bot.utils import function
1314
from bot.utils.checks import in_whitelist_check
1415

@@ -153,3 +154,23 @@ async def wrapper(*args, **kwargs) -> None:
153154
await func(*args, **kwargs)
154155
return wrapper
155156
return decorator
157+
158+
159+
def mock_in_debug(return_value: t.Any) -> t.Callable:
160+
"""
161+
Short-circuit function execution if in debug mode and return `return_value`.
162+
163+
The original function name, and the incoming args and kwargs are DEBUG level logged
164+
upon each call. This is useful for expensive operations, i.e. media asset uploads
165+
that are prone to rate-limits but need to be tested extensively.
166+
"""
167+
def decorator(func: t.Callable) -> t.Callable:
168+
@functools.wraps(func)
169+
async def wrapped(*args, **kwargs) -> t.Any:
170+
"""Short-circuit and log if in debug mode."""
171+
if DEBUG_MODE:
172+
log.debug(f"Function {func.__name__} called with args: {args}, kwargs: {kwargs}")
173+
return return_value
174+
return await func(*args, **kwargs)
175+
return wrapped
176+
return decorator

bot/errors.py

+6
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ def __init__(self, user: Union[Member, User], reason: str = "User infracted is a
3535
self.reason = reason
3636

3737
super().__init__(reason)
38+
39+
40+
class BrandingMisconfiguration(RuntimeError):
41+
"""Raised by the Branding cog when a misconfigured event is encountered."""
42+
43+
pass

bot/exts/backend/branding/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from bot.bot import Bot
2-
from bot.exts.backend.branding._cog import BrandingManager
2+
from bot.exts.backend.branding._cog import Branding
33

44

55
def setup(bot: Bot) -> None:
6-
"""Loads BrandingManager cog."""
7-
bot.add_cog(BrandingManager(bot))
6+
"""Load Branding cog."""
7+
bot.add_cog(Branding(bot))

0 commit comments

Comments
 (0)