diff options
| author | 2023-05-06 16:13:14 +0100 | |
|---|---|---|
| committer | 2023-05-09 15:42:23 +0100 | |
| commit | 9266ce3a1b3e9f20ca01e8bfc75530f1ac21f7cf (patch) | |
| tree | e159a0fae7850d706d713cf2b49dfed2140ce655 | |
| parent | Apply fixes for ruff linting (diff) | |
Move unshared contants inside modules
| -rw-r--r-- | bot/constants.py | 27 | ||||
| -rw-r--r-- | bot/exts/core/error_handler.py | 5 | ||||
| -rw-r--r-- | bot/exts/core/source.py | 13 | ||||
| -rw-r--r-- | bot/exts/fun/catify.py | 16 | ||||
| -rw-r--r-- | bot/utils/checks.py | 3 | 
5 files changed, 22 insertions, 42 deletions
| diff --git a/bot/constants.py b/bot/constants.py index 230cccf0..cd866a0b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -5,8 +5,6 @@ from os import environ  from pydantic import BaseSettings, SecretStr  __all__ = ( -    "Branding", -    "Cats",      "Channels",      "Categories",      "Client", @@ -20,7 +18,6 @@ __all__ = (      "Wolfram",      "Reddit",      "Redis", -    "RedirectOutput",      "PYTHON_PREFIX",      "MODERATION_ROLES",      "STAFF_ROLES", @@ -46,19 +43,6 @@ class EnvConfig(BaseSettings):          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: -    cats = ["ᓚᘏᗢ", "ᘡᘏᗢ", "🐈", "ᓕᘏᗢ", "ᓇᘏᗢ", "ᓂᘏᗢ", "ᘣᘏᗢ", "ᕦᘏᗢ", "ᕂᘏᗢ"] - -  class _Channels(EnvConfig):      EnvConfig.Config.env_prefix = "channels_" @@ -97,8 +81,6 @@ class _Categories(EnvConfig):  Categories = _Categories() -CODEJAM_CATEGORY_NAME = "Code Jam"  # Name of the codejam team categories -  class _Client(EnvConfig):      EnvConfig.Config.env_prefix = "client_" @@ -329,15 +311,6 @@ class _Redis(EnvConfig):  Redis = _Redis() -class Source: -    github = "https://github.com/python-discord/sir-lancebot" -    github_avatar_url = "https://avatars1.githubusercontent.com/u/9919" - - -class RedirectOutput: -    delete_delay: int = 10 - -  class _Reddit(EnvConfig):      EnvConfig.Config.env_prefix = "reddit_" diff --git a/bot/exts/core/error_handler.py b/bot/exts/core/error_handler.py index fa478d43..62dee53c 100644 --- a/bot/exts/core/error_handler.py +++ b/bot/exts/core/error_handler.py @@ -8,7 +8,7 @@ from discord.ext import commands  from sentry_sdk import push_scope  from bot.bot import Bot -from bot.constants import Channels, Colours, ERROR_REPLIES, NEGATIVE_REPLIES, RedirectOutput +from bot.constants import Channels, Colours, ERROR_REPLIES, NEGATIVE_REPLIES  from bot.utils.commands import get_command_suggestions  from bot.utils.decorators import InChannelCheckFailure, InMonthCheckFailure  from bot.utils.exceptions import APIError, MovedCommandError, UserNotPlayingError @@ -16,6 +16,7 @@ from bot.utils.exceptions import APIError, MovedCommandError, UserNotPlayingErro  log = logging.getLogger(__name__) +DELETE_DELAY = 10  QUESTION_MARK_ICON = "https://cdn.discordapp.com/emojis/512367613339369475.png" @@ -184,7 +185,7 @@ class CommandErrorHandler(commands.Cog):              e.description = "\n".join(                  misspelled_content.replace(command_name, cmd, 1) for cmd in command_suggestions              ) -            await ctx.send(embed=e, delete_after=RedirectOutput.delete_delay) +            await ctx.send(embed=e, delete_after=DELETE_DELAY)  async def setup(bot: Bot) -> None: diff --git a/bot/exts/core/source.py b/bot/exts/core/source.py index 592156fc..7c67bcb5 100644 --- a/bot/exts/core/source.py +++ b/bot/exts/core/source.py @@ -5,10 +5,13 @@ from discord import Embed  from discord.ext import commands  from bot.bot import Bot -from bot.constants import Channels, Source, WHITELISTED_CHANNELS +from bot.constants import Channels, WHITELISTED_CHANNELS  from bot.utils.converters import SourceConverter, SourceType  from bot.utils.decorators import whitelist_override +GITHUB_BOT_URL = "https://github.com/python-discord/sir-lancebot" +BOT_AVATAR_URL = "https://avatars1.githubusercontent.com/u/9919" +  class BotSource(commands.Cog):      """Displays information about the bot's source code.""" @@ -19,8 +22,8 @@ class BotSource(commands.Cog):          """Display information and a GitHub link to the source code of a command, tag, or cog."""          if not source_item:              embed = Embed(title="Sir Lancebot's GitHub Repository") -            embed.add_field(name="Repository", value=f"[Go to GitHub]({Source.github})") -            embed.set_thumbnail(url=Source.github_avatar_url) +            embed.add_field(name="Repository", value=f"[Go to GitHub]({GITHUB_BOT_URL})") +            embed.set_thumbnail(url=BOT_AVATAR_URL)              await ctx.send(embed=embed)              return @@ -57,7 +60,7 @@ class BotSource(commands.Cog):          file_location = Path(filename).relative_to(Path.cwd()).as_posix() -        url = f"{Source.github}/blob/main/{file_location}{lines_extension}" +        url = f"{GITHUB_BOT_URL}/blob/main/{file_location}{lines_extension}"          return url, file_location, first_line_no or None @@ -73,7 +76,7 @@ class BotSource(commands.Cog):              description = source_object.description.splitlines()[0]          embed = Embed(title=title, description=description) -        embed.set_thumbnail(url=Source.github_avatar_url) +        embed.set_thumbnail(url=BOT_AVATAR_URL)          embed.add_field(name="Source Code", value=f"[Go to GitHub]({url})")          line_text = f":{first_line}" if first_line else ""          embed.set_footer(text=f"{location}{line_text}") diff --git a/bot/exts/fun/catify.py b/bot/exts/fun/catify.py index 67d17292..c1677cd8 100644 --- a/bot/exts/fun/catify.py +++ b/bot/exts/fun/catify.py @@ -5,9 +5,11 @@ from discord import AllowedMentions, Embed, Forbidden  from discord.ext import commands  from bot.bot import Bot -from bot.constants import Cats, Colours, NEGATIVE_REPLIES +from bot.constants import Colours, NEGATIVE_REPLIES  from bot.utils import helpers +CATS = ["ᓚᘏᗢ", "ᘡᘏᗢ", "🐈", "ᓕᘏᗢ", "ᓇᘏᗢ", "ᓂᘏᗢ", "ᘣᘏᗢ", "ᕦᘏᗢ", "ᕂᘏᗢ"] +  class Catify(commands.Cog):      """Cog for the catify command.""" @@ -35,7 +37,7 @@ class Catify(commands.Cog):                  await ctx.send(embed=embed)                  return -            display_name += f" | {random.choice(Cats.cats)}" +            display_name += f" | {random.choice(CATS)}"              await ctx.send(f"Your catified nickname is: `{display_name}`", allowed_mentions=AllowedMentions.none()) @@ -56,10 +58,10 @@ class Catify(commands.Cog):                  name = name.lower()                  if "cat" in name:                      if random.randint(0, 5) == 5: -                        string_list[index] = name.replace("cat", f"**{random.choice(Cats.cats)}**") +                        string_list[index] = name.replace("cat", f"**{random.choice(CATS)}**")                      else: -                        string_list[index] = name.replace("cat", random.choice(Cats.cats)) -                for cat in Cats.cats: +                        string_list[index] = name.replace("cat", random.choice(CATS)) +                for cat in CATS:                      if cat in name:                          string_list[index] = name.replace(cat, "cat") @@ -68,9 +70,9 @@ class Catify(commands.Cog):              for _ in range(random.randint(1, string_len)):                  # insert cat at random index                  if random.randint(0, 5) == 5: -                    string_list.insert(random.randint(0, len(string_list)), f"**{random.choice(Cats.cats)}**") +                    string_list.insert(random.randint(0, len(string_list)), f"**{random.choice(CATS)}**")                  else: -                    string_list.insert(random.randint(0, len(string_list)), random.choice(Cats.cats)) +                    string_list.insert(random.randint(0, len(string_list)), random.choice(CATS))              text = helpers.suppress_links(" ".join(string_list))              await ctx.send( diff --git a/bot/utils/checks.py b/bot/utils/checks.py index 418bb7ad..f1c2b3ce 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -9,6 +9,7 @@ from discord.ext.commands import (  from bot import constants  log = logging.getLogger(__name__) +CODEJAM_CATEGORY_NAME = "Code Jam"  class InWhitelistCheckFailure(CheckFailure): @@ -73,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 == 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 | 
