Skip to content

Commit

Permalink
feature: add manual !trakt trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroquinc committed Dec 28, 2024
1 parent 867d345 commit 833f7d9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ async def on_ready(self):
await self.bot.load_extension('src.discord.cogs.tasks')

# Load commands here
logger.info('Loading Trakt cog')
await self.bot.load_extension('src.discord.cogs.trakt')

## Post an single embed to a channel
async def dispatch_embed(self, channel_id, embed):
Expand Down
2 changes: 1 addition & 1 deletion src/discord/cogs/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ async def before_weekly_task(self):
await asyncio.sleep(sleep_duration) # Sleep until the next run time

async def setup(bot):
logger.info('Cogs have been loaded')
logger.info('Tasks cogs have been loaded')
await bot.add_cog(TasksCog(bot))
27 changes: 27 additions & 0 deletions src/discord/cogs/trakt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import discord
from discord.ext import commands
from src.trakt.global_weekly import create_weekly_global_embed
from utils.custom_logger import logger


class TraktCog(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.command(name="trakt")
async def trakt(self, ctx):
"""Fetches and displays the weekly global Trakt stats manually."""
try:
logger.info("!trakt command invoked")
embed_data = create_weekly_global_embed()
for embed in embed_data["embeds"]:
await ctx.send(embed=discord.Embed.from_dict(embed))
except Exception as e:
logger.error(f"Error processing !trakt command: {e}")
await ctx.send("An error occurred while fetching Trakt data.")


async def setup(bot):
"""Setup function to add the cog to the bot."""
logger.info('Trakt cog have been loaded')
await bot.add_cog(TraktCog(bot))

0 comments on commit 833f7d9

Please sign in to comment.