Browse Source

Refactor: Changed name of system cog to base to better explain what it is. errors.py is now exceptions.py and blacklisting is now done via a global command check to be cleaner.

tags/v2.0.0
Roxie Gibson 5 years ago
parent
commit
eec802e206
4 changed files with 25 additions and 14 deletions
  1. +22
    -11
      main.py
  2. +1
    -1
      roxbot/__init__.py
  3. +2
    -2
      roxbot/base.py
  4. +0
    -0
      roxbot/exceptions.py

+ 22
- 11
main.py View File

import logging import logging
import os.path import os.path
import datetime import datetime
import traceback

import discord import discord
from discord.ext import commands from discord.ext import commands


from roxbot import guild_settings as gs from roxbot import guild_settings as gs




# Sets up Logging that discord.py does on its own
# Sets up Logging
logger = logging.getLogger('discord') logger = logging.getLogger('discord')
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
handler = logging.FileHandler(filename='roxbot.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler) logger.addHandler(handler)


# Load Roxbots inbuilt cogs and settings # Load Roxbots inbuilt cogs and settings
print("Loading Bot internals...") print("Loading Bot internals...")


bot.load_extension("roxbot.system")
print("system.py Loaded")
bot.load_extension("roxbot.base")
print("base.py Loaded")


bot.load_extension("roxbot.err_handle") bot.load_extension("roxbot.err_handle")
print("err_handle.py Loaded") print("err_handle.py Loaded")




@bot.event @bot.event
async def on_message(message):
"""
Checks if the user is blacklisted, if not, process the message for commands as usual.
"""
if roxbot.blacklisted(message.author):
return
return await bot.process_commands(message)
async def on_error(event, *args, **kwargs):
if roxbot.dev_mode:
traceback.print_exc()
else:
logging.exception(event)


@bot.event
async def on_command_error(self, ctx, error):
pass # This needs to overwrite the discord.py version and allow roxbot's errpr handling to kick in


@bot.check
def check_blacklist(ctx):
"""Adds global check to the bot to check for a user being blacklisted."""
return not roxbot.blacklisted(ctx.author)




@bot.command() @bot.command()

+ 1
- 1
roxbot/__init__.py View File





from roxbot import checks, http, guild_settings, converters, utils, roxbotfacts from roxbot import checks, http, guild_settings, converters, utils, roxbotfacts
from roxbot.errors import *
from roxbot.exceptions import *
from roxbot.enums import EmbedColours from roxbot.enums import EmbedColours
from roxbot.logging import log from roxbot.logging import log
from roxbot.utils import blacklisted from roxbot.utils import blacklisted

roxbot/system.py → roxbot/base.py View File

from discord.ext import commands from discord.ext import commands




class System:
class Base:
"""Cog for commands that change the bot account and bot running.""" """Cog for commands that change the bot account and bot running."""
def __init__(self, bot_client): def __init__(self, bot_client):
self.bot = bot_client self.bot = bot_client




def setup(bot_client): def setup(bot_client):
bot_client.add_cog(System(bot_client))
bot_client.add_cog(Base(bot_client))

roxbot/errors.py → roxbot/exceptions.py View File


Loading…
Cancel
Save