From a4abf84de2bb1dd110bfcd751cc19523ccc0a3b7 Mon Sep 17 00:00:00 2001 From: Ava Date: Fri, 15 Feb 2019 21:31:46 +0200 Subject: Refine love calculator command --- bot/bot.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index 2df550dc..12291a5f 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -5,6 +5,7 @@ from typing import List from aiohttp import AsyncResolver, ClientSession, TCPConnector from discord import Embed +from discord.ext import commands from discord.ext.commands import Bot from bot import constants @@ -61,3 +62,10 @@ class SeasonalBot(Bot): embed.set_author(name=title, icon_url=icon) await devlog.send(embed=embed) + + async def on_command_error(self, context, exception): + # Don't punish the user for getting the arguments wrong + if isinstance(exception, commands.UserInputError): + context.command.reset_cooldown(context) + else: + super().on_command_error(context, exception) -- cgit v1.2.3 From b53d8d8b7fe7c33c6931fa9075c30c27ea9c02da Mon Sep 17 00:00:00 2001 From: sco1 Date: Sun, 3 Mar 2019 21:50:01 -0500 Subject: Add new Cog class inheritance & event listener decoration Mitigates recent breaking d.py changes --- bot/bot.py | 3 ++- bot/seasons/christmas/adventofcode.py | 2 +- bot/seasons/evergreen/error_handler.py | 3 ++- bot/seasons/evergreen/fun.py | 2 +- bot/seasons/evergreen/uptime.py | 2 +- bot/seasons/halloween/candy_collection.py | 4 +++- bot/seasons/halloween/hacktoberstats.py | 2 +- bot/seasons/halloween/halloween_facts.py | 3 ++- bot/seasons/halloween/halloweenify.py | 2 +- bot/seasons/halloween/monstersurvey.py | 4 ++-- bot/seasons/halloween/scarymovie.py | 2 +- bot/seasons/halloween/spookyavatar.py | 2 +- bot/seasons/halloween/spookygif.py | 2 +- bot/seasons/halloween/spookyreact.py | 4 +++- bot/seasons/halloween/spookysound.py | 2 +- bot/seasons/valentines/be_my_valentine.py | 2 +- bot/seasons/valentines/lovecalculator.py | 4 ++-- bot/seasons/valentines/movie_generator.py | 2 +- bot/seasons/valentines/savethedate.py | 2 +- bot/seasons/valentines/valentine_zodiac.py | 2 +- bot/seasons/valentines/whoisvalentine.py | 2 +- 21 files changed, 30 insertions(+), 23 deletions(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index 12291a5f..84bac598 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -6,7 +6,7 @@ from typing import List from aiohttp import AsyncResolver, ClientSession, TCPConnector from discord import Embed from discord.ext import commands -from discord.ext.commands import Bot +from discord.ext.commands import Bot, Cog from bot import constants @@ -63,6 +63,7 @@ class SeasonalBot(Bot): await devlog.send(embed=embed) + @Cog.listener() async def on_command_error(self, context, exception): # Don't punish the user for getting the arguments wrong if isinstance(exception, commands.UserInputError): diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 3b199a4a..d360ae5e 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -108,7 +108,7 @@ async def day_countdown(bot: commands.Bot): await asyncio.sleep(120) -class AdventOfCode: +class AdventOfCode(commands.Cog): """ Advent of Code festivities! Ho Ho Ho! """ diff --git a/bot/seasons/evergreen/error_handler.py b/bot/seasons/evergreen/error_handler.py index 47e18a31..d764fe86 100644 --- a/bot/seasons/evergreen/error_handler.py +++ b/bot/seasons/evergreen/error_handler.py @@ -8,12 +8,13 @@ from discord.ext import commands log = logging.getLogger(__name__) -class CommandErrorHandler: +class CommandErrorHandler(commands.Cog): """A error handler for the PythonDiscord server!""" def __init__(self, bot): self.bot = bot + @commands.Cog.listener() async def on_command_error(self, ctx, error): """Activates when a command opens an error""" diff --git a/bot/seasons/evergreen/fun.py b/bot/seasons/evergreen/fun.py index 4da01dd1..0003714d 100644 --- a/bot/seasons/evergreen/fun.py +++ b/bot/seasons/evergreen/fun.py @@ -8,7 +8,7 @@ from bot.constants import Emojis log = logging.getLogger(__name__) -class Fun: +class Fun(commands.Cog): """ A collection of general commands for fun. """ diff --git a/bot/seasons/evergreen/uptime.py b/bot/seasons/evergreen/uptime.py index 1321da19..cce5ae76 100644 --- a/bot/seasons/evergreen/uptime.py +++ b/bot/seasons/evergreen/uptime.py @@ -9,7 +9,7 @@ from bot import start_time log = logging.getLogger(__name__) -class Uptime: +class Uptime(commands.Cog): """ A cog for posting the bots uptime. """ diff --git a/bot/seasons/halloween/candy_collection.py b/bot/seasons/halloween/candy_collection.py index 80f30a1b..d75e0d94 100644 --- a/bot/seasons/halloween/candy_collection.py +++ b/bot/seasons/halloween/candy_collection.py @@ -20,7 +20,7 @@ ADD_SKULL_REACTION_CHANCE = 50 # 2% ADD_SKULL_EXISTING_REACTION_CHANCE = 20 # 5% -class CandyCollection: +class CandyCollection(commands.Cog): def __init__(self, bot): self.bot = bot with open(json_location) as candy: @@ -31,6 +31,7 @@ class CandyCollection: userid = userinfo['userid'] self.get_candyinfo[userid] = userinfo + @commands.Cog.listener() async def on_message(self, message): """ Randomly adds candy or skull to certain messages @@ -54,6 +55,7 @@ class CandyCollection: self.msg_reacted.append(d) return await message.add_reaction('\N{CANDY}') + @commands.Cog.listener() async def on_reaction_add(self, reaction, user): """ Add/remove candies from a person if the reaction satisfies criteria diff --git a/bot/seasons/halloween/hacktoberstats.py b/bot/seasons/halloween/hacktoberstats.py index 41cf10ee..8ac448b8 100644 --- a/bot/seasons/halloween/hacktoberstats.py +++ b/bot/seasons/halloween/hacktoberstats.py @@ -13,7 +13,7 @@ from discord.ext import commands log = logging.getLogger(__name__) -class HacktoberStats: +class HacktoberStats(commands.Cog): def __init__(self, bot): self.bot = bot self.link_json = Path("bot", "resources", "github_links.json") diff --git a/bot/seasons/halloween/halloween_facts.py b/bot/seasons/halloween/halloween_facts.py index 098ee432..64f00ab3 100644 --- a/bot/seasons/halloween/halloween_facts.py +++ b/bot/seasons/halloween/halloween_facts.py @@ -25,7 +25,7 @@ PUMPKIN_ORANGE = discord.Color(0xFF7518) INTERVAL = timedelta(hours=6).total_seconds() -class HalloweenFacts: +class HalloweenFacts(commands.Cog): def __init__(self, bot): self.bot = bot @@ -35,6 +35,7 @@ class HalloweenFacts: self.facts = list(enumerate(self.halloween_facts)) random.shuffle(self.facts) + @commands.Cog.listener() async def on_ready(self): self.channel = self.bot.get_channel(Hacktoberfest.channel_id) self.bot.loop.create_task(self._fact_publisher_task()) diff --git a/bot/seasons/halloween/halloweenify.py b/bot/seasons/halloween/halloweenify.py index cda07472..9e1bae59 100644 --- a/bot/seasons/halloween/halloweenify.py +++ b/bot/seasons/halloween/halloweenify.py @@ -10,7 +10,7 @@ from discord.ext.commands.cooldowns import BucketType log = logging.getLogger(__name__) -class Halloweenify: +class Halloweenify(commands.Cog): """ A cog to change a invokers nickname to a spooky one! """ diff --git a/bot/seasons/halloween/monstersurvey.py b/bot/seasons/halloween/monstersurvey.py index 08873f24..aa5d97d2 100644 --- a/bot/seasons/halloween/monstersurvey.py +++ b/bot/seasons/halloween/monstersurvey.py @@ -4,7 +4,7 @@ import os from discord import Embed from discord.ext import commands -from discord.ext.commands import Bot, Context +from discord.ext.commands import Bot, Cog, Context log = logging.getLogger(__name__) @@ -14,7 +14,7 @@ EMOJIS = { } -class MonsterSurvey: +class MonsterSurvey(Cog): """ Vote for your favorite monster! This command allows users to vote for their favorite listed monster. diff --git a/bot/seasons/halloween/scarymovie.py b/bot/seasons/halloween/scarymovie.py index b280781e..c9a62edf 100644 --- a/bot/seasons/halloween/scarymovie.py +++ b/bot/seasons/halloween/scarymovie.py @@ -13,7 +13,7 @@ TMDB_API_KEY = environ.get('TMDB_API_KEY') TMDB_TOKEN = environ.get('TMDB_TOKEN') -class ScaryMovie: +class ScaryMovie(commands.Cog): """ Selects a random scary movie and embeds info into discord chat """ diff --git a/bot/seasons/halloween/spookyavatar.py b/bot/seasons/halloween/spookyavatar.py index b37a03f9..a2ed3b85 100644 --- a/bot/seasons/halloween/spookyavatar.py +++ b/bot/seasons/halloween/spookyavatar.py @@ -12,7 +12,7 @@ from bot.utils.halloween import spookifications log = logging.getLogger(__name__) -class SpookyAvatar: +class SpookyAvatar(commands.Cog): """ A cog that spookifies an avatar. diff --git a/bot/seasons/halloween/spookygif.py b/bot/seasons/halloween/spookygif.py index 1233773b..f013f415 100644 --- a/bot/seasons/halloween/spookygif.py +++ b/bot/seasons/halloween/spookygif.py @@ -9,7 +9,7 @@ from bot.constants import Tokens log = logging.getLogger(__name__) -class SpookyGif: +class SpookyGif(commands.Cog): """ A cog to fetch a random spooky gif from the web! """ diff --git a/bot/seasons/halloween/spookyreact.py b/bot/seasons/halloween/spookyreact.py index f63cd7e5..92afe798 100644 --- a/bot/seasons/halloween/spookyreact.py +++ b/bot/seasons/halloween/spookyreact.py @@ -2,6 +2,7 @@ import logging import re import discord +from discord.ext.commands import Cog log = logging.getLogger(__name__) @@ -16,7 +17,7 @@ SPOOKY_TRIGGERS = { } -class SpookyReact: +class SpookyReact(Cog): """ A cog that makes the bot react to message triggers. @@ -25,6 +26,7 @@ class SpookyReact: def __init__(self, bot): self.bot = bot + @Cog.listener() async def on_message(self, ctx: discord.Message): """ A command to send the seasonalbot github project diff --git a/bot/seasons/halloween/spookysound.py b/bot/seasons/halloween/spookysound.py index 4cab1239..1fbbfea6 100644 --- a/bot/seasons/halloween/spookysound.py +++ b/bot/seasons/halloween/spookysound.py @@ -10,7 +10,7 @@ from bot.constants import Hacktoberfest log = logging.getLogger(__name__) -class SpookySound: +class SpookySound(commands.Cog): """ A cog that plays a spooky sound in a voice channel on command. """ diff --git a/bot/seasons/valentines/be_my_valentine.py b/bot/seasons/valentines/be_my_valentine.py index 0046ceb4..f589dbeb 100644 --- a/bot/seasons/valentines/be_my_valentine.py +++ b/bot/seasons/valentines/be_my_valentine.py @@ -15,7 +15,7 @@ log = logging.getLogger(__name__) HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] -class BeMyValentine: +class BeMyValentine(commands.Cog): """ A cog that sends valentines to other users ! """ diff --git a/bot/seasons/valentines/lovecalculator.py b/bot/seasons/valentines/lovecalculator.py index 4df33b93..655430f5 100644 --- a/bot/seasons/valentines/lovecalculator.py +++ b/bot/seasons/valentines/lovecalculator.py @@ -9,7 +9,7 @@ from typing import Union import discord from discord import Member from discord.ext import commands -from discord.ext.commands import BadArgument, clean_content +from discord.ext.commands import BadArgument, Cog, clean_content from bot.constants import Roles @@ -20,7 +20,7 @@ with Path('bot', 'resources', 'valentines', 'love_matches.json').open() as file: LOVE_DATA = sorted((int(key), value) for key, value in LOVE_DATA.items()) -class LoveCalculator: +class LoveCalculator(Cog): """ A cog for calculating the love between two people """ diff --git a/bot/seasons/valentines/movie_generator.py b/bot/seasons/valentines/movie_generator.py index b52eba7f..ff0bb86b 100644 --- a/bot/seasons/valentines/movie_generator.py +++ b/bot/seasons/valentines/movie_generator.py @@ -11,7 +11,7 @@ TMDB_API_KEY = environ.get("TMDB_API_KEY") log = logging.getLogger(__name__) -class RomanceMovieFinder: +class RomanceMovieFinder(commands.Cog): """ A cog that returns a random romance movie suggestion to a user """ diff --git a/bot/seasons/valentines/savethedate.py b/bot/seasons/valentines/savethedate.py index b9484be9..f49d9ff4 100644 --- a/bot/seasons/valentines/savethedate.py +++ b/bot/seasons/valentines/savethedate.py @@ -13,7 +13,7 @@ log = logging.getLogger(__name__) HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] -class SaveTheDate: +class SaveTheDate(commands.Cog): """ A cog that gives random suggestion, for a valentines date ! """ diff --git a/bot/seasons/valentines/valentine_zodiac.py b/bot/seasons/valentines/valentine_zodiac.py index 06c0237d..aa80a7e9 100644 --- a/bot/seasons/valentines/valentine_zodiac.py +++ b/bot/seasons/valentines/valentine_zodiac.py @@ -14,7 +14,7 @@ LETTER_EMOJI = ':love_letter:' HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] -class ValentineZodiac: +class ValentineZodiac(commands.Cog): """ A cog that returns a counter compatible zodiac sign to the given user's zodiac sign. """ diff --git a/bot/seasons/valentines/whoisvalentine.py b/bot/seasons/valentines/whoisvalentine.py index 2fe07aba..ade4f131 100644 --- a/bot/seasons/valentines/whoisvalentine.py +++ b/bot/seasons/valentines/whoisvalentine.py @@ -14,7 +14,7 @@ with open(Path("bot", "resources", "valentines", "valentine_facts.json"), "r") a FACTS = json.load(file) -class ValentineFacts: +class ValentineFacts(commands.Cog): def __init__(self, bot): self.bot = bot -- cgit v1.2.3 From 3bbc4cc2132b7dffb98702304014561f69d230dd Mon Sep 17 00:00:00 2001 From: Chris Goes Date: Mon, 4 Mar 2019 23:56:02 -0700 Subject: Make this pig fly --- Pipfile | 2 +- Pipfile.lock | 5 ++--- bot/bot.py | 2 +- bot/seasons/evergreen/snakes/snakes_cog.py | 29 +++++++++-------------------- bot/seasons/evergreen/snakes/utils.py | 4 ++-- 5 files changed, 15 insertions(+), 27 deletions(-) (limited to 'bot/bot.py') diff --git a/Pipfile b/Pipfile index 8bc3eadf..277106c5 100644 --- a/Pipfile +++ b/Pipfile @@ -4,7 +4,7 @@ verify_ssl = true name = "pypi" [packages] -discord-py = {ref = "rewrite",git = "https://github.com/Rapptz/discord.py"} +discord-py = {ref = "3f06f24",git = "https://github.com/Rapptz/discord.py"} arrow = "*" beautifulsoup4 = "*" aiodns = "*" diff --git a/Pipfile.lock b/Pipfile.lock index e67f3d5b..1d078621 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "27243f1b58b38c7b873bcac661af6454eed41c7a7da9c812546fe3a98ed29949" + "sha256": "1b41990a905b26b2dfc8d59f3de837b4dffc0485d83e865bd9d9792276bb9b9c" }, "pipfile-spec": 6, "requires": { @@ -76,7 +76,7 @@ }, "discord-py": { "git": "https://github.com/Rapptz/discord.py", - "ref": "45af9fa40bc0083de3a695795029d6f6a85ce0d8" + "ref": "3f06f247c039a23948e7bb0014ea31db533b4ba2" }, "fuzzywuzzy": { "hashes": [ @@ -142,7 +142,6 @@ }, "pycparser": { "hashes": [ - "sha256:25043a2570be3ee8741c8f63eaad1602b7eced44a2586650756d765680a47898", "sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3" ], "version": "==2.19" diff --git a/bot/bot.py b/bot/bot.py index 12291a5f..3cc57c3f 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -68,4 +68,4 @@ class SeasonalBot(Bot): if isinstance(exception, commands.UserInputError): context.command.reset_cooldown(context) else: - super().on_command_error(context, exception) + await super().on_command_error(context, exception) diff --git a/bot/seasons/evergreen/snakes/snakes_cog.py b/bot/seasons/evergreen/snakes/snakes_cog.py index f2f63141..4ed277bd 100644 --- a/bot/seasons/evergreen/snakes/snakes_cog.py +++ b/bot/seasons/evergreen/snakes/snakes_cog.py @@ -148,7 +148,10 @@ class Snakes: def __init__(self, bot: Bot): self.active_sal = {} self.bot = bot - # self.headers = {"X-API-KEY": Keys.site_api} + self.snake_names = utils.get_resource("snake_names") + self.snake_idioms = utils.get_resource("snake_idioms") + self.snake_quizzes = utils.get_resource("snake_quiz") + self.snake_facts = utils.get_resource("snake_facts") # region: Helper methods @staticmethod @@ -417,7 +420,7 @@ class Snakes: Gets a random snake name. :return: A random snake name, as a string. """ - return await utils.get_resource("snake_names") + return random.choice(self.snake_names) async def _validate_answer(self, ctx: Context, message: Message, answer: str, options: list): """ @@ -628,21 +631,15 @@ class Snakes: random.randint(50, 70), ) - # Get a snake idiom from the API - # response = await self.bot.http_session.get(URLs.site_idioms_api, headers=self.headers) - # text = await response.json() - # TODO: did the API return a random name or something?? - # why was text being passed as-is without str conversion? - text = await utils.get_resource("snake_idioms") - # Build and send the snek + text = random.choice(self.snake_idioms)["idiom"] factory = utils.PerlinNoiseFactory(dimension=1, octaves=2) image_frame = utils.create_snek_frame( factory, snake_width=width, snake_length=length, snake_color=snek_color, - text=str(text), + text=text, text_color=text_color, bg_color=bg_color ) @@ -848,10 +845,7 @@ class Snakes: """ # Prepare a question. - # response = await self.bot.http_session.get(URLs.site_quiz_api, headers=self.headers) - # question = await response.json() - question = await utils.get_resource("snake_quiz") - + question = random.choice(self.snake_quizzes) answer = question["answerkey"] options = {key: question["options"][key] for key in ANSWERS_EMOJI.keys()} @@ -1052,12 +1046,7 @@ class Snakes: Modified by lemon. """ - # Get a fact from the API. - # response = await self.bot.http_session.get(URLs.site_facts_api, headers=self.headers) - # question = await response.json() - question = await utils.get_resource("snake_facts") - - # Build and send the embed. + question = random.choice(self.snake_facts)["fact"] embed = Embed( title="Snake fact", color=SNAKE_COLOR, diff --git a/bot/seasons/evergreen/snakes/utils.py b/bot/seasons/evergreen/snakes/utils.py index 1e2ccacd..9823d701 100644 --- a/bot/seasons/evergreen/snakes/utils.py +++ b/bot/seasons/evergreen/snakes/utils.py @@ -11,7 +11,7 @@ import math import random from itertools import product from pathlib import Path -from typing import Dict, Tuple +from typing import List, Tuple import aiohttp from PIL import Image @@ -114,7 +114,7 @@ Y = 1 ANGLE_RANGE = math.pi * 2 -async def get_resource(file: str) -> Dict[str, str]: +def get_resource(file: str) -> List[dict]: with (SNAKE_RESOURCES / f"{file}.json").open() as snakefile: return json.load(snakefile) -- cgit v1.2.3 From 79b16232c62c6381c1669718a718bba6acddc958 Mon Sep 17 00:00:00 2001 From: Scragly <29337040+scragly@users.noreply.github.com> Date: Tue, 26 Mar 2019 13:53:54 +1000 Subject: Recombine error handlers into the main listener. Fix cooldown revert. --- bot/bot.py | 17 ++---- bot/seasons/evergreen/error_handler.py | 99 ++++++++++++++++------------------ 2 files changed, 48 insertions(+), 68 deletions(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index c1198957..d60390c3 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -5,8 +5,7 @@ from typing import List from aiohttp import AsyncResolver, ClientSession, TCPConnector from discord import Embed -from discord.ext import commands -from discord.ext.commands import Bot, Cog +from discord.ext.commands import Bot from bot import constants @@ -19,10 +18,7 @@ class SeasonalBot(Bot): def __init__(self, **kwargs): super().__init__(**kwargs) self.http_session = ClientSession( - connector=TCPConnector( - resolver=AsyncResolver(), - family=socket.AF_INET, - ) + connector=TCPConnector(resolver=AsyncResolver(), family=socket.AF_INET) ) def load_extensions(self, exts: List[str]): @@ -49,6 +45,7 @@ class SeasonalBot(Bot): """ Send an embed message to the devlog channel """ + devlog = self.get_channel(constants.Channels.devlog) if not devlog: @@ -62,11 +59,3 @@ class SeasonalBot(Bot): embed.set_author(name=title, icon_url=icon) await devlog.send(embed=embed) - - @Cog.listener() - async def on_command_error(self, context, exception): - # Don't punish the user for getting the arguments wrong - if isinstance(exception, commands.UserInputError): - context.command.reset_cooldown(context) - else: - await super().on_command_error(context, exception) diff --git a/bot/seasons/evergreen/error_handler.py b/bot/seasons/evergreen/error_handler.py index 19c22ed8..c60e33ee 100644 --- a/bot/seasons/evergreen/error_handler.py +++ b/bot/seasons/evergreen/error_handler.py @@ -14,98 +14,89 @@ class CommandErrorHandler(commands.Cog): def __init__(self, bot): self.bot = bot + @staticmethod + def revert_cooldown_counter(command, message): + """Undoes the last cooldown counter for user-error cases.""" + if command._buckets.valid: + bucket = command._buckets.get_bucket(message) + bucket._tokens = min(bucket.rate, bucket._tokens + 1) + logging.debug( + "Cooldown counter reverted as the command was not used correctly." + ) + @commands.Cog.listener() async def on_command_error(self, ctx, error): """Activates when a command opens an error""" if hasattr(ctx.command, 'on_error'): return logging.debug( - "A command error occured but " - "the command had it's own error handler" + "A command error occured but the command had it's own error handler." ) + error = getattr(error, 'original', error) + if isinstance(error, commands.CommandNotFound): return logging.debug( - f"{ctx.author} called '{ctx.message.content}' " - "but no command was found" + f"{ctx.author} called '{ctx.message.content}' but no command was found." ) + if isinstance(error, commands.UserInputError): logging.debug( - f"{ctx.author} called the command '{ctx.command}' " - "but entered invalid input!" + f"{ctx.author} called the command '{ctx.command}' but entered invalid input!" ) + + self.revert_cooldown_counter(ctx.command, ctx.message) + return await ctx.send( - ":no_entry: The command you specified failed to run." + ":no_entry: The command you specified failed to run. " "This is because the arguments you provided were invalid." ) + if isinstance(error, commands.CommandOnCooldown): logging.debug( - f"{ctx.author} called the command '{ctx.command}' " - "but they were on cooldown!" + f"{ctx.author} called the command '{ctx.command}' but they were on cooldown!" ) - seconds = error.retry_after - remaining_minutes, remaining_seconds = divmod(seconds, 60) - time_remaining = f'{int(remaining_minutes)} minutes {math.ceil(remaining_seconds)} seconds' + remaining_minutes, remaining_seconds = divmod(error.retry_after, 60) + return await ctx.send( - "This command is on cooldown," - f" please retry in {time_remaining}." + f"This command is on cooldown, please retry in " + f"{int(remaining_minutes)} minutes {math.ceil(remaining_seconds)} seconds." ) + if isinstance(error, commands.DisabledCommand): logging.debug( - f"{ctx.author} called the command '{ctx.command}' " - "but the command was disabled!" - ) - return await ctx.send( - ":no_entry: This command has been disabled." + f"{ctx.author} called the command '{ctx.command}' but the command was disabled!" ) + return await ctx.send(":no_entry: This command has been disabled.") + if isinstance(error, commands.NoPrivateMessage): logging.debug( f"{ctx.author} called the command '{ctx.command}' " "in a private message however the command was guild only!" ) - return await ctx.author.send( - ":no_entry: This command can only be used inside a server." - ) + return await ctx.author.send(":no_entry: This command can only be used in the server.") + if isinstance(error, commands.BadArgument): - if ctx.command.qualified_name == 'tag list': - logging.debug( - f"{ctx.author} called the command '{ctx.command}' " - "but entered an invalid user!" - ) - return await ctx.send( - "I could not find that member. Please try again." - ) - else: - logging.debug( - f"{ctx.author} called the command '{ctx.command}' " - "but entered a bad argument!" - ) - return await ctx.send( - "The argument you provided was invalid." - ) - if isinstance(error, commands.CheckFailure): + self.revert_cooldown_counter(ctx.command, ctx.message) + logging.debug( - f"{ctx.author} called the command '{ctx.command}' " - "but the checks failed!" - ) - return await ctx.send( - ":no_entry: You are not authorized to use this command." + f"{ctx.author} called the command '{ctx.command}' but entered a bad argument!" ) - print( - f"Ignoring exception in command {ctx.command}:", - file=sys.stderr - ) + return await ctx.send("The argument you provided was invalid.") + + if isinstance(error, commands.CheckFailure): + logging.debug(f"{ctx.author} called the command '{ctx.command}' but the checks failed!") + return await ctx.send(":no_entry: You are not authorized to use this command.") + + print(f"Ignoring exception in command {ctx.command}:", file=sys.stderr) + logging.warning( f"{ctx.author} called the command '{ctx.command}' " "however the command failed to run with the error:" f"-------------\n{error}" ) - traceback.print_exception( - type(error), - error, - error.__traceback__, - file=sys.stderr - ) + + traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr) def setup(bot): -- cgit v1.2.3