Add stop command, fix logging

This commit is contained in:
Zeva Rose 2022-08-11 14:43:57 -06:00
parent 78a2ac014d
commit b84f5a771e
2 changed files with 14 additions and 0 deletions

View file

@ -19,6 +19,7 @@ __version__ = const.__version__
async def run() -> None:
"""Run JARVIS"""
# Configure logger
jconfig = JarvisConfig.from_yaml()
logger = get_logger("jarvis", show_locals=jconfig.log_level == "DEBUG")
logger.setLevel(jconfig.log_level)
@ -28,6 +29,7 @@ async def run() -> None:
)
logger.addHandler(file_handler)
# Configure client
intents = (
Intents.DEFAULT | Intents.MESSAGES | Intents.GUILD_MEMBERS | Intents.GUILD_MESSAGE_CONTENT
)
@ -42,18 +44,23 @@ async def run() -> None:
delete_unused_application_cmds=True,
send_command_tracebacks=False,
redis=redis,
logger=logger,
)
# External modules
if jconfig.log_level == "DEBUG":
jurigged.watch(pattern="jarvis/*.py")
if jconfig.rook_token:
rook.start(token=jconfig.rook_token, labels={"env": "dev"})
# Initialize bot
logger.info("Starting JARVIS")
logger.debug("Connecting to database")
connect(**jconfig.mongo["connect"], testing=jconfig.mongo["database"] != "jarvis")
logger.debug("Loading configuration from database")
# jconfig.get_db_config()
# Load extensions
logger.debug("Loading extensions")
for extension in get_extensions(cogs_path):
jarvis.load_extension(extension)

View file

@ -1,4 +1,5 @@
"""JARVIS bot utility commands."""
import asyncio
import logging
import platform
from io import BytesIO
@ -26,6 +27,12 @@ class BotutilCog(Extension):
"""Checks if author is bot owner."""
return ctx.author.id == self.bot.owner.id
@prefixed_command(name="stop")
async def _stop(self, ctx: PrefixedContext) -> None:
await ctx.send("Shutting down now")
loop = asyncio.get_running_loop()
loop.stop()
@prefixed_command(name="tail")
async def _tail(self, ctx: PrefixedContext, count: int = 10) -> None:
lines = []