Skip to content

Commit 9fa1fb3

Browse files
wookie184ChrisLovering
authored andcommitted
Update to pydantic 2.0
1 parent bbe107b commit 9fa1fb3

File tree

3 files changed

+216
-123
lines changed

3 files changed

+216
-123
lines changed

bot/constants.py

Lines changed: 62 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from os import environ
33
from types import MappingProxyType
44

5-
from pydantic import BaseSettings, SecretStr
5+
from pydantic import SecretStr
6+
from pydantic_settings import BaseSettings
67
from pydis_core.utils.logging import get_logger
78

89
__all__ = (
@@ -34,78 +35,70 @@
3435
PYTHON_PREFIX = "!"
3536

3637

37-
class EnvConfig(BaseSettings):
38+
class EnvConfig(
39+
BaseSettings,
40+
env_file=(".env.server", ".env"),
41+
env_file_encoding="utf-8",
42+
env_nested_delimiter="__",
43+
extra="ignore",
44+
):
3845
"""Our default configuration for models that should load from .env files."""
3946

40-
class Config:
41-
"""Specify what .env files to load, and how to load them."""
4247

43-
env_file = ".env",
44-
env_file_encoding = "utf-8"
45-
46-
47-
class _Channels(EnvConfig):
48-
EnvConfig.Config.env_prefix = "channels_"
49-
50-
algos_and_data_structs = 650401909852864553
51-
bot_commands = 267659945086812160
52-
community_meta = 267659945086812160
53-
organisation = 551789653284356126
54-
data_science_and_ai = 366673247892275221
55-
devlog = 622895325144940554
56-
dev_contrib = 635950537262759947
57-
mod_meta = 775412552795947058
58-
mod_tools = 775413915391098921
59-
off_topic_0 = 291284109232308226
60-
off_topic_1 = 463035241142026251
61-
off_topic_2 = 463035268514185226
62-
python_help = 1035199133436354600
63-
sir_lancebot_playground = 607247579608121354
64-
voice_chat_0 = 412357430186344448
65-
voice_chat_1 = 799647045886541885
66-
staff_voice = 541638762007101470
67-
reddit = 458224812528238616
48+
class _Channels(EnvConfig, env_prefix="channels_"):
49+
algos_and_data_structs: int = 650401909852864553
50+
bot_commands: int = 267659945086812160
51+
community_meta: int = 267659945086812160
52+
organisation: int = 551789653284356126
53+
data_science_and_ai: int = 366673247892275221
54+
devlog: int = 622895325144940554
55+
dev_contrib: int = 635950537262759947
56+
mod_meta: int = 775412552795947058
57+
mod_tools: int = 775413915391098921
58+
off_topic_0: int = 291284109232308226
59+
off_topic_1: int = 463035241142026251
60+
off_topic_2: int = 463035268514185226
61+
python_help: int = 1035199133436354600
62+
sir_lancebot_playground: int = 607247579608121354
63+
voice_chat_0: int = 412357430186344448
64+
voice_chat_1: int = 799647045886541885
65+
staff_voice: int = 541638762007101470
66+
reddit: int = 458224812528238616
6867

6968

7069
Channels = _Channels()
7170

7271

73-
class _Categories(EnvConfig):
74-
EnvConfig.Config.env_prefix = "categories_"
75-
76-
python_help_system = 691405807388196926
77-
development = 411199786025484308
78-
devprojects = 787641585624940544
79-
media = 799054581991997460
80-
staff = 364918151625965579
72+
class _Categories(EnvConfig, env_prefix="categories_"):
73+
python_help_system: int = 691405807388196926
74+
development: int = 411199786025484308
75+
devprojects: int = 787641585624940544
76+
media: int = 799054581991997460
77+
staff: int = 364918151625965579
8178

8279

8380
Categories = _Categories()
8481

8582

86-
class _Client(EnvConfig):
87-
EnvConfig.Config.env_prefix = "client_"
88-
89-
name = "Sir Lancebot"
90-
guild = 267624335836053506
91-
prefix = "."
83+
class _Client(EnvConfig, env_prefix="client_"):
84+
name: str = "Sir Lancebot"
85+
guild: int = 267624335836053506
86+
prefix: str = "."
9287
token: SecretStr
93-
debug = True
94-
in_ci = False
95-
github_repo = "https://github.com/python-discord/sir-lancebot"
88+
debug: bool = True
89+
in_ci: bool = False
90+
github_repo: str = "https://github.com/python-discord/sir-lancebot"
9691
# Override seasonal locks: 1 (January) to 12 (December)
9792
month_override: int | None = None
9893

9994

10095
Client = _Client()
10196

10297

103-
class _Logging(EnvConfig):
104-
EnvConfig.Config.env_prefix = "logging_"
105-
106-
debug = Client.debug
107-
file_logs = False
108-
trace_loggers = ""
98+
class _Logging(EnvConfig, env_prefix="logging_"):
99+
debug: bool = Client.debug
100+
file_logs: bool = False
101+
trace_loggers: str = ""
109102

110103

111104
Logging = _Logging()
@@ -259,26 +252,21 @@ def __str__(self) -> str:
259252
Month(Client.month_override)
260253

261254

262-
class _Roles(EnvConfig):
255+
class _Roles(EnvConfig, env_prefix="roles_"):
256+
owners: int = 267627879762755584
257+
admins: int = 267628507062992896
258+
moderation_team: int = 267629731250176001
259+
helpers: int = 267630620367257601
260+
core_developers: int = 587606783669829632
261+
everyone: int = Client.guild
263262

264-
EnvConfig.Config.env_prefix = "roles_"
265-
266-
owners = 267627879762755584
267-
admins = 267628507062992896
268-
moderation_team = 267629731250176001
269-
helpers = 267630620367257601
270-
core_developers = 587606783669829632
271-
everyone = Client.guild
272-
273-
lovefest = 542431903886606399
263+
lovefest: int = 542431903886606399
274264

275265

276266
Roles = _Roles()
277267

278268

279-
class _Tokens(EnvConfig):
280-
EnvConfig.Config.env_prefix = "tokens_"
281-
269+
class _Tokens(EnvConfig, env_prefix="tokens_"):
282270
giphy: SecretStr = ""
283271
youtube: SecretStr = ""
284272
tmdb: SecretStr = ""
@@ -292,31 +280,26 @@ class _Tokens(EnvConfig):
292280
Tokens = _Tokens()
293281

294282

295-
class _Wolfram(EnvConfig):
296-
EnvConfig.Config.env_prefix = "wolfram_"
297-
user_limit_day = 10
298-
guild_limit_day = 67
283+
class _Wolfram(EnvConfig, env_prefix="wolfram_"):
284+
user_limit_day: int = 10
285+
guild_limit_day: int = 67
299286
key: SecretStr = ""
300287

301288

302289
Wolfram = _Wolfram()
303290

304291

305-
class _Redis(EnvConfig):
306-
EnvConfig.Config.env_prefix = "redis_"
307-
308-
host = "redis.default.svc.cluster.local"
309-
port = 6379
292+
class _Redis(EnvConfig, env_prefix="redis_"):
293+
host: str = "redis.default.svc.cluster.local"
294+
port: int = 6379
310295
password: SecretStr = ""
311-
use_fakeredis = False
296+
use_fakeredis: bool = False
312297

313298

314299
Redis = _Redis()
315300

316301

317-
class _Reddit(EnvConfig):
318-
EnvConfig.Config.env_prefix = "reddit_"
319-
302+
class _Reddit(EnvConfig, env_prefix="reddit_"):
320303
subreddits: tuple[str, ...] = ("r/Python",)
321304

322305
client_id: SecretStr = ""

0 commit comments

Comments
 (0)