mirror of
https://github.com/allthingslinux/tux.git
synced 2024-10-03 00:53:12 +00:00
broke out error handling
This commit is contained in:
parent
8638fb0277
commit
5ab77eab0a
5 changed files with 34 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
# cog_loader.py
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
|
23
tux/error_handler.py
Normal file
23
tux/error_handler.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# error_handler.py
|
||||||
|
from discord.ext import commands
|
||||||
|
from utils._tux_logger import TuxLogger
|
||||||
|
|
||||||
|
logger = TuxLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ErrorHandler:
|
||||||
|
@staticmethod
|
||||||
|
async def handle_command_not_found(ctx: commands.Context, error):
|
||||||
|
await ctx.send("Invalid command used.")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def handle_missing_permissions(ctx: commands.Context, error):
|
||||||
|
await ctx.send("You do not have permission to use this command.")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def handle_bot_missing_permissions(ctx: commands.Context, error):
|
||||||
|
await ctx.send("I do not have permission to execute this command.")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def handle_other_errors(ctx: commands.Context, error):
|
||||||
|
logger.error(error)
|
14
tux/main.py
14
tux/main.py
|
@ -1,3 +1,4 @@
|
||||||
|
# main.py
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
@ -9,6 +10,9 @@ from utils._tux_logger import TuxLogger
|
||||||
logger = TuxLogger(__name__)
|
logger = TuxLogger(__name__)
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
from discord.ext import commands
|
||||||
|
from error_handler import ErrorHandler
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot: commands.Bot, debug: bool = False):
|
async def setup(bot: commands.Bot, debug: bool = False):
|
||||||
"""
|
"""
|
||||||
|
@ -66,16 +70,14 @@ async def main():
|
||||||
|
|
||||||
error (Exception): The error that occurred.
|
error (Exception): The error that occurred.
|
||||||
""" # noqa E501
|
""" # noqa E501
|
||||||
|
|
||||||
if isinstance(error, commands.CommandNotFound):
|
if isinstance(error, commands.CommandNotFound):
|
||||||
await ctx.send("Invalid command used.")
|
await ErrorHandler.handle_command_not_found(ctx, error)
|
||||||
elif isinstance(error, commands.MissingPermissions):
|
elif isinstance(error, commands.MissingPermissions):
|
||||||
await ctx.send("You do not have permission to use this command.")
|
await ErrorHandler.handle_missing_permissions(ctx, error)
|
||||||
elif isinstance(error, commands.BotMissingPermissions):
|
elif isinstance(error, commands.BotMissingPermissions):
|
||||||
await ctx.send("I do not have permission to execute this command.")
|
await ErrorHandler.handle_bot_missing_permissions(ctx, error)
|
||||||
else:
|
else:
|
||||||
# For other errors you probably want to log them somewhere for review
|
await ErrorHandler.handle_other_errors(ctx, error)
|
||||||
logger.error(error)
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_command_completion(ctx: commands.Context):
|
async def on_command_completion(ctx: commands.Context):
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# permissions.py
|
||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# utils/_tux_loader.py
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue