rewrite: Cleanup main.
Also attach a `ClientSession` to LionBot.
This commit is contained in:
60
bot/main.py
60
bot/main.py
@@ -1,10 +1,12 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from meta import LionBot, conf, sharding, appname, shard_talk
|
from meta import LionBot, conf, sharding, appname, shard_talk
|
||||||
|
from meta.app import shardname
|
||||||
from meta.logger import log_context, log_action_stack, logging_context
|
from meta.logger import log_context, log_action_stack, logging_context
|
||||||
from meta.context import ctx_bot
|
from meta.context import ctx_bot
|
||||||
|
|
||||||
@@ -12,20 +14,6 @@ from data import Database
|
|||||||
|
|
||||||
from constants import DATA_VERSION
|
from constants import DATA_VERSION
|
||||||
|
|
||||||
# from data import tables
|
|
||||||
|
|
||||||
# Note: This MUST be imported after core, due to table definition orders
|
|
||||||
# from settings import AppSettings
|
|
||||||
# log_context.set(f"APP: {appname}")
|
|
||||||
|
|
||||||
# client.appdata = core.data.meta.fetch_or_create(appname)
|
|
||||||
|
|
||||||
# client.data = tables
|
|
||||||
|
|
||||||
# client.settings = AppSettings(conf.bot['data_appid'])
|
|
||||||
|
|
||||||
# Initialise all modules
|
|
||||||
# client.initialise_modules()
|
|
||||||
|
|
||||||
for name in conf.config.options('LOGGING_LEVELS', no_defaults=True):
|
for name in conf.config.options('LOGGING_LEVELS', no_defaults=True):
|
||||||
logging.getLogger(name).setLevel(conf.logging_levels[name])
|
logging.getLogger(name).setLevel(conf.logging_levels[name])
|
||||||
@@ -50,27 +38,29 @@ async def main():
|
|||||||
logger.critical(error)
|
logger.critical(error)
|
||||||
raise RuntimeError(error)
|
raise RuntimeError(error)
|
||||||
|
|
||||||
async with LionBot(
|
async with aiohttp.ClientSession() as session:
|
||||||
command_prefix=commands.when_mentioned,
|
async with LionBot(
|
||||||
intents=intents,
|
command_prefix=commands.when_mentioned,
|
||||||
appname=appname,
|
intents=intents,
|
||||||
db=db,
|
appname=appname,
|
||||||
config=conf,
|
shardname=shardname,
|
||||||
initial_extensions=['modules'],
|
db=db,
|
||||||
web_client=None,
|
config=conf,
|
||||||
app_ipc=shard_talk,
|
initial_extensions=['core', 'modules'],
|
||||||
testing_guilds=[889875661848723456, 879411098384752672],
|
web_client=session,
|
||||||
shard_id=sharding.shard_number,
|
app_ipc=shard_talk,
|
||||||
shard_count=sharding.shard_count
|
testing_guilds=conf.bot.getintlist('admin_guilds'),
|
||||||
) as lionbot:
|
shard_id=sharding.shard_number,
|
||||||
ctx_bot.set(lionbot)
|
shard_count=sharding.shard_count
|
||||||
try:
|
) as lionbot:
|
||||||
with logging_context(context=f"APP: {appname}"):
|
ctx_bot.set(lionbot)
|
||||||
logger.info("StudyLion initialised, starting!", extra={'action': 'Starting'})
|
try:
|
||||||
await lionbot.start(conf.bot['TOKEN'])
|
with logging_context(context=f"APP: {appname}"):
|
||||||
except asyncio.CancelledError:
|
logger.info("StudyLion initialised, starting!", extra={'action': 'Starting'})
|
||||||
with logging_context(context=f"APP: {appname}", action="Shutting Down"):
|
await lionbot.start(conf.bot['TOKEN'])
|
||||||
logger.info("StudyLion closed, shutting down.", exc_info=True)
|
except asyncio.CancelledError:
|
||||||
|
with logging_context(context=f"APP: {appname}", action="Shutting Down"):
|
||||||
|
logger.info("StudyLion closed, shutting down.", exc_info=True)
|
||||||
|
|
||||||
|
|
||||||
def _main():
|
def _main():
|
||||||
|
|||||||
Reference in New Issue
Block a user