aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2022-01-25 12:13:07 +0300
committerGravatar ChrisJL <[email protected]>2022-01-26 03:39:23 +0000
commit1fd39adbb53b14015033fcaff0cbfb4aa81c65d7 (patch)
treeda1f3fa10e7fd850c9162f2e83233cc9f3f25159
parentMerge pull request #1017 from python-discord/test-actions (diff)
Clean Up Constants File
This commit moves the logging constants from the Client class to a new Logging class. Flake8 is renabled for constants, and the error it was disabled for was specifically ignored. All new errors were fixed. It also fixes a bug with __all__, which was trying to export a missing symbol due to a missing comma. Signed-off-by: Hassan Abouelela <[email protected]>
-rw-r--r--bot/constants.py13
-rw-r--r--bot/log.py8
-rw-r--r--tox.ini4
3 files changed, 17 insertions, 8 deletions
diff --git a/bot/constants.py b/bot/constants.py
index 3b426c47..7e7ee749 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -12,6 +12,7 @@ __all__ = (
"Channels",
"Categories",
"Client",
+ "Logging",
"Colours",
"Emojis",
"Icons",
@@ -23,7 +24,7 @@ __all__ = (
"Reddit",
"RedisConfig",
"RedirectOutput",
- "PYTHON_PREFIX"
+ "PYTHON_PREFIX",
"MODERATION_ROLES",
"STAFF_ROLES",
"WHITELISTED_CHANNELS",
@@ -37,6 +38,7 @@ log = logging.getLogger(__name__)
PYTHON_PREFIX = "!"
+
@dataclasses.dataclass
class AdventOfCodeLeaderboard:
id: str
@@ -130,18 +132,24 @@ class Categories(NamedTuple):
media = 799054581991997460
staff = 364918151625965579
+
codejam_categories_name = "Code Jam" # Name of the codejam team categories
+
class Client(NamedTuple):
name = "Sir Lancebot"
guild = int(environ.get("BOT_GUILD", 267624335836053506))
prefix = environ.get("PREFIX", ".")
token = environ.get("BOT_TOKEN")
debug = environ.get("BOT_DEBUG", "true").lower() == "true"
- file_logs = environ.get("FILE_LOGS", "false").lower() == "true"
github_bot_repo = "https://github.com/python-discord/sir-lancebot"
# Override seasonal locks: 1 (January) to 12 (December)
month_override = int(environ["MONTH_OVERRIDE"]) if "MONTH_OVERRIDE" in environ else None
+
+
+class Logging(NamedTuple):
+ debug = Client.debug
+ file_logs = environ.get("FILE_LOGS", "false").lower() == "true"
trace_loggers = environ.get("BOT_TRACE_LOGGERS")
@@ -231,7 +239,6 @@ class Emojis:
status_dnd = "<:status_dnd:470326272082313216>"
status_offline = "<:status_offline:470326266537705472>"
-
stackoverflow_tag = "<:stack_tag:870926975307501570>"
stackoverflow_views = "<:stack_eye:870926992692879371>"
diff --git a/bot/log.py b/bot/log.py
index 29e696e0..a87a836a 100644
--- a/bot/log.py
+++ b/bot/log.py
@@ -6,7 +6,7 @@ from pathlib import Path
import coloredlogs
-from bot.constants import Client
+from bot.constants import Logging
def setup() -> None:
@@ -20,7 +20,7 @@ def setup() -> None:
log_format = logging.Formatter(format_string)
root_logger = logging.getLogger()
- if Client.file_logs:
+ if Logging.file_logs:
# Set up file logging
log_file = Path("logs/sir-lancebot.log")
log_file.parent.mkdir(exist_ok=True)
@@ -45,7 +45,7 @@ def setup() -> None:
coloredlogs.install(level=logging.TRACE, stream=sys.stdout)
- root_logger.setLevel(logging.DEBUG if Client.debug else logging.INFO)
+ root_logger.setLevel(logging.DEBUG if Logging.debug else logging.INFO)
# Silence irrelevant loggers
logging.getLogger("discord").setLevel(logging.ERROR)
logging.getLogger("websockets").setLevel(logging.ERROR)
@@ -81,7 +81,7 @@ def _set_trace_loggers() -> None:
Otherwise if the env var begins with a "*",
the root logger is set to the trace level and other contents are ignored.
"""
- level_filter = Client.trace_loggers
+ level_filter = Logging.trace_loggers
if level_filter:
if level_filter.startswith("*"):
logging.getLogger().setLevel(logging.TRACE)
diff --git a/tox.ini b/tox.ini
index f561fcd9..61ff9616 100644
--- a/tox.ini
+++ b/tox.ini
@@ -20,5 +20,7 @@ exclude=
__pycache__,.cache,
venv,.venv,
tests,
- constants.py
+per-file-ignores =
+ # Don't require docstrings in constants
+ constants.py:D101
import-order-style=pycharm