2023-12-13 01:46:41 +00:00

51 lines
1.3 KiB
Python

"""
Extension for the `test` cog.
Loading this file via `commands.Bot.load_extension` will add the `test` cog to the bot.
"""
import logging
from discord import app_commands, Interaction
from discord.ext import commands, tasks
from sqlalchemy import insert, select
from db import DatabaseManager, AuditModel
log = logging.getLogger(__name__)
class Test(commands.Cog):
"""
News cog.
Delivers embeds of news articles to discord channels.
"""
def __init__(self, bot):
super().__init__()
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
log.info(f"{self.__class__.__name__} cog is ready")
@app_commands.command(name="test-command")
async def test_command(self, inter: Interaction):
async with DatabaseManager() as database:
message = f"Test command has been invoked successfully!"
query = insert(AuditModel).values(discord_user_id=inter.user.id, message=message)
await database.session.execute(query)
await inter.response.send_message("the audit log test was successful")
async def setup(bot):
"""
Setup function for this extension.
Adds the `ErrorCog` cog to the bot.
"""
cog = Test(bot)
await bot.add_cog(cog)
log.info(f"Added {cog.__class__.__name__} cog")