diff --git a/jarvis/cogs/admin.py b/jarvis/cogs/admin.py index 3c18d80..6215a24 100644 --- a/jarvis/cogs/admin.py +++ b/jarvis/cogs/admin.py @@ -17,7 +17,7 @@ class AdminCog(commands.Cog): self.db = DBManager(config.mongo) @commands.command(name="ban") - @commands.has_permissions(administrator=True) + @commands.has_permissions(ban_members=True) async def _ban(self, ctx, user: User = None, reason=None): if not user or user == ctx.message.author: await ctx.send("You cannot ban yourself.") @@ -36,7 +36,7 @@ class AdminCog(commands.Cog): ) @commands.command(name="kick") - @commands.has_permissions(administrator=True) + @commands.has_permissions(kick_members=True) async def _kick(self, ctx, user: User = None, reason=None): if not user or user == ctx.message.author: await ctx.send("You cannot kick yourself.") @@ -50,15 +50,10 @@ class AdminCog(commands.Cog): ) await ctx.guild.kick(user, reason=reason) await ctx.send( - f"{user.name} has been banned from {guild_name}." + f"{user.name} has been kicked from {guild_name}." + f"Reason:\n{reason}" ) - @commands.Cog.listener() - async def on_command_error(self, ctx, error): - if isinstance(error, commands.errors.MissingPermissions): - await ctx.send("I'm afraid I can't let you do that.") - def setup(bot): bot.add_cog(AdminCog(bot)) diff --git a/jarvis/cogs/dbrand.py b/jarvis/cogs/dbrand.py index d7e6a3b..4f4d164 100644 --- a/jarvis/cogs/dbrand.py +++ b/jarvis/cogs/dbrand.py @@ -22,6 +22,7 @@ class DbrandCog(commands.Cog): self._session = aiohttp.ClientSession() self._session.headers.update({"Content-Type": "application/json"}) self.api_url = get_config().urls["dbrand_shipping"] + self.cache = {} @commands.group(name="db", aliases=["dbrand"], pass_context=True) async def _db(self, ctx): @@ -72,16 +73,16 @@ class DbrandCog(commands.Cog): if len(matches) > 0: search = matches[0] dest = search - api_link = self.api_url + dest - try: + if not self.cache.contains(dest): + api_link = self.api_url + dest data = await self._session.get(api_link) - except Exception as e: - print(e) + if 200 <= data.status < 400: + data = await data.json() + else: + data = None + self.cache.update(dest) + data = self.cache.get(dest) fields = None - if 200 <= data.status < 400: - data = await data.json() - else: - data = None if ( data is not None and data["is_valid"] diff --git a/jarvis/cogs/dev.py b/jarvis/cogs/dev.py index 8e56773..6745aaa 100644 --- a/jarvis/cogs/dev.py +++ b/jarvis/cogs/dev.py @@ -300,13 +300,6 @@ class DevCog(commands.Cog): del args, code - @commands.Cog.listener() - async def on_command_error(self, ctx, error): - if isinstance(error, commands.errors.MissingPermissions): - await ctx.send("I'm afraid I can't let you do that.") - else: - await ctx.send(f"Error processing command:\n```{error}```") - def setup(bot): bot.add_cog(DevCog(bot)) diff --git a/jarvis/cogs/error.py b/jarvis/cogs/error.py new file mode 100644 index 0000000..2a9c26c --- /dev/null +++ b/jarvis/cogs/error.py @@ -0,0 +1,22 @@ +import jarvis +from discord.ext import commands + + +class ErrorHandlerCog(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_command_error(self, ctx, error): + if isinstance(error, commands.errors.MissingPermissions): + await ctx.send("I'm afraid I can't let you do that.") + elif isinstance(error, commands.errors.CommandNotFound): + await ctx.send( + "Command does not exist. Run `>help` to get a list of commands" + ) + else: + await ctx.send(f"Error processing command:\n```{error}```") + + +def setup(bot): + bot.add_cog(ErrorHandlerCog(bot)) diff --git a/jarvis/cogs/owner.py b/jarvis/cogs/owner.py index 6eab4c5..c11da7d 100644 --- a/jarvis/cogs/owner.py +++ b/jarvis/cogs/owner.py @@ -150,11 +150,6 @@ class OwnerCog(commands.Cog): reload_config() await ctx.send("System refreshed") - @commands.Cog.listener() - async def on_command_error(self, ctx, error): - if isinstance(error, commands.errors.MissingPermissions): - await ctx.send("I'm afraid I can't let you do that.") - def setup(bot): bot.add_cog(OwnerCog(bot))