aboutsummaryrefslogtreecommitdiffstats
path: root/bot/utils
diff options
context:
space:
mode:
Diffstat (limited to 'bot/utils')
-rw-r--r--bot/utils/checks.py2
-rw-r--r--bot/utils/decorators.py22
-rw-r--r--bot/utils/exceptions.py6
-rw-r--r--bot/utils/persist.py69
4 files changed, 2 insertions, 97 deletions
diff --git a/bot/utils/checks.py b/bot/utils/checks.py
index 3031a271..9dd4dde0 100644
--- a/bot/utils/checks.py
+++ b/bot/utils/checks.py
@@ -39,7 +39,7 @@ def in_whitelist_check(
channels: Container[int] = (),
categories: Container[int] = (),
roles: Container[int] = (),
- redirect: Optional[int] = constants.Channels.seasonalbot_commands,
+ redirect: Optional[int] = constants.Channels.community_bot_commands,
fail_silently: bool = False,
) -> bool:
"""
diff --git a/bot/utils/decorators.py b/bot/utils/decorators.py
index 9e6ef73d..9cdaad3f 100644
--- a/bot/utils/decorators.py
+++ b/bot/utils/decorators.py
@@ -11,7 +11,7 @@ from discord import Colour, Embed
from discord.ext import commands
from discord.ext.commands import CheckFailure, Command, Context
-from bot.constants import Client, ERROR_REPLIES, Month
+from bot.constants import ERROR_REPLIES, Month
from bot.utils import human_months, resolve_current_month
ONE_DAY = 24 * 60 * 60
@@ -298,23 +298,3 @@ def locked() -> t.Union[t.Callable, None]:
return await func(self, ctx, *args, **kwargs)
return inner
return wrap
-
-
-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 Client.debug:
- log.debug(f"Function {func.__name__} called with args: {args}, kwargs: {kwargs}")
- return return_value
- return await func(*args, **kwargs)
- return wrapped
- return decorator
diff --git a/bot/utils/exceptions.py b/bot/utils/exceptions.py
index dc62debe..2b1c1b31 100644
--- a/bot/utils/exceptions.py
+++ b/bot/utils/exceptions.py
@@ -1,9 +1,3 @@
-class BrandingError(Exception):
- """Exception raised by the BrandingManager cog."""
-
- pass
-
-
class UserNotPlayingError(Exception):
"""Will raised when user try to use game commands when not playing."""
diff --git a/bot/utils/persist.py b/bot/utils/persist.py
deleted file mode 100644
index 1e178569..00000000
--- a/bot/utils/persist.py
+++ /dev/null
@@ -1,69 +0,0 @@
-import sqlite3
-from pathlib import Path
-from shutil import copyfile
-
-from bot.exts import get_package_names
-
-DIRECTORY = Path("data") # directory that has a persistent volume mapped to it
-
-
-def make_persistent(file_path: Path) -> Path:
- """
- Copy datafile at the provided file_path to the persistent data directory.
-
- A persistent data file is needed by some features in order to not lose data
- after bot rebuilds.
-
- This function will ensure that a clean data file with default schema,
- structure or data is copied over to the persistent volume before returning
- the path to this new persistent version of the file.
-
- If the persistent file already exists, it won't be overwritten with the
- clean default file, just returning the Path instead to the existing file.
-
- Note: Avoid using the same file name as other features in the same seasons
- as otherwise only one datafile can be persistent and will be returned for
- both cases.
-
- Ensure that all open files are using explicit appropriate encoding to avoid
- encoding errors from diffent OS systems.
-
- Example Usage:
- >>> import json
- >>> template_datafile = Path("bot", "resources", "evergreen", "myfile.json")
- >>> path_to_persistent_file = make_persistent(template_datafile)
- >>> print(path_to_persistent_file)
- data/evergreen/myfile.json
- >>> with path_to_persistent_file.open("w+", encoding="utf8") as f:
- >>> data = json.load(f)
- """
- # ensure the persistent data directory exists
- DIRECTORY.mkdir(exist_ok=True)
-
- if not file_path.is_file():
- raise OSError(f"File not found at {file_path}.")
-
- # detect season in datafile path for assigning to subdirectory
- season = next((s for s in get_package_names() if s in file_path.parts), None)
-
- if season:
- # make sure subdirectory exists first
- subdirectory = Path(DIRECTORY, season)
- subdirectory.mkdir(exist_ok=True)
-
- persistent_path = Path(subdirectory, file_path.name)
-
- else:
- persistent_path = Path(DIRECTORY, file_path.name)
-
- # copy base/template datafile to persistent directory
- if not persistent_path.exists():
- copyfile(file_path, persistent_path)
-
- return persistent_path
-
-
-def sqlite(db_path: Path) -> sqlite3.Connection:
- """Copy sqlite file to the persistent data directory and return an open connection."""
- persistent_path = make_persistent(db_path)
- return sqlite3.connect(persistent_path)