From 31188d41ff25699ab595a0ef7565c93ff3797695 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sun, 30 Apr 2023 13:06:18 +0100 Subject: add base EnvConfig --- bot/constants.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 7e5fa1d9..827c5356 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,7 +1,9 @@ import enum import logging from os import environ -from typing import NamedTuple + +from pydantic import BaseSettings + __all__ = ( "Branding", @@ -36,8 +38,23 @@ 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.server", ".env", + env_file_encoding = "utf-8" + + +class _Branding(EnvConfig): + EnvConfig.Config.env_prefix = "branding_" + + cycle_frequency = 3 # 0: never, 1: every day, 2: every other day, ... + + +Branding = _Branding() class Cats: -- cgit v1.2.3 From 6d0f5d319a4f25495ee59a6153a493649f0e4e5c Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sun, 30 Apr 2023 13:07:05 +0100 Subject: update Channels --- bot/constants.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 827c5356..d550b317 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -61,13 +61,15 @@ class Cats: cats = ["ᓚᘏᗢ", "ᘡᘏᗢ", "🐈", "ᓕᘏᗢ", "ᓇᘏᗢ", "ᓂᘏᗢ", "ᘣᘏᗢ", "ᕦᘏᗢ", "ᕂᘏᗢ"] -class Channels(NamedTuple): +class _Channels(EnvConfig): + EnvConfig.Config.env_prefix = "channels_" + 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 @@ -75,12 +77,14 @@ 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 -- cgit v1.2.3 From 229c1672529c7d5b87dc0928816c0094bd42189c Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:17:28 +0100 Subject: update Categories --- bot/constants.py | 11 ++++++++--- bot/exts/utilities/cheatsheet.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index d550b317..4c657ff9 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -86,15 +86,20 @@ class _Channels(EnvConfig): 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() + +CODEJAM_CATEGORY_NAME = "Code Jam" # Name of the codejam team categories class Client(NamedTuple): diff --git a/bot/exts/utilities/cheatsheet.py b/bot/exts/utilities/cheatsheet.py index 3141a050..d7eb4917 100644 --- a/bot/exts/utilities/cheatsheet.py +++ b/bot/exts/utilities/cheatsheet.py @@ -80,7 +80,7 @@ class CheatSheet(commands.Cog): aliases=("cht.sh", "cheatsheet", "cheat-sheet", "cht"), ) @commands.cooldown(1, 10, BucketType.user) - @whitelist_override(categories=[Categories.help_in_use]) + @whitelist_override(categories=[Categories.python_help_system]) async def cheat_sheet(self, ctx: Context, *search_terms: str) -> None: """ Search cheat.sh. -- cgit v1.2.3 From 64e1ac315daf4d17da02790859baebbbbb7bdfc4 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:20:31 +0100 Subject: update Client constants This also renames the Client class to Bot, to align better with Python. --- bot/__main__.py | 10 +++++----- bot/bot.py | 4 ++-- bot/constants.py | 22 +++++++++++++--------- bot/exts/core/extensions.py | 4 ++-- bot/exts/core/help.py | 4 ++-- bot/exts/core/internal_eval/_internal_eval.py | 2 +- bot/exts/fun/fun.py | 4 ++-- bot/exts/fun/minesweeper.py | 6 +++--- bot/exts/fun/trivia_quiz.py | 4 ++-- bot/exts/holidays/halloween/spookynamerate.py | 20 ++++++++++---------- bot/exts/holidays/pride/pride_leader.py | 2 +- bot/exts/utilities/cheatsheet.py | 6 +++--- bot/exts/utilities/logging.py | 2 +- bot/exts/utilities/wtf_python.py | 6 +++--- bot/utils/__init__.py | 6 +++--- bot/utils/checks.py | 2 +- 16 files changed, 54 insertions(+), 50 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/__main__.py b/bot/__main__.py index d39e93bf..970614ce 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -62,11 +62,11 @@ async def main() -> None: async with aiohttp.ClientSession() as session: bot.instance = Bot( - guild_id=constants.Client.guild, + guild_id=constants.Bot.guild, http_session=session, redis_session=await _create_redis_session(), - command_prefix=commands.when_mentioned_or(constants.Client.prefix), - activity=discord.Game(name=f"Commands: {constants.Client.prefix}help"), + command_prefix=commands.when_mentioned_or(constants.Bot.prefix), + activity=discord.Game(name=f"Commands: {constants.Bot.prefix}help"), case_insensitive=True, allowed_mentions=discord.AllowedMentions(everyone=False, roles=allowed_roles), intents=intents, @@ -78,10 +78,10 @@ async def main() -> None: channels=constants.WHITELISTED_CHANNELS, roles=constants.STAFF_ROLES, )) - if constants.Client.in_ci: + if constants.Bot.in_ci: await test_bot_in_ci(_bot) else: - await _bot.start(constants.Client.token) + await _bot.start(constants.Bot.token) asyncio.run(main()) diff --git a/bot/bot.py b/bot/bot.py index da19bdd9..b9f1a62c 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -23,12 +23,12 @@ class Bot(BotBase): that the upload was successful. See the `mock_in_debug` decorator for further details. """ - name = constants.Client.name + name = constants.Bot.name @property def member(self) -> Optional[discord.Member]: """Retrieves the guild member object for the bot.""" - guild = self.get_guild(constants.Client.guild) + guild = self.get_guild(constants.Bot.guild) if not guild: return None return guild.me diff --git a/bot/constants.py b/bot/constants.py index 4c657ff9..ee7ab6d8 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -10,7 +10,7 @@ __all__ = ( "Cats", "Channels", "Categories", - "Client", + "Bot", "Logging", "Colours", "Emojis", @@ -102,17 +102,21 @@ Categories = _Categories() CODEJAM_CATEGORY_NAME = "Code Jam" # Name of the codejam team categories -class Client(NamedTuple): +class _Bot(EnvConfig): + EnvConfig.Config.env_prefix = "bot_" + 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 = "" + 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 + +Bot = _Bot() class Logging(NamedTuple): debug = Client.debug diff --git a/bot/exts/core/extensions.py b/bot/exts/core/extensions.py index 1d22cf37..3b1a1e8a 100644 --- a/bot/exts/core/extensions.py +++ b/bot/exts/core/extensions.py @@ -11,7 +11,7 @@ from pydis_core.utils._extensions import unqualify from bot import exts from bot.bot import Bot -from bot.constants import Client, Emojis, MODERATION_ROLES, Roles +from bot.constants import Bot, Emojis, MODERATION_ROLES, Roles from bot.utils.checks import with_role_check from bot.utils.pagination import LinePaginator @@ -155,7 +155,7 @@ class Extensions(commands.Cog): embed = Embed(colour=Colour.og_blurple()) embed.set_author( name="Extensions List", - url=Client.github_bot_repo, + url=Bot.github_repo, icon_url=str(self.bot.user.display_avatar.url) ) diff --git a/bot/exts/core/help.py b/bot/exts/core/help.py index 30deaff4..d031cafe 100644 --- a/bot/exts/core/help.py +++ b/bot/exts/core/help.py @@ -311,7 +311,7 @@ class HelpSession: self._pages = paginator.pages async def _add_command_signature(self, paginator: LinePaginator) -> None: - prefix = constants.Client.prefix + prefix = constants.Bot.prefix signature = self._get_command_params(self.query) paginator.add_line(f"**```\n{prefix}{signature}\n```**") @@ -405,7 +405,7 @@ class HelpSession: if isinstance(self.query, commands.Command): prefix = "" else: - prefix = constants.Client.prefix + prefix = constants.Bot.prefix signature = self._get_command_params(command) info = f"{strikeout}**`{prefix}{signature}`**{strikeout}" diff --git a/bot/exts/core/internal_eval/_internal_eval.py b/bot/exts/core/internal_eval/_internal_eval.py index 2daf8ef9..7365effc 100644 --- a/bot/exts/core/internal_eval/_internal_eval.py +++ b/bot/exts/core/internal_eval/_internal_eval.py @@ -43,7 +43,7 @@ class InternalEval(commands.Cog): self.bot = bot self.locals = {} - if Client.debug: + if Bot.debug: self.internal_group.add_check(commands.is_owner().predicate) @staticmethod diff --git a/bot/exts/fun/fun.py b/bot/exts/fun/fun.py index 16279dd7..aa12b079 100644 --- a/bot/exts/fun/fun.py +++ b/bot/exts/fun/fun.py @@ -12,7 +12,7 @@ from discord.ext.commands import BadArgument, Cog, Context from pydis_core.utils.commands import clean_text_or_reply from bot.bot import Bot -from bot.constants import Client, Colours, Emojis +from bot.constants import Bot, Colours, Emojis from bot.utils import helpers, messages log = logging.getLogger(__name__) @@ -58,7 +58,7 @@ class Fun(Cog): dice = " ".join(self._get_random_die() for _ in range(num_rolls)) await ctx.send(dice) else: - raise BadArgument(f"`{Client.prefix}roll` only supports between 1 and 6 rolls.") + raise BadArgument(f"`{Bot.prefix}roll` only supports between 1 and 6 rolls.") @commands.command(name="randomcase", aliases=("rcase", "randomcaps", "rcaps",)) async def randomcase_command(self, ctx: Context, *, text: str | None) -> None: diff --git a/bot/exts/fun/minesweeper.py b/bot/exts/fun/minesweeper.py index f16b1db2..cd1f6711 100644 --- a/bot/exts/fun/minesweeper.py +++ b/bot/exts/fun/minesweeper.py @@ -8,7 +8,7 @@ import discord from discord.ext import commands from bot.bot import Bot -from bot.constants import Client +from bot.constants import Bot from bot.utils.converters import CoordinateConverter from bot.utils.exceptions import UserNotPlayingError @@ -117,8 +117,8 @@ class Minesweeper(commands.Cog): try: await ctx.author.send( - f"Play by typing: `{Client.prefix}ms reveal xy [xy]` or `{Client.prefix}ms flag xy [xy]` \n" - f"Close the game with `{Client.prefix}ms end`\n" + f"Play by typing: `{Bot.prefix}ms reveal xy [xy]` or `{Bot.prefix}ms flag xy [xy]` \n" + f"Close the game with `{Bot.prefix}ms end`\n" ) except discord.errors.Forbidden: log.debug(f"{ctx.author.name} ({ctx.author.id}) has disabled DMs from server members.") diff --git a/bot/exts/fun/trivia_quiz.py b/bot/exts/fun/trivia_quiz.py index 31652374..546b796b 100644 --- a/bot/exts/fun/trivia_quiz.py +++ b/bot/exts/fun/trivia_quiz.py @@ -16,7 +16,7 @@ from discord.ext import commands, tasks from rapidfuzz import fuzz from bot.bot import Bot -from bot.constants import Client, Colours, MODERATION_ROLES, NEGATIVE_REPLIES +from bot.constants import Bot, Colours, MODERATION_ROLES, NEGATIVE_REPLIES logger = logging.getLogger(__name__) @@ -332,7 +332,7 @@ class TriviaQuiz(commands.Cog): if self.game_status[ctx.channel.id]: await ctx.send( "Game is already running... " - f"do `{Client.prefix}quiz stop`" + f"do `{Bot.prefix}quiz stop`" ) return diff --git a/bot/exts/holidays/halloween/spookynamerate.py b/bot/exts/holidays/halloween/spookynamerate.py index a76e5e12..fd3f4247 100644 --- a/bot/exts/holidays/halloween/spookynamerate.py +++ b/bot/exts/holidays/halloween/spookynamerate.py @@ -15,7 +15,7 @@ from discord.ext import tasks from discord.ext.commands import Cog, Context, group from bot.bot import Bot -from bot.constants import Channels, Client, Colours, Month +from bot.constants import Channels, Bot, Colours, Month from bot.utils.decorators import InMonthCheckFailure logger = getLogger(__name__) @@ -38,7 +38,7 @@ PING = "<@{id}>" EMOJI_MESSAGE = "\n".join(f"- {emoji} {val}" for emoji, val in EMOJIS_VAL.items()) HELP_MESSAGE_DICT = { "title": "Spooky Name Rate", - "description": f"Help for the `{Client.prefix}spookynamerate` command", + "description": f"Help for the `{Bot.prefix}spookynamerate` command", "color": Colours.soft_orange, "fields": [ { @@ -54,12 +54,12 @@ HELP_MESSAGE_DICT = { }, { "name": "How do I add my spookified name?", - "value": f"Simply type `{Client.prefix}spookynamerate add my name`", + "value": f"Simply type `{Bot.prefix}spookynamerate add my name`", "inline": False, }, { "name": "How do I *delete* my spookified name?", - "value": f"Simply type `{Client.prefix}spookynamerate delete`", + "value": f"Simply type `{Bot.prefix}spookynamerate delete`", "inline": False, }, ], @@ -141,7 +141,7 @@ class SpookyNameRate(Cog): if data["author"] == ctx.author.id: await ctx.send( "But you have already added an entry! Type " - f"`{Client.prefix}spookynamerate " + f"`{Bot.prefix}spookynamerate " "delete` to delete it, and then you can add it again" ) return @@ -183,7 +183,7 @@ class SpookyNameRate(Cog): return await ctx.send( - f"But you don't have an entry... :eyes: Type `{Client.prefix}spookynamerate add your entry`" + f"But you don't have an entry... :eyes: Type `{Bot.prefix}spookynamerate add your entry`" ) @Cog.listener() @@ -223,7 +223,7 @@ class SpookyNameRate(Cog): "Okkey... Welcome to the **Spooky Name Rate Game**! It's a relatively simple game.\n" f"Everyday, a random name will be sent in <#{Channels.sir_lancebot_playground}> " "and you need to try and spookify it!\nRegister your name using " - f"`{Client.prefix}spookynamerate add spookified name`" + f"`{Bot.prefix}spookynamerate add spookified name`" ) await self.data.set("first_time", False) @@ -348,7 +348,7 @@ class SpookyNameRate(Cog): embed.add_field( name=(self.bot.get_user(data["author"]) or await self.bot.fetch_user(data["author"])).name, - value=f"[{(data)['name']}](https://discord.com/channels/{Client.guild}/{channel.id}/{message_id})", + value=f"[{(data)['name']}](https://discord.com/channels/{Bot.guild}/{channel.id}/{message_id})", ) return embed @@ -368,9 +368,9 @@ class SpookyNameRate(Cog): if SpookyNameRate.debug: return True - if not Client.month_override: + if not Bot.month_override: return datetime.utcnow().month == Month.OCTOBER - return Client.month_override == Month.OCTOBER + return Bot.month_override == Month.OCTOBER def cog_check(self, ctx: Context) -> bool: """A command to check whether the command is being called in October.""" diff --git a/bot/exts/holidays/pride/pride_leader.py b/bot/exts/holidays/pride/pride_leader.py index 120e9e16..94ba612e 100644 --- a/bot/exts/holidays/pride/pride_leader.py +++ b/bot/exts/holidays/pride/pride_leader.py @@ -82,7 +82,7 @@ class PrideLeader(commands.Cog): ) embed.add_field( name="For More Information", - value=f"Do `{constants.Client.prefix}wiki {name}`" + value=f"Do `{constants.Bot.prefix}wiki {name}`" f" in <#{constants.Channels.sir_lancebot_playground}>", inline=False ) diff --git a/bot/exts/utilities/cheatsheet.py b/bot/exts/utilities/cheatsheet.py index d7eb4917..48956de3 100644 --- a/bot/exts/utilities/cheatsheet.py +++ b/bot/exts/utilities/cheatsheet.py @@ -17,9 +17,9 @@ Unknown cheat sheet. Please try to reformulate your query. **Examples**: ```md -{constants.Client.prefix}cht read json -{constants.Client.prefix}cht hello world -{constants.Client.prefix}cht lambda +{constants.Bot.prefix}cht read json +{constants.Bot.prefix}cht hello world +{constants.Bot.prefix}cht lambda ``` If the problem persists send a message in <#{Channels.dev_contrib}> """ diff --git a/bot/exts/utilities/logging.py b/bot/exts/utilities/logging.py index 00febc2c..7f520522 100644 --- a/bot/exts/utilities/logging.py +++ b/bot/exts/utilities/logging.py @@ -23,7 +23,7 @@ class Logging(Cog): async def check_channels(self) -> None: """Verifies that all channel constants refer to channels which exist.""" - if constants.Client.debug: + if constants.Bot.debug: log.info("Skipping Channels Check.") return diff --git a/bot/exts/utilities/wtf_python.py b/bot/exts/utilities/wtf_python.py index 0c0375cb..f5db7a96 100644 --- a/bot/exts/utilities/wtf_python.py +++ b/bot/exts/utilities/wtf_python.py @@ -21,9 +21,9 @@ Unknown WTF Python Query. Please try to reformulate your query. **Examples**: ```md -{constants.Client.prefix}wtf wild imports -{constants.Client.prefix}wtf subclass -{constants.Client.prefix}wtf del +{constants.Bot.prefix}wtf wild imports +{constants.Bot.prefix}wtf subclass +{constants.Bot.prefix}wtf del ``` If the problem persists send a message in <#{constants.Channels.dev_contrib}> """ diff --git a/bot/utils/__init__.py b/bot/utils/__init__.py index 91682dbc..69439d91 100644 --- a/bot/utils/__init__.py +++ b/bot/utils/__init__.py @@ -9,7 +9,7 @@ from typing import Optional import discord from discord.ext.commands import BadArgument, Context -from bot.constants import Client, Month +from bot.constants import Bot, Month from bot.utils.pagination import LinePaginator @@ -25,8 +25,8 @@ def resolve_current_month() -> Month: If the env variable was set, current month always resolves to the configured value. Otherwise, the current UTC month is given. """ - if Client.month_override is not None: - return Month(Client.month_override) + if Bot.month_override is not None: + return Month(Bot.month_override) else: return Month(datetime.utcnow().month) diff --git a/bot/utils/checks.py b/bot/utils/checks.py index 857b6746..f21d2ddd 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -74,7 +74,7 @@ def in_whitelist_check( return True category = getattr(ctx_channel, "category", None) - if category and category.name == constants.codejam_categories_name: + if category and category.name == constants.CODEJAM_CATEGORY_NAME: log.trace(f"{ctx.author} may use the `{ctx.command.name}` command as they are in a codejam team channel.") return True -- cgit v1.2.3 From ebdeed7b7903fbec6555e94bfa6d741a3e11b2ba Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:21:03 +0100 Subject: update Logging --- bot/constants.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index ee7ab6d8..91ef7d10 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -118,10 +118,16 @@ class _Bot(EnvConfig): Bot = _Bot() -class Logging(NamedTuple): - debug = Client.debug - file_logs = environ.get("FILE_LOGS", "false").lower() == "true" - trace_loggers = environ.get("BOT_TRACE_LOGGERS") + +class _Logging(EnvConfig): + EnvConfig.Config.env_prefix = "logging_" + + debug = Bot.debug + file_logs = False + trace_loggers = "" + + +Logging = _Logging() class Colours: -- cgit v1.2.3 From 7b7dea1a8d5f8e53b8ad9b9a82138e4c8689f566 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:21:40 +0100 Subject: redeem lost bot references --- bot/constants.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 91ef7d10..11f9a5b9 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -171,7 +171,7 @@ class Emojis: trashcan = environ.get( "TRASHCAN_EMOJI", - "\N{WASTEBASKET}" if Client.debug else "<:trashcan:637136429717389331>", + "\N{WASTEBASKET}" if Bot.debug else "<:trashcan:637136429717389331>", ) ok_hand = ":ok_hand:" @@ -268,8 +268,9 @@ class Month(enum.IntEnum): # If a month override was configured, check that it's a valid Month # Prevents delaying an exception after the bot starts -if Client.month_override is not None: - Month(Client.month_override) +if Bot.month_override is not None: + Month(Bot.month_override) + class Roles(NamedTuple): -- cgit v1.2.3 From 25b5e0e81b8ae555f8fe7c3cf1cf4faf92af86c7 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:22:00 +0100 Subject: update lovefest --- bot/constants.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 11f9a5b9..540183ee 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -244,8 +244,14 @@ class Icons: ) -class Lovefest: - role_id = int(environ.get("LOVEFEST_ROLE_ID", 542431903886606399)) +class _Lovefest(EnvConfig): + + EnvConfig.Config.env_prefix = "lovefest_" + + role_id = 542431903886606399 + + +Lovefest = _Lovefest() class Month(enum.IntEnum): -- cgit v1.2.3 From 45087ea8845227fbb16ee75c4a4836e9dcdf91c8 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:22:57 +0100 Subject: update Roles --- bot/constants.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 540183ee..b17fc920 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -278,14 +278,19 @@ if Bot.month_override is not None: Month(Bot.month_override) +class _Roles(EnvConfig): + + EnvConfig.Config.env_prefix = "roles_" -class Roles(NamedTuple): 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 = Bot.guild + + +Roles = _Roles() class Tokens(NamedTuple): -- cgit v1.2.3 From e5cce5558c4dd3da38f9106d9b4addb874ea0c4b Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:25:14 +0100 Subject: update Tokens & Wolfram --- bot/constants.py | 37 ++++++++++++++++++++++---------- bot/exts/holidays/easter/earth_photos.py | 6 +++--- bot/exts/utilities/wolfram.py | 4 ++-- 3 files changed, 31 insertions(+), 16 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index b17fc920..5f853521 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -293,17 +293,32 @@ class _Roles(EnvConfig): 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_" + + giphy = "" + aoc_session_cookie = "" + omdb = "" + youtube = "" + tmdb = "" + nasa = "" + igdb_client_id = "" + igdb_client_secret = "" + github = "" + unsplash = "" + wolfram = "" + + +Tokens = _Tokens() + + +class _Wolfram(EnvConfig): + EnvConfig.Config.env_prefix = "wolfram_" + user_limit_day = 10 + guild_limit_day = 67 + + +Wolfram = _Wolfram() class Wolfram(NamedTuple): diff --git a/bot/exts/holidays/easter/earth_photos.py b/bot/exts/holidays/easter/earth_photos.py index e60e2626..5008b24d 100644 --- a/bot/exts/holidays/easter/earth_photos.py +++ b/bot/exts/holidays/easter/earth_photos.py @@ -23,7 +23,7 @@ class EarthPhotos(commands.Cog): async with ctx.typing(): async with self.bot.http_session.get( API_URL, - params={"query": "planet_earth", "client_id": Tokens.unsplash_access_key} + params={"query": "planet_earth", "client_id": Tokens.unsplash} ) as r: jsondata = await r.json() linksdata = jsondata.get("urls") @@ -37,7 +37,7 @@ class EarthPhotos(commands.Cog): rf = "?utm_source=Sir%20Lancebot&utm_medium=referral" async with self.bot.http_session.get( downloadlinksdata.get("download_location"), - params={"client_id": Tokens.unsplash_access_key} + params={"client_id": Tokens.unsplash} ) as _: pass @@ -59,7 +59,7 @@ class EarthPhotos(commands.Cog): async def setup(bot: Bot) -> None: """Load the Earth Photos cog.""" - if not Tokens.unsplash_access_key: + if not Tokens.unsplash: log.warning("No Unsplash access key found. Cog not loading.") return await bot.add_cog(EarthPhotos(bot)) diff --git a/bot/exts/utilities/wolfram.py b/bot/exts/utilities/wolfram.py index a2f1228a..7dc4d7c3 100644 --- a/bot/exts/utilities/wolfram.py +++ b/bot/exts/utilities/wolfram.py @@ -10,12 +10,12 @@ from discord.ext import commands from discord.ext.commands import BucketType, Cog, Context, check, group from bot.bot import Bot -from bot.constants import Colours, STAFF_ROLES, Wolfram +from bot.constants import Colours, STAFF_ROLES, Tokens, Wolfram from bot.utils.pagination import ImagePaginator log = logging.getLogger(__name__) -APPID = Wolfram.key +APPID = Tokens.wolfram DEFAULT_OUTPUT_FORMAT = "JSON" QUERY = "http://api.wolframalpha.com/v2/{request}" WOLF_IMAGE = "https://www.symbols.com/gi.php?type=1&id=2886&i=1" -- cgit v1.2.3 From 9b203e6f9eccc71644b76900c2a7b7084d6a240c Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:26:15 +0100 Subject: update Redis config This also renames RedisConfig to Redis, the way we have it in Python --- bot/__main__.py | 8 ++++---- bot/constants.py | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/__main__.py b/bot/__main__.py index 970614ce..bd3df263 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -19,11 +19,11 @@ log = logging.getLogger(__name__) async def _create_redis_session() -> RedisSession: """Create and connect to a redis session.""" redis_session = RedisSession( - host=constants.RedisConfig.host, - port=constants.RedisConfig.port, - password=constants.RedisConfig.password, + host=constants.Redis.host, + port=constants.Redis.port, + password=constants.Redis.password, max_connections=20, - use_fakeredis=constants.RedisConfig.use_fakeredis, + use_fakeredis=constants.Redis.use_fakeredis, global_namespace="bot", decode_responses=True, ) diff --git a/bot/constants.py b/bot/constants.py index 5f853521..81db539a 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -21,7 +21,7 @@ __all__ = ( "Tokens", "Wolfram", "Reddit", - "RedisConfig", + "Redis", "RedirectOutput", "PYTHON_PREFIX", "MODERATION_ROLES", @@ -321,17 +321,16 @@ class _Wolfram(EnvConfig): Wolfram = _Wolfram() -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") +class _Redis(EnvConfig): + EnvConfig.Config.env_prefix = "redis_" + host = "redis.default.svc.cluster.local" + port = 6379 + password = "" + use_fakeredis = False -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" + +Redis = _Redis() class Source: -- cgit v1.2.3 From 54eaf1402630347b0be689ee1b60214087d542ab Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:26:52 +0100 Subject: update Reddit --- bot/constants.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 81db539a..2a28cd22 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -342,13 +342,17 @@ class RedirectOutput: delete_delay: int = 10 -class Reddit: +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 = "" + secret = "" + webhook = 635408384794951680 + +Reddit = _Reddit() # Default role combinations MODERATION_ROLES = {Roles.moderation_team, Roles.admins, Roles.owners} -- cgit v1.2.3 From d5d44e3689bb8d25b4eb70545cbe0d086f8892e7 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:34:38 +0100 Subject: Revert "redeem lost bot references" This reverts commit 8d4fa84652e98dcb92fddf0a776c32634e0dfcf0. --- bot/constants.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 2a28cd22..162f8aca 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -171,7 +171,7 @@ class Emojis: trashcan = environ.get( "TRASHCAN_EMOJI", - "\N{WASTEBASKET}" if Bot.debug else "<:trashcan:637136429717389331>", + "\N{WASTEBASKET}" if Client.debug else "<:trashcan:637136429717389331>", ) ok_hand = ":ok_hand:" @@ -274,9 +274,8 @@ class Month(enum.IntEnum): # If a month override was configured, check that it's a valid Month # Prevents delaying an exception after the bot starts -if Bot.month_override is not None: - Month(Bot.month_override) - +if Client.month_override is not None: + Month(Client.month_override) class _Roles(EnvConfig): -- cgit v1.2.3 From a976c7888423e657f946ac567695c7da23e9f9a7 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:38:18 +0100 Subject: revert renaming of Client to Bot --- bot/__main__.py | 10 +++++----- bot/bot.py | 4 ++-- bot/constants.py | 14 +++++++------- bot/exts/core/extensions.py | 4 ++-- bot/exts/core/help.py | 4 ++-- bot/exts/core/internal_eval/_internal_eval.py | 2 +- bot/exts/fun/fun.py | 4 ++-- bot/exts/fun/minesweeper.py | 6 +++--- bot/exts/fun/trivia_quiz.py | 4 ++-- bot/exts/holidays/halloween/spookynamerate.py | 20 ++++++++++---------- bot/exts/holidays/pride/pride_leader.py | 2 +- bot/exts/utilities/cheatsheet.py | 6 +++--- bot/exts/utilities/logging.py | 2 +- bot/exts/utilities/wtf_python.py | 6 +++--- bot/utils/__init__.py | 6 +++--- bot/utils/checks.py | 2 +- 16 files changed, 48 insertions(+), 48 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/__main__.py b/bot/__main__.py index bd3df263..829819fb 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -62,11 +62,11 @@ async def main() -> None: async with aiohttp.ClientSession() as session: bot.instance = Bot( - guild_id=constants.Bot.guild, + guild_id=constants.Client.guild, http_session=session, redis_session=await _create_redis_session(), - command_prefix=commands.when_mentioned_or(constants.Bot.prefix), - activity=discord.Game(name=f"Commands: {constants.Bot.prefix}help"), + command_prefix=commands.when_mentioned_or(constants.Client.prefix), + activity=discord.Game(name=f"Commands: {constants.Client.prefix}help"), case_insensitive=True, allowed_mentions=discord.AllowedMentions(everyone=False, roles=allowed_roles), intents=intents, @@ -78,10 +78,10 @@ async def main() -> None: channels=constants.WHITELISTED_CHANNELS, roles=constants.STAFF_ROLES, )) - if constants.Bot.in_ci: + if constants.Client.in_ci: await test_bot_in_ci(_bot) else: - await _bot.start(constants.Bot.token) + await _bot.start(constants.Client.token) asyncio.run(main()) diff --git a/bot/bot.py b/bot/bot.py index b9f1a62c..da19bdd9 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -23,12 +23,12 @@ class Bot(BotBase): that the upload was successful. See the `mock_in_debug` decorator for further details. """ - name = constants.Bot.name + name = constants.Client.name @property def member(self) -> Optional[discord.Member]: """Retrieves the guild member object for the bot.""" - guild = self.get_guild(constants.Bot.guild) + guild = self.get_guild(constants.Client.guild) if not guild: return None return guild.me diff --git a/bot/constants.py b/bot/constants.py index 162f8aca..4a977b79 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -4,13 +4,12 @@ from os import environ from pydantic import BaseSettings - __all__ = ( "Branding", "Cats", "Channels", "Categories", - "Bot", + "Client", "Logging", "Colours", "Emojis", @@ -102,8 +101,8 @@ Categories = _Categories() CODEJAM_CATEGORY_NAME = "Code Jam" # Name of the codejam team categories -class _Bot(EnvConfig): - EnvConfig.Config.env_prefix = "bot_" +class _Client(EnvConfig): + EnvConfig.Config.env_prefix = "client_" name = "Sir Lancebot" guild = 267624335836053506 @@ -116,13 +115,13 @@ class _Bot(EnvConfig): month_override: int | None = None -Bot = _Bot() +Client = _Client() class _Logging(EnvConfig): EnvConfig.Config.env_prefix = "logging_" - debug = Bot.debug + debug = Client.debug file_logs = False trace_loggers = "" @@ -277,6 +276,7 @@ class Month(enum.IntEnum): if Client.month_override is not None: Month(Client.month_override) + class _Roles(EnvConfig): EnvConfig.Config.env_prefix = "roles_" @@ -286,7 +286,7 @@ class _Roles(EnvConfig): moderation_team = 267629731250176001 helpers = 267630620367257601 core_developers = 587606783669829632 - everyone = Bot.guild + everyone = Client.guild Roles = _Roles() diff --git a/bot/exts/core/extensions.py b/bot/exts/core/extensions.py index 3b1a1e8a..1d22cf37 100644 --- a/bot/exts/core/extensions.py +++ b/bot/exts/core/extensions.py @@ -11,7 +11,7 @@ from pydis_core.utils._extensions import unqualify from bot import exts from bot.bot import Bot -from bot.constants import Bot, Emojis, MODERATION_ROLES, Roles +from bot.constants import Client, Emojis, MODERATION_ROLES, Roles from bot.utils.checks import with_role_check from bot.utils.pagination import LinePaginator @@ -155,7 +155,7 @@ class Extensions(commands.Cog): embed = Embed(colour=Colour.og_blurple()) embed.set_author( name="Extensions List", - url=Bot.github_repo, + url=Client.github_bot_repo, icon_url=str(self.bot.user.display_avatar.url) ) diff --git a/bot/exts/core/help.py b/bot/exts/core/help.py index d031cafe..30deaff4 100644 --- a/bot/exts/core/help.py +++ b/bot/exts/core/help.py @@ -311,7 +311,7 @@ class HelpSession: self._pages = paginator.pages async def _add_command_signature(self, paginator: LinePaginator) -> None: - prefix = constants.Bot.prefix + prefix = constants.Client.prefix signature = self._get_command_params(self.query) paginator.add_line(f"**```\n{prefix}{signature}\n```**") @@ -405,7 +405,7 @@ class HelpSession: if isinstance(self.query, commands.Command): prefix = "" else: - prefix = constants.Bot.prefix + prefix = constants.Client.prefix signature = self._get_command_params(command) info = f"{strikeout}**`{prefix}{signature}`**{strikeout}" diff --git a/bot/exts/core/internal_eval/_internal_eval.py b/bot/exts/core/internal_eval/_internal_eval.py index 7365effc..2daf8ef9 100644 --- a/bot/exts/core/internal_eval/_internal_eval.py +++ b/bot/exts/core/internal_eval/_internal_eval.py @@ -43,7 +43,7 @@ class InternalEval(commands.Cog): self.bot = bot self.locals = {} - if Bot.debug: + if Client.debug: self.internal_group.add_check(commands.is_owner().predicate) @staticmethod diff --git a/bot/exts/fun/fun.py b/bot/exts/fun/fun.py index aa12b079..16279dd7 100644 --- a/bot/exts/fun/fun.py +++ b/bot/exts/fun/fun.py @@ -12,7 +12,7 @@ from discord.ext.commands import BadArgument, Cog, Context from pydis_core.utils.commands import clean_text_or_reply from bot.bot import Bot -from bot.constants import Bot, Colours, Emojis +from bot.constants import Client, Colours, Emojis from bot.utils import helpers, messages log = logging.getLogger(__name__) @@ -58,7 +58,7 @@ class Fun(Cog): dice = " ".join(self._get_random_die() for _ in range(num_rolls)) await ctx.send(dice) else: - raise BadArgument(f"`{Bot.prefix}roll` only supports between 1 and 6 rolls.") + raise BadArgument(f"`{Client.prefix}roll` only supports between 1 and 6 rolls.") @commands.command(name="randomcase", aliases=("rcase", "randomcaps", "rcaps",)) async def randomcase_command(self, ctx: Context, *, text: str | None) -> None: diff --git a/bot/exts/fun/minesweeper.py b/bot/exts/fun/minesweeper.py index cd1f6711..f16b1db2 100644 --- a/bot/exts/fun/minesweeper.py +++ b/bot/exts/fun/minesweeper.py @@ -8,7 +8,7 @@ import discord from discord.ext import commands from bot.bot import Bot -from bot.constants import Bot +from bot.constants import Client from bot.utils.converters import CoordinateConverter from bot.utils.exceptions import UserNotPlayingError @@ -117,8 +117,8 @@ class Minesweeper(commands.Cog): try: await ctx.author.send( - f"Play by typing: `{Bot.prefix}ms reveal xy [xy]` or `{Bot.prefix}ms flag xy [xy]` \n" - f"Close the game with `{Bot.prefix}ms end`\n" + f"Play by typing: `{Client.prefix}ms reveal xy [xy]` or `{Client.prefix}ms flag xy [xy]` \n" + f"Close the game with `{Client.prefix}ms end`\n" ) except discord.errors.Forbidden: log.debug(f"{ctx.author.name} ({ctx.author.id}) has disabled DMs from server members.") diff --git a/bot/exts/fun/trivia_quiz.py b/bot/exts/fun/trivia_quiz.py index 546b796b..31652374 100644 --- a/bot/exts/fun/trivia_quiz.py +++ b/bot/exts/fun/trivia_quiz.py @@ -16,7 +16,7 @@ from discord.ext import commands, tasks from rapidfuzz import fuzz from bot.bot import Bot -from bot.constants import Bot, Colours, MODERATION_ROLES, NEGATIVE_REPLIES +from bot.constants import Client, Colours, MODERATION_ROLES, NEGATIVE_REPLIES logger = logging.getLogger(__name__) @@ -332,7 +332,7 @@ class TriviaQuiz(commands.Cog): if self.game_status[ctx.channel.id]: await ctx.send( "Game is already running... " - f"do `{Bot.prefix}quiz stop`" + f"do `{Client.prefix}quiz stop`" ) return diff --git a/bot/exts/holidays/halloween/spookynamerate.py b/bot/exts/holidays/halloween/spookynamerate.py index fd3f4247..a76e5e12 100644 --- a/bot/exts/holidays/halloween/spookynamerate.py +++ b/bot/exts/holidays/halloween/spookynamerate.py @@ -15,7 +15,7 @@ from discord.ext import tasks from discord.ext.commands import Cog, Context, group from bot.bot import Bot -from bot.constants import Channels, Bot, Colours, Month +from bot.constants import Channels, Client, Colours, Month from bot.utils.decorators import InMonthCheckFailure logger = getLogger(__name__) @@ -38,7 +38,7 @@ PING = "<@{id}>" EMOJI_MESSAGE = "\n".join(f"- {emoji} {val}" for emoji, val in EMOJIS_VAL.items()) HELP_MESSAGE_DICT = { "title": "Spooky Name Rate", - "description": f"Help for the `{Bot.prefix}spookynamerate` command", + "description": f"Help for the `{Client.prefix}spookynamerate` command", "color": Colours.soft_orange, "fields": [ { @@ -54,12 +54,12 @@ HELP_MESSAGE_DICT = { }, { "name": "How do I add my spookified name?", - "value": f"Simply type `{Bot.prefix}spookynamerate add my name`", + "value": f"Simply type `{Client.prefix}spookynamerate add my name`", "inline": False, }, { "name": "How do I *delete* my spookified name?", - "value": f"Simply type `{Bot.prefix}spookynamerate delete`", + "value": f"Simply type `{Client.prefix}spookynamerate delete`", "inline": False, }, ], @@ -141,7 +141,7 @@ class SpookyNameRate(Cog): if data["author"] == ctx.author.id: await ctx.send( "But you have already added an entry! Type " - f"`{Bot.prefix}spookynamerate " + f"`{Client.prefix}spookynamerate " "delete` to delete it, and then you can add it again" ) return @@ -183,7 +183,7 @@ class SpookyNameRate(Cog): return await ctx.send( - f"But you don't have an entry... :eyes: Type `{Bot.prefix}spookynamerate add your entry`" + f"But you don't have an entry... :eyes: Type `{Client.prefix}spookynamerate add your entry`" ) @Cog.listener() @@ -223,7 +223,7 @@ class SpookyNameRate(Cog): "Okkey... Welcome to the **Spooky Name Rate Game**! It's a relatively simple game.\n" f"Everyday, a random name will be sent in <#{Channels.sir_lancebot_playground}> " "and you need to try and spookify it!\nRegister your name using " - f"`{Bot.prefix}spookynamerate add spookified name`" + f"`{Client.prefix}spookynamerate add spookified name`" ) await self.data.set("first_time", False) @@ -348,7 +348,7 @@ class SpookyNameRate(Cog): embed.add_field( name=(self.bot.get_user(data["author"]) or await self.bot.fetch_user(data["author"])).name, - value=f"[{(data)['name']}](https://discord.com/channels/{Bot.guild}/{channel.id}/{message_id})", + value=f"[{(data)['name']}](https://discord.com/channels/{Client.guild}/{channel.id}/{message_id})", ) return embed @@ -368,9 +368,9 @@ class SpookyNameRate(Cog): if SpookyNameRate.debug: return True - if not Bot.month_override: + if not Client.month_override: return datetime.utcnow().month == Month.OCTOBER - return Bot.month_override == Month.OCTOBER + return Client.month_override == Month.OCTOBER def cog_check(self, ctx: Context) -> bool: """A command to check whether the command is being called in October.""" diff --git a/bot/exts/holidays/pride/pride_leader.py b/bot/exts/holidays/pride/pride_leader.py index 94ba612e..120e9e16 100644 --- a/bot/exts/holidays/pride/pride_leader.py +++ b/bot/exts/holidays/pride/pride_leader.py @@ -82,7 +82,7 @@ class PrideLeader(commands.Cog): ) embed.add_field( name="For More Information", - value=f"Do `{constants.Bot.prefix}wiki {name}`" + value=f"Do `{constants.Client.prefix}wiki {name}`" f" in <#{constants.Channels.sir_lancebot_playground}>", inline=False ) diff --git a/bot/exts/utilities/cheatsheet.py b/bot/exts/utilities/cheatsheet.py index 48956de3..d7eb4917 100644 --- a/bot/exts/utilities/cheatsheet.py +++ b/bot/exts/utilities/cheatsheet.py @@ -17,9 +17,9 @@ Unknown cheat sheet. Please try to reformulate your query. **Examples**: ```md -{constants.Bot.prefix}cht read json -{constants.Bot.prefix}cht hello world -{constants.Bot.prefix}cht lambda +{constants.Client.prefix}cht read json +{constants.Client.prefix}cht hello world +{constants.Client.prefix}cht lambda ``` If the problem persists send a message in <#{Channels.dev_contrib}> """ diff --git a/bot/exts/utilities/logging.py b/bot/exts/utilities/logging.py index 7f520522..00febc2c 100644 --- a/bot/exts/utilities/logging.py +++ b/bot/exts/utilities/logging.py @@ -23,7 +23,7 @@ class Logging(Cog): async def check_channels(self) -> None: """Verifies that all channel constants refer to channels which exist.""" - if constants.Bot.debug: + if constants.Client.debug: log.info("Skipping Channels Check.") return diff --git a/bot/exts/utilities/wtf_python.py b/bot/exts/utilities/wtf_python.py index f5db7a96..0c0375cb 100644 --- a/bot/exts/utilities/wtf_python.py +++ b/bot/exts/utilities/wtf_python.py @@ -21,9 +21,9 @@ Unknown WTF Python Query. Please try to reformulate your query. **Examples**: ```md -{constants.Bot.prefix}wtf wild imports -{constants.Bot.prefix}wtf subclass -{constants.Bot.prefix}wtf del +{constants.Client.prefix}wtf wild imports +{constants.Client.prefix}wtf subclass +{constants.Client.prefix}wtf del ``` If the problem persists send a message in <#{constants.Channels.dev_contrib}> """ diff --git a/bot/utils/__init__.py b/bot/utils/__init__.py index 69439d91..91682dbc 100644 --- a/bot/utils/__init__.py +++ b/bot/utils/__init__.py @@ -9,7 +9,7 @@ from typing import Optional import discord from discord.ext.commands import BadArgument, Context -from bot.constants import Bot, Month +from bot.constants import Client, Month from bot.utils.pagination import LinePaginator @@ -25,8 +25,8 @@ def resolve_current_month() -> Month: If the env variable was set, current month always resolves to the configured value. Otherwise, the current UTC month is given. """ - if Bot.month_override is not None: - return Month(Bot.month_override) + if Client.month_override is not None: + return Month(Client.month_override) else: return Month(datetime.utcnow().month) diff --git a/bot/utils/checks.py b/bot/utils/checks.py index f21d2ddd..857b6746 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -74,7 +74,7 @@ def in_whitelist_check( return True category = getattr(ctx_channel, "category", None) - if category and category.name == constants.CODEJAM_CATEGORY_NAME: + if category and category.name == constants.codejam_categories_name: log.trace(f"{ctx.author} may use the `{ctx.command.name}` command as they are in a codejam team channel.") return True -- cgit v1.2.3 From f57fbfb7dea0990b0ac6fddfa9b04c862801c29b Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 1 May 2023 14:47:55 +0100 Subject: move lovefest role under the Roles class --- bot/constants.py | 13 ++----------- bot/exts/holidays/valentines/be_my_valentine.py | 6 +++--- bot/exts/holidays/valentines/lovecalculator.py | 6 +++--- 3 files changed, 8 insertions(+), 17 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 4a977b79..5f70c8b9 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -14,7 +14,6 @@ __all__ = ( "Colours", "Emojis", "Icons", - "Lovefest", "Month", "Roles", "Tokens", @@ -243,16 +242,6 @@ class Icons: ) -class _Lovefest(EnvConfig): - - EnvConfig.Config.env_prefix = "lovefest_" - - role_id = 542431903886606399 - - -Lovefest = _Lovefest() - - class Month(enum.IntEnum): JANUARY = 1 FEBRUARY = 2 @@ -288,6 +277,8 @@ class _Roles(EnvConfig): core_developers = 587606783669829632 everyone = Client.guild + lovefest = 542431903886606399 + Roles = _Roles() diff --git a/bot/exts/holidays/valentines/be_my_valentine.py b/bot/exts/holidays/valentines/be_my_valentine.py index 5ffd14e6..3a2beef3 100644 --- a/bot/exts/holidays/valentines/be_my_valentine.py +++ b/bot/exts/holidays/valentines/be_my_valentine.py @@ -7,7 +7,7 @@ import discord from discord.ext import commands from bot.bot import Bot -from bot.constants import Channels, Colours, Lovefest, Month, PYTHON_PREFIX +from bot.constants import Channels, Colours, Month, PYTHON_PREFIX, Roles from bot.utils.decorators import in_month from bot.utils.exceptions import MovedCommandError @@ -60,7 +60,7 @@ class BeMyValentine(commands.Cog): # This command should only be used in the server raise commands.UserInputError("You are supposed to use this command in the server.") - if Lovefest.role_id not in [role.id for role in user.roles]: + if Roles.lovefest not in [role.id for role in user.roles]: raise commands.UserInputError( f"You cannot send a valentine to {user} as they do not have the lovefest role!" ) @@ -95,7 +95,7 @@ class BeMyValentine(commands.Cog): example : .bemyvalentine secret Iceman#6508 Hey I love you, wanna hang around ? (sends the custom message to Iceman in DM making you anonymous) """ - if Lovefest.role_id not in [role.id for role in user.roles]: + if Roles.lovefest not in [role.id for role in user.roles]: await ctx.message.delete() raise commands.UserInputError( f"You cannot send a valentine to {user} as they do not have the lovefest role!" diff --git a/bot/exts/holidays/valentines/lovecalculator.py b/bot/exts/holidays/valentines/lovecalculator.py index c212e833..eab3d083 100644 --- a/bot/exts/holidays/valentines/lovecalculator.py +++ b/bot/exts/holidays/valentines/lovecalculator.py @@ -12,7 +12,7 @@ from discord.ext import commands from discord.ext.commands import BadArgument, Cog, clean_content from bot.bot import Bot -from bot.constants import Channels, Lovefest, Month, PYTHON_PREFIX +from bot.constants import Channels, Month, PYTHON_PREFIX, Roles from bot.utils.decorators import in_month log = logging.getLogger(__name__) @@ -45,8 +45,8 @@ class LoveCalculator(Cog): Running .love @chrisjl#2655 @joe#6000 will yield the same result as before. """ if ( - Lovefest.role_id not in [role.id for role in who.roles] - or (whom is not None and Lovefest.role_id not in [role.id for role in whom.roles]) + Roles.lovefest not in [role.id for role in who.roles] + or (whom is not None and Roles.lovefest not in [role.id for role in whom.roles]) ): raise BadArgument( "This command can only be ran against members with the lovefest role! " -- cgit v1.2.3 From 12be2fdf771a1a25c2c135516746002154135dbf Mon Sep 17 00:00:00 2001 From: shtlrs Date: Fri, 5 May 2023 22:08:09 +0100 Subject: use `SecretStr` for all secrets --- bot/__main__.py | 2 +- bot/constants.py | 33 +++++++++++----------- .../events/hacktoberfest/hacktober-issue-finder.py | 2 +- bot/exts/events/hacktoberfest/hacktoberstats.py | 4 +-- bot/exts/fun/game.py | 4 +-- bot/exts/fun/movie.py | 4 +-- bot/exts/fun/snakes/_snakes_cog.py | 6 ++-- bot/exts/fun/space.py | 2 +- bot/exts/holidays/easter/earth_photos.py | 4 +-- bot/exts/holidays/halloween/scarymovie.py | 4 +-- bot/exts/holidays/halloween/spookygif.py | 2 +- bot/exts/utilities/githubinfo.py | 2 +- bot/exts/utilities/reddit.py | 2 +- bot/exts/utilities/wolfram.py | 2 +- 14 files changed, 37 insertions(+), 36 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/__main__.py b/bot/__main__.py index 829819fb..934dc0a9 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -21,7 +21,7 @@ async def _create_redis_session() -> RedisSession: redis_session = RedisSession( host=constants.Redis.host, port=constants.Redis.port, - password=constants.Redis.password, + password=constants.Redis.password.get_secret_value(), max_connections=20, use_fakeredis=constants.Redis.use_fakeredis, global_namespace="bot", diff --git a/bot/constants.py b/bot/constants.py index 5f70c8b9..80ebf077 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -2,7 +2,7 @@ import enum import logging from os import environ -from pydantic import BaseSettings +from pydantic import BaseSettings, SecretStr __all__ = ( "Branding", @@ -106,7 +106,7 @@ class _Client(EnvConfig): name = "Sir Lancebot" guild = 267624335836053506 prefix = "." - token = "" + token: SecretStr debug = True in_ci = False github_repo = "https://github.com/python-discord/sir-lancebot" @@ -116,6 +116,9 @@ class _Client(EnvConfig): Client = _Client() +print(Client.token) +print(Client.token.get_secret_value()) + class _Logging(EnvConfig): EnvConfig.Config.env_prefix = "logging_" @@ -286,17 +289,15 @@ Roles = _Roles() class _Tokens(EnvConfig): EnvConfig.Config.env_prefix = "tokens_" - giphy = "" - aoc_session_cookie = "" - omdb = "" - youtube = "" - tmdb = "" - nasa = "" - igdb_client_id = "" - igdb_client_secret = "" - github = "" - unsplash = "" - wolfram = "" + giphy: SecretStr | None + youtube: SecretStr | None + tmdb: SecretStr | None + nasa: SecretStr | None + igdb_client_id: SecretStr | None + igdb_client_secret: SecretStr | None + github: SecretStr | None + unsplash: SecretStr | None + wolfram: SecretStr | None Tokens = _Tokens() @@ -316,7 +317,7 @@ class _Redis(EnvConfig): host = "redis.default.svc.cluster.local" port = 6379 - password = "" + password: SecretStr | None use_fakeredis = False @@ -337,8 +338,8 @@ class _Reddit(EnvConfig): subreddits = ["r/Python"] - client_id = "" - secret = "" + client_id: SecretStr | None + secret: SecretStr | None webhook = 635408384794951680 diff --git a/bot/exts/events/hacktoberfest/hacktober-issue-finder.py b/bot/exts/events/hacktoberfest/hacktober-issue-finder.py index aeffc8d7..4f7bef5d 100644 --- a/bot/exts/events/hacktoberfest/hacktober-issue-finder.py +++ b/bot/exts/events/hacktoberfest/hacktober-issue-finder.py @@ -18,7 +18,7 @@ REQUEST_HEADERS = { "User-Agent": "Python Discord Hacktoberbot", "Accept": "application / vnd.github.v3 + json" } -if GITHUB_TOKEN := Tokens.github: +if GITHUB_TOKEN := Tokens.github.get_secret_value(): REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}" diff --git a/bot/exts/events/hacktoberfest/hacktoberstats.py b/bot/exts/events/hacktoberfest/hacktoberstats.py index c29e24b0..0b4266d8 100644 --- a/bot/exts/events/hacktoberfest/hacktoberstats.py +++ b/bot/exts/events/hacktoberfest/hacktoberstats.py @@ -24,8 +24,8 @@ REQUEST_HEADERS = {"User-Agent": "Python Discord Hacktoberbot"} # using repo topics API during preview period requires an accept header GITHUB_TOPICS_ACCEPT_HEADER = {"Accept": "application/vnd.github.mercy-preview+json"} if GITHUB_TOKEN := Tokens.github: - REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}" - GITHUB_TOPICS_ACCEPT_HEADER["Authorization"] = f"token {GITHUB_TOKEN}" + REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN.get_secret_value()}" + GITHUB_TOPICS_ACCEPT_HEADER["Authorization"] = f"token {GITHUB_TOKEN.get_secret_value()}" GITHUB_NONEXISTENT_USER_MESSAGE = ( "The listed users cannot be searched either because the users do not exist " diff --git a/bot/exts/fun/game.py b/bot/exts/fun/game.py index a8b0b3a0..c38dc063 100644 --- a/bot/exts/fun/game.py +++ b/bot/exts/fun/game.py @@ -20,8 +20,8 @@ from bot.utils.pagination import ImagePaginator, LinePaginator # Base URL of IGDB API BASE_URL = "https://api.igdb.com/v4" -CLIENT_ID = Tokens.igdb_client_id -CLIENT_SECRET = Tokens.igdb_client_secret +CLIENT_ID = Tokens.igdb_client_id.get_secret_value() +CLIENT_SECRET = Tokens.igdb_client_secret.get_secret_value() # The number of seconds before expiry that we attempt to re-fetch a new access token ACCESS_TOKEN_RENEWAL_WINDOW = 60*60*24*2 diff --git a/bot/exts/fun/movie.py b/bot/exts/fun/movie.py index 422a83ac..73ef0a3c 100644 --- a/bot/exts/fun/movie.py +++ b/bot/exts/fun/movie.py @@ -22,7 +22,7 @@ THUMBNAIL_URL = "https://i.imgur.com/LtFtC8H.png" # Define movie params, that will be used for every movie request MOVIE_PARAMS = { - "api_key": Tokens.tmdb, + "api_key": Tokens.tmdb.get_secret_value(), "language": "en-US" } @@ -106,7 +106,7 @@ class Movie(Cog): """Return JSON of TMDB discover request.""" # Define params of request params = { - "api_key": Tokens.tmdb, + "api_key": Tokens.tmdb.get_secret_value(), "language": "en-US", "sort_by": "popularity.desc", "include_adult": "false", diff --git a/bot/exts/fun/snakes/_snakes_cog.py b/bot/exts/fun/snakes/_snakes_cog.py index d0542c23..892a3dd2 100644 --- a/bot/exts/fun/snakes/_snakes_cog.py +++ b/bot/exts/fun/snakes/_snakes_cog.py @@ -773,7 +773,7 @@ class Snakes(Cog): "query": "snake", "page": page, "language": "en-US", - "api_key": Tokens.tmdb, + "api_key": Tokens.tmdb.get_secret_value(), } ) data = await response.json() @@ -785,7 +785,7 @@ class Snakes(Cog): f"https://api.themoviedb.org/3/movie/{movie}", params={ "language": "en-US", - "api_key": Tokens.tmdb, + "api_key": Tokens.tmdb.get_secret_value(), } ) data = await response.json() @@ -1095,7 +1095,7 @@ class Snakes(Cog): "part": "snippet", "q": urllib.parse.quote_plus(query), "type": "video", - "key": Tokens.youtube + "key": Tokens.youtube.get_secret_value() } ) response = await response.json() diff --git a/bot/exts/fun/space.py b/bot/exts/fun/space.py index 22a89050..c688b281 100644 --- a/bot/exts/fun/space.py +++ b/bot/exts/fun/space.py @@ -210,7 +210,7 @@ class Space(Cog): """Fetch information from NASA API, return result.""" params = {} if use_api_key: - params["api_key"] = Tokens.nasa + params["api_key"] = Tokens.nasa.get_secret_value() # Add additional parameters to request parameters only when they provided by user if additional_params is not None: diff --git a/bot/exts/holidays/easter/earth_photos.py b/bot/exts/holidays/easter/earth_photos.py index 5008b24d..013122c8 100644 --- a/bot/exts/holidays/easter/earth_photos.py +++ b/bot/exts/holidays/easter/earth_photos.py @@ -23,7 +23,7 @@ class EarthPhotos(commands.Cog): async with ctx.typing(): async with self.bot.http_session.get( API_URL, - params={"query": "planet_earth", "client_id": Tokens.unsplash} + params={"query": "planet_earth", "client_id": Tokens.unsplash.get_secret_value()} ) as r: jsondata = await r.json() linksdata = jsondata.get("urls") @@ -37,7 +37,7 @@ class EarthPhotos(commands.Cog): rf = "?utm_source=Sir%20Lancebot&utm_medium=referral" async with self.bot.http_session.get( downloadlinksdata.get("download_location"), - params={"client_id": Tokens.unsplash} + params={"client_id": Tokens.unsplash.get_secret_value()} ) as _: pass diff --git a/bot/exts/holidays/halloween/scarymovie.py b/bot/exts/holidays/halloween/scarymovie.py index 9f1a95fd..00c96153 100644 --- a/bot/exts/holidays/halloween/scarymovie.py +++ b/bot/exts/holidays/halloween/scarymovie.py @@ -36,7 +36,7 @@ class ScaryMovie(commands.Cog): """Selects a random movie and returns a JSON of movie details from TMDb.""" url = "https://api.themoviedb.org/3/discover/movie" params = { - "api_key": Tokens.tmdb, + "api_key": Tokens.tmdb.get_secret_value(), "with_genres": "27", "vote_count.gte": "5", "include_adult": "false" @@ -65,7 +65,7 @@ class ScaryMovie(commands.Cog): # Get full details and credits async with self.bot.http_session.get( url=f"https://api.themoviedb.org/3/movie/{selection_id}", - params={"api_key": Tokens.tmdb, "append_to_response": "credits"} + params={"api_key": Tokens.tmdb.get_secret_value(), "append_to_response": "credits"} ) as selection: return await selection.json() diff --git a/bot/exts/holidays/halloween/spookygif.py b/bot/exts/holidays/halloween/spookygif.py index 750e86ca..7a90a8a9 100644 --- a/bot/exts/holidays/halloween/spookygif.py +++ b/bot/exts/holidays/halloween/spookygif.py @@ -21,7 +21,7 @@ class SpookyGif(commands.Cog): async def spookygif(self, ctx: commands.Context) -> None: """Fetches a random gif from the GIPHY API and responds with it.""" async with ctx.typing(): - params = {"api_key": Tokens.giphy, "tag": "halloween", "rating": "g"} + params = {"api_key": Tokens.giphy.get_secret_value(), "tag": "halloween", "rating": "g"} # Make a GET request to the Giphy API to get a random halloween gif. async with self.bot.http_session.get(API_URL, params=params) as resp: data = await resp.json() diff --git a/bot/exts/utilities/githubinfo.py b/bot/exts/utilities/githubinfo.py index a7979718..4e008e9f 100644 --- a/bot/exts/utilities/githubinfo.py +++ b/bot/exts/utilities/githubinfo.py @@ -26,7 +26,7 @@ ISSUE_ENDPOINT = "https://api.github.com/repos/{user}/{repository}/issues/{numbe PR_ENDPOINT = "https://api.github.com/repos/{user}/{repository}/pulls/{number}" if Tokens.github: - REQUEST_HEADERS["Authorization"] = f"token {Tokens.github}" + REQUEST_HEADERS["Authorization"] = f"token {Tokens.github.get_secret_value()}" CODE_BLOCK_RE = re.compile( r"^`([^`\n]+)`" # Inline codeblock diff --git a/bot/exts/utilities/reddit.py b/bot/exts/utilities/reddit.py index 028c16bc..43a82aef 100644 --- a/bot/exts/utilities/reddit.py +++ b/bot/exts/utilities/reddit.py @@ -36,7 +36,7 @@ class Reddit(Cog): self.webhook = None self.access_token = None - self.client_auth = BasicAuth(RedditConfig.client_id, RedditConfig.secret) + self.client_auth = BasicAuth(RedditConfig.client_id.get_secret_value(), RedditConfig.secret.get_secret_value()) self.auto_poster_loop.start() diff --git a/bot/exts/utilities/wolfram.py b/bot/exts/utilities/wolfram.py index 7dc4d7c3..d06e8f03 100644 --- a/bot/exts/utilities/wolfram.py +++ b/bot/exts/utilities/wolfram.py @@ -15,7 +15,7 @@ from bot.utils.pagination import ImagePaginator log = logging.getLogger(__name__) -APPID = Tokens.wolfram +APPID = Tokens.wolfram.get_secret_value() DEFAULT_OUTPUT_FORMAT = "JSON" QUERY = "http://api.wolframalpha.com/v2/{request}" WOLF_IMAGE = "https://www.symbols.com/gi.php?type=1&id=2886&i=1" -- cgit v1.2.3 From 817247bbb6c1274ef1de1815ea13c69e093f79fc Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sat, 6 May 2023 12:31:52 +0100 Subject: give empty str as default to tokens --- bot/constants.py | 28 +++++++++++++--------------- bot/exts/utilities/wolfram.py | 4 ++-- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 80ebf077..c16faa9b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -116,9 +116,6 @@ class _Client(EnvConfig): Client = _Client() -print(Client.token) -print(Client.token.get_secret_value()) - class _Logging(EnvConfig): EnvConfig.Config.env_prefix = "logging_" @@ -289,15 +286,15 @@ Roles = _Roles() class _Tokens(EnvConfig): EnvConfig.Config.env_prefix = "tokens_" - giphy: SecretStr | None - youtube: SecretStr | None - tmdb: SecretStr | None - nasa: SecretStr | None - igdb_client_id: SecretStr | None - igdb_client_secret: SecretStr | None - github: SecretStr | None - unsplash: SecretStr | None - wolfram: SecretStr | None + giphy: SecretStr = "" + youtube: SecretStr = "" + tmdb: SecretStr = "" + nasa: SecretStr = "" + igdb_client_id: SecretStr = "" + igdb_client_secret: SecretStr = "" + github: SecretStr = "" + unsplash: SecretStr = "" + wolfram: SecretStr = "" Tokens = _Tokens() @@ -307,6 +304,7 @@ class _Wolfram(EnvConfig): EnvConfig.Config.env_prefix = "wolfram_" user_limit_day = 10 guild_limit_day = 67 + key: SecretStr = "" Wolfram = _Wolfram() @@ -317,7 +315,7 @@ class _Redis(EnvConfig): host = "redis.default.svc.cluster.local" port = 6379 - password: SecretStr | None + password: SecretStr = "" use_fakeredis = False @@ -338,8 +336,8 @@ class _Reddit(EnvConfig): subreddits = ["r/Python"] - client_id: SecretStr | None - secret: SecretStr | None + client_id: SecretStr = "" + secret: SecretStr = "" webhook = 635408384794951680 diff --git a/bot/exts/utilities/wolfram.py b/bot/exts/utilities/wolfram.py index d06e8f03..a036b50f 100644 --- a/bot/exts/utilities/wolfram.py +++ b/bot/exts/utilities/wolfram.py @@ -10,12 +10,12 @@ from discord.ext import commands from discord.ext.commands import BucketType, Cog, Context, check, group from bot.bot import Bot -from bot.constants import Colours, STAFF_ROLES, Tokens, Wolfram +from bot.constants import Colours, STAFF_ROLES, Wolfram from bot.utils.pagination import ImagePaginator log = logging.getLogger(__name__) -APPID = Tokens.wolfram.get_secret_value() +APPID = Wolfram.key.get_secret_value() DEFAULT_OUTPUT_FORMAT = "JSON" QUERY = "http://api.wolframalpha.com/v2/{request}" WOLF_IMAGE = "https://www.symbols.com/gi.php?type=1&id=2886&i=1" -- cgit v1.2.3 From f300ca786a0814f9b6656b275a4aaf95279fb30a Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sat, 6 May 2023 13:05:36 +0100 Subject: remove wolfram key from Tokens class --- bot/constants.py | 1 - 1 file changed, 1 deletion(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index c16faa9b..a484b4c9 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -294,7 +294,6 @@ class _Tokens(EnvConfig): igdb_client_secret: SecretStr = "" github: SecretStr = "" unsplash: SecretStr = "" - wolfram: SecretStr = "" Tokens = _Tokens() -- cgit v1.2.3 From 17a8ecbce9f802b888df60d7b3aa669900f86cc8 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sat, 6 May 2023 13:19:00 +0100 Subject: remove `.env.server` env file --- bot/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index a484b4c9..a5f12fe2 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -42,7 +42,7 @@ class EnvConfig(BaseSettings): class Config: """Specify what .env files to load, and how to load them.""" - env_file = ".env.server", ".env", + env_file = ".env", env_file_encoding = "utf-8" -- cgit v1.2.3