aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons/evergreen
diff options
context:
space:
mode:
Diffstat (limited to 'bot/seasons/evergreen')
-rw-r--r--bot/seasons/evergreen/__init__.py13
-rw-r--r--bot/seasons/evergreen/error_handler.py109
-rw-r--r--bot/seasons/evergreen/uptime.py38
3 files changed, 160 insertions, 0 deletions
diff --git a/bot/seasons/evergreen/__init__.py b/bot/seasons/evergreen/__init__.py
new file mode 100644
index 00000000..e4367aaa
--- /dev/null
+++ b/bot/seasons/evergreen/__init__.py
@@ -0,0 +1,13 @@
+from bot.seasons import SeasonBase
+
+
+class Evergreen(SeasonBase):
+ bot_name = "SeasonalBot"
+
+ def __init__(self, bot):
+ self.bot = bot
+
+ @property
+ def bot_avatar(self):
+ with open(self.avatar_path("standard.png"), "rb") as avatar:
+ return bytearray(avatar.read())
diff --git a/bot/seasons/evergreen/error_handler.py b/bot/seasons/evergreen/error_handler.py
new file mode 100644
index 00000000..6de35e60
--- /dev/null
+++ b/bot/seasons/evergreen/error_handler.py
@@ -0,0 +1,109 @@
+import logging
+import math
+import sys
+import traceback
+
+from discord.ext import commands
+
+log = logging.getLogger(__name__)
+
+
+class CommandErrorHandler:
+ """A error handler for the PythonDiscord server!"""
+
+ def __init__(self, bot):
+ self.bot = bot
+
+ 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"
+ )
+ 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"
+ )
+ if isinstance(error, commands.UserInputError):
+ logging.debug(
+ f"{ctx.author} called the command '{ctx.command}' "
+ "but entered invalid input!"
+ )
+ return await ctx.send(
+ ":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!"
+ )
+ return await ctx.send(
+ "This command is on cooldown,"
+ f" please retry in {math.ceil(error.retry_after)}s."
+ )
+ 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."
+ )
+ 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."
+ )
+ 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):
+ 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
+ )
+
+
+def setup(bot):
+ bot.add_cog(CommandErrorHandler(bot))
+ log.debug("CommandErrorHandler cog loaded")
diff --git a/bot/seasons/evergreen/uptime.py b/bot/seasons/evergreen/uptime.py
new file mode 100644
index 00000000..1321da19
--- /dev/null
+++ b/bot/seasons/evergreen/uptime.py
@@ -0,0 +1,38 @@
+import logging
+
+import arrow
+from dateutil.relativedelta import relativedelta
+from discord.ext import commands
+
+from bot import start_time
+
+log = logging.getLogger(__name__)
+
+
+class Uptime:
+ """
+ A cog for posting the bots uptime.
+ """
+
+ def __init__(self, bot):
+ self.bot = bot
+
+ @commands.command(name="uptime")
+ async def uptime(self, ctx):
+ """
+ Returns the uptime of the bot.
+ """
+ difference = relativedelta(start_time - arrow.utcnow())
+ uptime_string = start_time.shift(
+ seconds=-difference.seconds,
+ minutes=-difference.minutes,
+ hours=-difference.hours,
+ days=-difference.days
+ ).humanize()
+ await ctx.send(f"I started up {uptime_string}.")
+
+
+# Required in order to load the cog, use the class name in the add_cog function.
+def setup(bot):
+ bot.add_cog(Uptime(bot))
+ log.debug("Uptime cog loaded")