Didn't know a good branch name...
This commit is contained in:
parent
dd7a9c8d4b
commit
c7f77241e2
@ -1,21 +1,27 @@
|
|||||||
# !/usr/bin/python
|
# !/usr/bin/python
|
||||||
# -*- coding: utf8 -*-
|
# -*- coding: utf8 -*-
|
||||||
|
"""
|
||||||
|
App entry point.
|
||||||
|
|
||||||
# Import packages
|
Something meaningful here, eventually.
|
||||||
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import discord
|
|
||||||
from discord.ext import commands
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
|
||||||
import random
|
import random
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
# Import custom files
|
|
||||||
from src.config.config import LoadConfig
|
from src.config.config import LoadConfig
|
||||||
from src.shared_libs.loggable import Loggable
|
from src.shared_libs.loggable import Loggable
|
||||||
|
|
||||||
|
|
||||||
|
# Init logging to output on INFO level to stderr.
|
||||||
logging.basicConfig(level='INFO')
|
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:
|
||||||
@ -23,13 +29,14 @@ 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:
|
||||||
logging.warning(f'Could not load uvloop. {type(ex).__name__}: {ex};',
|
logging.warning(f'Could not load uvloop. {type(ex).__qualname__}: {ex};',
|
||||||
'reverting to default impl.')
|
'reverting to default impl.')
|
||||||
else:
|
else:
|
||||||
logging.info(f'Using uvloop for asyncio event loop policy.')
|
logging.info(f'Using uvloop for asyncio event loop policy.')
|
||||||
|
|
||||||
|
|
||||||
# Bot Class
|
# Bot Class
|
||||||
|
# Might be worth moving this to it's own file?
|
||||||
class SebiMachine(commands.Bot, LoadConfig, Loggable):
|
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):
|
||||||
@ -39,13 +46,13 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
|
|||||||
|
|
||||||
# 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') as cog_file:
|
||||||
cogs = cog_file.readlines()
|
cogs = cog_file.readlines()
|
||||||
|
|
||||||
for cog in cogs:
|
for cog in cogs:
|
||||||
# Could this just be replaced with `strip()`?
|
# 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'{__name__}.cogs.{cog}')
|
||||||
self.logger.info(f'Loaded: {cog}')
|
self.logger.info(f'Loaded: {cog}')
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
@ -68,7 +75,9 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
|
|||||||
"The bug repellent dit not work...",
|
"The bug repellent dit not work...",
|
||||||
"You found a bug in the program. Unfortunately the joke did not fit here, better luck next time..."]
|
"You found a bug in the program. Unfortunately the joke did not fit here, better luck next time..."]
|
||||||
|
|
||||||
# catch error
|
# CommandErrors triggered by other propagating errors tend to get wrapped. This means
|
||||||
|
# if we have a cause, we should probably consider unwrapping that so we get a useful
|
||||||
|
# message.
|
||||||
error = error.__cause__ or error
|
error = error.__cause__ or error
|
||||||
tb = traceback.format_exception(type(error), error, error.__traceback__, limit=2, chain=False)
|
tb = traceback.format_exception(type(error), error, error.__traceback__, limit=2, chain=False)
|
||||||
tb = ''.join(tb)
|
tb = ''.join(tb)
|
||||||
@ -86,7 +95,8 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
client = SebiMachine()
|
client = SebiMachine()
|
||||||
# Make sure the key stays private.
|
# Make sure the key stays private.
|
||||||
with open('src/config/PrivateConfig.json') as fp:
|
# I am 99% certain this is valid!
|
||||||
|
with open(f'{__name__}/config/PrivateConfig.json') as fp:
|
||||||
PrivateConfig = json.load(fp)
|
PrivateConfig = json.load(fp)
|
||||||
|
|
||||||
client.run(PrivateConfig["bot-key"])
|
client.run(PrivateConfig["bot-key"])
|
||||||
Loading…
x
Reference in New Issue
Block a user