Skip to content

Commit

Permalink
Merge pull request #1463 from kwzrd/kwzrd/branding
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 authored Mar 31, 2021
2 parents 5f4dc42 + b778c25 commit c2f6644
Show file tree
Hide file tree
Showing 12 changed files with 766 additions and 669 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lxml = "~=4.4"
markdownify = "==0.5.3"
more_itertools = "~=8.2"
python-dateutil = "~=2.8"
python-frontmatter = "~=1.0.0"
pyyaml = "~=5.1"
requests = "~=2.22"
sentry-sdk = "~=0.19"
Expand Down
10 changes: 9 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion bot/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import functools
import logging
import typing as t
from contextlib import suppress
Expand All @@ -8,7 +9,7 @@
from discord.ext import commands
from discord.ext.commands import Cog, Context

from bot.constants import Channels, RedirectOutput
from bot.constants import Channels, DEBUG_MODE, RedirectOutput
from bot.utils import function
from bot.utils.checks import in_whitelist_check

Expand Down Expand Up @@ -153,3 +154,23 @@ async def wrapper(*args, **kwargs) -> None:
await func(*args, **kwargs)
return wrapper
return decorator


def mock_in_debug(return_value: t.Any) -> t.Callable:
"""
Short-circuit function execution if in debug mode and return `return_value`.
The original function name, and the incoming args and kwargs are DEBUG level logged
upon each call. This is useful for expensive operations, i.e. media asset uploads
that are prone to rate-limits but need to be tested extensively.
"""
def decorator(func: t.Callable) -> t.Callable:
@functools.wraps(func)
async def wrapped(*args, **kwargs) -> t.Any:
"""Short-circuit and log if in debug mode."""
if DEBUG_MODE:
log.debug(f"Function {func.__name__} called with args: {args}, kwargs: {kwargs}")
return return_value
return await func(*args, **kwargs)
return wrapped
return decorator
6 changes: 6 additions & 0 deletions bot/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ def __init__(self, user: Union[Member, User], reason: str = "User infracted is a
self.reason = reason

super().__init__(reason)


class BrandingMisconfiguration(RuntimeError):
"""Raised by the Branding cog when a misconfigured event is encountered."""

pass
6 changes: 3 additions & 3 deletions bot/exts/backend/branding/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from bot.bot import Bot
from bot.exts.backend.branding._cog import BrandingManager
from bot.exts.backend.branding._cog import Branding


def setup(bot: Bot) -> None:
"""Loads BrandingManager cog."""
bot.add_cog(BrandingManager(bot))
"""Load Branding cog."""
bot.add_cog(Branding(bot))
Loading

0 comments on commit c2f6644

Please sign in to comment.