diff options
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/constants.py | 3 | ||||
| -rw-r--r-- | bot/exts/core/error_handler.py | 10 | ||||
| -rw-r--r-- | bot/exts/holidays/valentines/be_my_valentine.py | 40 | ||||
| -rw-r--r-- | bot/utils/exceptions.py | 7 | 
4 files changed, 27 insertions, 33 deletions
| diff --git a/bot/constants.py b/bot/constants.py index f4b1cab0..854fbe55 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -23,6 +23,7 @@ __all__ = (      "Reddit",      "RedisConfig",      "RedirectOutput", +    "PYTHON_PREFIX"      "MODERATION_ROLES",      "STAFF_ROLES",      "WHITELISTED_CHANNELS", @@ -34,6 +35,8 @@ __all__ = (  log = logging.getLogger(__name__) +PYTHON_PREFIX = "!" +  @dataclasses.dataclass  class AdventOfCodeLeaderboard:      id: str diff --git a/bot/exts/core/error_handler.py b/bot/exts/core/error_handler.py index fd2123e7..676a1e70 100644 --- a/bot/exts/core/error_handler.py +++ b/bot/exts/core/error_handler.py @@ -12,7 +12,7 @@ from sentry_sdk import push_scope  from bot.bot import Bot  from bot.constants import Channels, Colours, ERROR_REPLIES, NEGATIVE_REPLIES, RedirectOutput  from bot.utils.decorators import InChannelCheckFailure, InMonthCheckFailure -from bot.utils.exceptions import APIError, UserNotPlayingError +from bot.utils.exceptions import APIError, MovedCommandError, UserNotPlayingError  log = logging.getLogger(__name__) @@ -130,6 +130,14 @@ class CommandErrorHandler(commands.Cog):              )              return +        if isinstance(error, MovedCommandError): +            description = ( +                f"This command, `{ctx.prefix}{ctx.command.qualified_name}` has moved to `{error.new_command_name}`.\n" +                f"Please use `{error.new_command_name}` instead." +            ) +            await ctx.send(embed=self.error_embed(description, NEGATIVE_REPLIES)) +            return +          with push_scope() as scope:              scope.user = {                  "id": ctx.author.id, diff --git a/bot/exts/holidays/valentines/be_my_valentine.py b/bot/exts/holidays/valentines/be_my_valentine.py index 4d454c3a..1572d474 100644 --- a/bot/exts/holidays/valentines/be_my_valentine.py +++ b/bot/exts/holidays/valentines/be_my_valentine.py @@ -7,14 +7,16 @@ import discord  from discord.ext import commands  from bot.bot import Bot -from bot.constants import Channels, Colours, Lovefest, Month +from bot.constants import Channels, Colours, Lovefest, Month, PYTHON_PREFIX  from bot.utils.decorators import in_month -from bot.utils.extensions import invoke_help_command +from bot.utils.exceptions import MovedCommandError  log = logging.getLogger(__name__)  HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] +MOVED_COMMAND = f"{PYTHON_PREFIX}subscribe" +  class BeMyValentine(commands.Cog):      """A cog that sends Valentines to other users!""" @@ -30,40 +32,14 @@ class BeMyValentine(commands.Cog):          return loads(p.read_text("utf8"))      @in_month(Month.FEBRUARY) -    @commands.group(name="lovefest") +    @commands.command(name="lovefest", help=f"NOTE: This command has been moved to {MOVED_COMMAND}")      async def lovefest_role(self, ctx: commands.Context) -> None:          """ -        Subscribe or unsubscribe from the lovefest role. - -        The lovefest role makes you eligible to receive anonymous valentines from other users. +        Deprecated lovefest role command. -        1) use the command \".lovefest sub\" to get the lovefest role. -        2) use the command \".lovefest unsub\" to get rid of the lovefest role. +        This command has been moved to bot, and will be removed in the future.          """ -        if not ctx.invoked_subcommand: -            await invoke_help_command(ctx) - -    @lovefest_role.command(name="sub") -    async def add_role(self, ctx: commands.Context) -> None: -        """Adds the lovefest role.""" -        user = ctx.author -        role = ctx.guild.get_role(Lovefest.role_id) -        if role not in ctx.author.roles: -            await user.add_roles(role) -            await ctx.send("The Lovefest role has been added !") -        else: -            await ctx.send("You already have the role !") - -    @lovefest_role.command(name="unsub") -    async def remove_role(self, ctx: commands.Context) -> None: -        """Removes the lovefest role.""" -        user = ctx.author -        role = ctx.guild.get_role(Lovefest.role_id) -        if role not in ctx.author.roles: -            await ctx.send("You dont have the lovefest role.") -        else: -            await user.remove_roles(role) -            await ctx.send("The lovefest role has been successfully removed!") +        raise MovedCommandError(MOVED_COMMAND)      @commands.cooldown(1, 1800, commands.BucketType.user)      @commands.group(name="bemyvalentine", invoke_without_command=True) diff --git a/bot/utils/exceptions.py b/bot/utils/exceptions.py index bf0e5813..3cd96325 100644 --- a/bot/utils/exceptions.py +++ b/bot/utils/exceptions.py @@ -15,3 +15,10 @@ class APIError(Exception):          self.api = api          self.status_code = status_code          self.error_msg = error_msg + + +class MovedCommandError(Exception): +    """Raised when a command has moved locations.""" + +    def __init__(self, new_command_name: str): +        self.new_command_name = new_command_name | 
