Skip to content

Commit

Permalink
Bot prefix change (#871)
Browse files Browse the repository at this point in the history
* initial commit for Choose cog

* formatting

* fixed formatting for linter

* fixed mypy type errors

* fixed suggested locations

* added check for invalid prefix

* added list of invalid prefixes and a check in the custom prefix cog

* fixed formatting issues for automatic checks

* Changed Invalid prefix list location and updated error message

---------

Co-authored-by: Justin Kristensen <[email protected]>
  • Loading branch information
arock475 and jkriste authored Dec 14, 2023
1 parent ae5a0c4 commit 8423af8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ClemBot.Bot/bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import bot.bot_secrets as bot_secrets
from bot.clem_bot import ClemBot
from bot.consts import INVALID_PREFIXES
from bot.custom_prefix import CustomPrefix
from bot.messaging.messenger import Messenger
from bot.utils.scheduler import Scheduler
Expand Down Expand Up @@ -36,6 +37,9 @@ async def main() -> None:

# get the default prefix for the bot instance
prefix = bot_secrets.secrets.bot_prefix
if prefix in INVALID_PREFIXES:
bot_log.fatal(f"Invalid bot prefix")
sys.exit(0)

# Initialize the messenger here and inject it into the base bot class,
# this is so it can be reused later on
Expand Down
11 changes: 10 additions & 1 deletion ClemBot.Bot/bot/cogs/custom_prefix_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import bot.bot_secrets as bot_secrets
import bot.extensions as ext
from bot.clem_bot import ClemBot
from bot.consts import Claims, Colors
from bot.consts import INVALID_PREFIXES, Claims, Colors
from bot.utils.logging_utils import get_logger

log = get_logger(__name__)
Expand Down Expand Up @@ -45,6 +45,15 @@ async def prefix(self, ctx: ext.ClemBotCtx, *, prefix: str | None = None) -> Non
await ctx.send(embed=embed)
return

if prefix in INVALID_PREFIXES:
embed = discord.Embed(title="Error", color=Colors.Error)
embed.add_field(
name="Invalid prefix",
value=f"The given prefix `{prefix}` is not supported.",
)
await ctx.send(embed=embed)
return

if "`" in prefix:
embed = discord.Embed(title="Error", color=Colors.Error)
embed.add_field(name="Invalid prefix", value='Prefix can not contain " ` "')
Expand Down
1 change: 1 addition & 0 deletions ClemBot.Bot/bot/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ class Moderation:


TAG_INVOKE_REGEX = r"{tag_prefix}([^\s]+)"
INVALID_PREFIXES = ["<"]

0 comments on commit 8423af8

Please sign in to comment.