aboutsummaryrefslogtreecommitdiffstats
path: root/bot/constants.py
diff options
context:
space:
mode:
authorGravatar Rohan Reddy Alleti <[email protected]>2023-05-17 12:23:29 +0530
committerGravatar GitHub <[email protected]>2023-05-17 12:23:29 +0530
commit7876744fedab9fbb22a160c8950ee22262570270 (patch)
treef7189b5f3e9c0947d71f86461f151e50092f6e2c /bot/constants.py
parentnit (diff)
parentBump sentry-sdk from 1.22.2 to 1.23.0 (#1277) (diff)
Merge branch 'main' into undeprecate-bookmark
Diffstat (limited to 'bot/constants.py')
-rw-r--r--bot/constants.py165
1 files changed, 100 insertions, 65 deletions
diff --git a/bot/constants.py b/bot/constants.py
index 7e5fa1d9..cd866a0b 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -1,11 +1,10 @@
import enum
import logging
from os import environ
-from typing import NamedTuple
+
+from pydantic import BaseSettings, SecretStr
__all__ = (
- "Branding",
- "Cats",
"Channels",
"Categories",
"Client",
@@ -13,14 +12,12 @@ __all__ = (
"Colours",
"Emojis",
"Icons",
- "Lovefest",
"Month",
"Roles",
"Tokens",
"Wolfram",
"Reddit",
- "RedisConfig",
- "RedirectOutput",
+ "Redis",
"PYTHON_PREFIX",
"MODERATION_ROLES",
"STAFF_ROLES",
@@ -36,21 +33,25 @@ log = logging.getLogger(__name__)
PYTHON_PREFIX = "!"
-class Branding:
- cycle_frequency = int(environ.get("CYCLE_FREQUENCY", 3)) # 0: never, 1: every day, 2: every other day, ...
+class EnvConfig(BaseSettings):
+ """Our default configuration for models that should load from .env files."""
+
+ class Config:
+ """Specify what .env files to load, and how to load them."""
+ env_file = ".env",
+ env_file_encoding = "utf-8"
-class Cats:
- cats = ["ᓚᘏᗢ", "ᘡᘏᗢ", "🐈", "ᓕᘏᗢ", "ᓇᘏᗢ", "ᓂᘏᗢ", "ᘣᘏᗢ", "ᕦᘏᗢ", "ᕂᘏᗢ"]
+class _Channels(EnvConfig):
+ EnvConfig.Config.env_prefix = "channels_"
-class Channels(NamedTuple):
algos_and_data_structs = 650401909852864553
bot_commands = 267659945086812160
community_meta = 267659945086812160
organisation = 551789653284356126
data_science_and_ai = 366673247892275221
- devlog = int(environ.get("CHANNEL_DEVLOG", 622895325144940554))
+ devlog = 622895325144940554
dev_contrib = 635950537262759947
mod_meta = 775412552795947058
mod_tools = 775413915391098921
@@ -58,43 +59,60 @@ class Channels(NamedTuple):
off_topic_1 = 463035241142026251
off_topic_2 = 463035268514185226
python_help = 1035199133436354600
- sir_lancebot_playground = int(environ.get("CHANNEL_COMMUNITY_BOT_COMMANDS", 607247579608121354))
+ sir_lancebot_playground = 607247579608121354
voice_chat_0 = 412357430186344448
voice_chat_1 = 799647045886541885
staff_voice = 541638762007101470
- reddit = int(environ.get("CHANNEL_REDDIT", 458224812528238616))
+ reddit = 458224812528238616
+
+
+Channels = _Channels()
-class Categories(NamedTuple):
- help_in_use = 696958401460043776
+class _Categories(EnvConfig):
+ EnvConfig.Config.env_prefix = "categories_"
+
+ python_help_system = 691405807388196926
development = 411199786025484308
devprojects = 787641585624940544
media = 799054581991997460
staff = 364918151625965579
-codejam_categories_name = "Code Jam" # Name of the codejam team categories
+Categories = _Categories()
+
+class _Client(EnvConfig):
+ EnvConfig.Config.env_prefix = "client_"
-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"
- in_ci = environ.get("IN_CI", "false").lower() == "true"
- github_bot_repo = "https://github.com/python-discord/sir-lancebot"
+ guild = 267624335836053506
+ prefix = "."
+ token: SecretStr
+ debug = True
+ in_ci = False
+ github_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
+ month_override: int | None = None
+
+Client = _Client()
+
+
+class _Logging(EnvConfig):
+ EnvConfig.Config.env_prefix = "logging_"
-class Logging(NamedTuple):
debug = Client.debug
- file_logs = environ.get("FILE_LOGS", "false").lower() == "true"
- trace_loggers = environ.get("BOT_TRACE_LOGGERS")
+ file_logs = False
+ trace_loggers = ""
+
+
+Logging = _Logging()
class Colours:
+ """Lookups for commonly used colours."""
+
blue = 0x0279FD
twitter_blue = 0x1DA1F2
bright_green = 0x01D277
@@ -129,6 +147,8 @@ class Colours:
class Emojis:
+ """Commonly used emojis."""
+
cross_mark = "\u274C"
check = "\u2611"
envelope = "\U0001F4E8"
@@ -201,6 +221,8 @@ class Emojis:
class Icons:
+ """URLs to commonly used icons."""
+
questionmark = "https://cdn.discordapp.com/emojis/512367613339369475.png"
bookmark = (
"https://images-ext-2.discordapp.net/external/zl4oDwcmxUILY7sD9ZWE2fU5R7n6QcxEmPYSE5eddbg/"
@@ -208,11 +230,9 @@ class Icons:
)
-class Lovefest:
- role_id = int(environ.get("LOVEFEST_ROLE_ID", 542431903886606399))
-
-
class Month(enum.IntEnum):
+ """Month of the year lookup. Used for in_month checks."""
+
JANUARY = 1
FEBRUARY = 2
MARCH = 3
@@ -236,57 +256,72 @@ if Client.month_override is not None:
Month(Client.month_override)
-class Roles(NamedTuple):
+class _Roles(EnvConfig):
+
+ EnvConfig.Config.env_prefix = "roles_"
+
owners = 267627879762755584
- admins = int(environ.get("BOT_ADMIN_ROLE_ID", 267628507062992896))
+ admins = 267628507062992896
moderation_team = 267629731250176001
- helpers = int(environ.get("ROLE_HELPERS", 267630620367257601))
+ helpers = 267630620367257601
core_developers = 587606783669829632
- everyone = int(environ.get("BOT_GUILD", 267624335836053506))
+ everyone = Client.guild
+
+ lovefest = 542431903886606399
+
+Roles = _Roles()
-class Tokens(NamedTuple):
- giphy = environ.get("GIPHY_TOKEN")
- aoc_session_cookie = environ.get("AOC_SESSION_COOKIE")
- omdb = environ.get("OMDB_API_KEY")
- youtube = environ.get("YOUTUBE_API_KEY")
- tmdb = environ.get("TMDB_API_KEY")
- nasa = environ.get("NASA_API_KEY")
- igdb_client_id = environ.get("IGDB_CLIENT_ID")
- igdb_client_secret = environ.get("IGDB_CLIENT_SECRET")
- github = environ.get("GITHUB_TOKEN")
- unsplash_access_key = environ.get("UNSPLASH_KEY")
+class _Tokens(EnvConfig):
+ EnvConfig.Config.env_prefix = "tokens_"
-class Wolfram(NamedTuple):
- user_limit_day = int(environ.get("WOLFRAM_USER_LIMIT_DAY", 10))
- guild_limit_day = int(environ.get("WOLFRAM_GUILD_LIMIT_DAY", 67))
- key = environ.get("WOLFRAM_API_KEY")
+ giphy: SecretStr = ""
+ youtube: SecretStr = ""
+ tmdb: SecretStr = ""
+ nasa: SecretStr = ""
+ igdb_client_id: SecretStr = ""
+ igdb_client_secret: SecretStr = ""
+ github: SecretStr = ""
+ unsplash: SecretStr = ""
-class RedisConfig(NamedTuple):
- host = environ.get("REDIS_HOST", "redis.default.svc.cluster.local")
- port = environ.get("REDIS_PORT", 6379)
- password = environ.get("REDIS_PASSWORD")
- use_fakeredis = environ.get("USE_FAKEREDIS", "false").lower() == "true"
+Tokens = _Tokens()
-class Source:
- github = "https://github.com/python-discord/sir-lancebot"
- github_avatar_url = "https://avatars1.githubusercontent.com/u/9919"
+class _Wolfram(EnvConfig):
+ EnvConfig.Config.env_prefix = "wolfram_"
+ user_limit_day = 10
+ guild_limit_day = 67
+ key: SecretStr = ""
-class RedirectOutput:
- delete_delay: int = 10
+Wolfram = _Wolfram()
-class Reddit:
+class _Redis(EnvConfig):
+ EnvConfig.Config.env_prefix = "redis_"
+
+ host = "redis.default.svc.cluster.local"
+ port = 6379
+ password: SecretStr = ""
+ use_fakeredis = False
+
+
+Redis = _Redis()
+
+
+class _Reddit(EnvConfig):
+ EnvConfig.Config.env_prefix = "reddit_"
+
subreddits = ["r/Python"]
- client_id = environ.get("REDDIT_CLIENT_ID")
- secret = environ.get("REDDIT_SECRET")
- webhook = int(environ.get("REDDIT_WEBHOOK", 635408384794951680))
+ client_id: SecretStr = ""
+ secret: SecretStr = ""
+ webhook = 635408384794951680
+
+Reddit = _Reddit()
# Default role combinations
MODERATION_ROLES = {Roles.moderation_team, Roles.admins, Roles.owners}