From f46753ed306232a679a79b1987af7b063fd68d68 Mon Sep 17 00:00:00 2001 From: Espy | Neko | 404 <34942042+neko404notfound@users.noreply.github.com> Date: Tue, 22 May 2018 22:08:01 +0100 Subject: [PATCH] Update run.py --- run.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/run.py b/run.py index dffb7a8..a6723d3 100644 --- a/run.py +++ b/run.py @@ -6,12 +6,15 @@ import asyncio import discord from discord.ext import commands import json +import logging import traceback import random # Import custom files from src.config.config import LoadConfig +logging.basicConfig(level='INFO') + # If uvloop is installed, change to that eventloop policy as it # is more efficient try: @@ -19,34 +22,36 @@ try: asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) del uvloop except BaseException as ex: - print(f'Could not load uvloop. {type(ex).__name__}: {ex};', - 'reverting to default impl.') + logging.warning(f'Could not load uvloop. {type(ex).__name__}: {ex};', + 'reverting to default impl.')) else: - print(f'Using uvloop for asyncio event loop policy.') + logging.info(print(f'Using uvloop for asyncio event loop policy.')) # Bot Class -class SebiMachine(commands.Bot, LoadConfig): +class SebiMachine(commands.Bot, LoadConfig, Loggable): """This discord is dedicated to http://www.discord.gg/GWdhBSp""" def __init__(self): # Initialize and attach config / settings LoadConfig.__init__(self) commands.Bot.__init__(self, command_prefix=self.defaultprefix) - # Load plugins # Add your cog file name in this list with open('cogs.txt', 'r') as cog_file: cogs = cog_file.readlines() + for cog in cogs: - print(f'Loaded:{cog}') + # Could this just be replaced with `strip()`? cog = cog.replace('\n', '') self.load_extension(f'src.cogs.{cog}') + self.logger.info(f'Loaded: {cog}') + async def on_ready(self): """On ready function""" if self.maintenance: - print('MAINTENANCE ACTIVE') + self.logger.warning('MAINTENANCE ACTIVE') async def on_command_error(self, ctx, error): """ @@ -79,5 +84,5 @@ if __name__ == '__main__': # Make sure the key stays private. with open('src/config/PrivateConfig.json') as fp: PrivateConfig = json.load(fp) - fp.close() + client.run(PrivateConfig["bot-key"])