Update run.py
This commit is contained in:
parent
557879451c
commit
f46753ed30
21
run.py
21
run.py
@ -6,12 +6,15 @@ import asyncio
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
import random
|
import random
|
||||||
|
|
||||||
# Import custom files
|
# Import custom files
|
||||||
from src.config.config import LoadConfig
|
from src.config.config import LoadConfig
|
||||||
|
|
||||||
|
logging.basicConfig(level='INFO')
|
||||||
|
|
||||||
# If uvloop is installed, change to that eventloop policy as it
|
# If uvloop is installed, change to that eventloop policy as it
|
||||||
# is more efficient
|
# is more efficient
|
||||||
try:
|
try:
|
||||||
@ -19,34 +22,36 @@ try:
|
|||||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||||
del uvloop
|
del uvloop
|
||||||
except BaseException as ex:
|
except BaseException as ex:
|
||||||
print(f'Could not load uvloop. {type(ex).__name__}: {ex};',
|
logging.warning(f'Could not load uvloop. {type(ex).__name__}: {ex};',
|
||||||
'reverting to default impl.')
|
'reverting to default impl.'))
|
||||||
else:
|
else:
|
||||||
print(f'Using uvloop for asyncio event loop policy.')
|
logging.info(print(f'Using uvloop for asyncio event loop policy.'))
|
||||||
|
|
||||||
|
|
||||||
# Bot Class
|
# Bot Class
|
||||||
class SebiMachine(commands.Bot, LoadConfig):
|
class SebiMachine(commands.Bot, LoadConfig, Loggable):
|
||||||
"""This discord is dedicated to http://www.discord.gg/GWdhBSp"""
|
"""This discord is dedicated to http://www.discord.gg/GWdhBSp"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Initialize and attach config / settings
|
# Initialize and attach config / settings
|
||||||
LoadConfig.__init__(self)
|
LoadConfig.__init__(self)
|
||||||
commands.Bot.__init__(self, command_prefix=self.defaultprefix)
|
commands.Bot.__init__(self, command_prefix=self.defaultprefix)
|
||||||
|
|
||||||
|
|
||||||
# Load plugins
|
# Load plugins
|
||||||
# Add your cog file name in this list
|
# Add your cog file name in this list
|
||||||
with open('cogs.txt', 'r') as cog_file:
|
with open('cogs.txt', 'r') as cog_file:
|
||||||
cogs = cog_file.readlines()
|
cogs = cog_file.readlines()
|
||||||
|
|
||||||
for cog in cogs:
|
for cog in cogs:
|
||||||
print(f'Loaded:{cog}')
|
# Could this just be replaced with `strip()`?
|
||||||
cog = cog.replace('\n', '')
|
cog = cog.replace('\n', '')
|
||||||
self.load_extension(f'src.cogs.{cog}')
|
self.load_extension(f'src.cogs.{cog}')
|
||||||
|
self.logger.info(f'Loaded: {cog}')
|
||||||
|
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
"""On ready function"""
|
"""On ready function"""
|
||||||
if self.maintenance:
|
if self.maintenance:
|
||||||
print('MAINTENANCE ACTIVE')
|
self.logger.warning('MAINTENANCE ACTIVE')
|
||||||
|
|
||||||
async def on_command_error(self, ctx, error):
|
async def on_command_error(self, ctx, error):
|
||||||
"""
|
"""
|
||||||
@ -79,5 +84,5 @@ if __name__ == '__main__':
|
|||||||
# Make sure the key stays private.
|
# Make sure the key stays private.
|
||||||
with open('src/config/PrivateConfig.json') as fp:
|
with open('src/config/PrivateConfig.json') as fp:
|
||||||
PrivateConfig = json.load(fp)
|
PrivateConfig = json.load(fp)
|
||||||
fp.close()
|
|
||||||
client.run(PrivateConfig["bot-key"])
|
client.run(PrivateConfig["bot-key"])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user