Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions src/capy_app/frontend/cogs/onboarding/brian_onboarding_cog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import discord
import logging
from discord.ext import commands
from discord import app_commands

from frontend import config_colors as colors
from config import settings


class todoCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.logger = logging.getLogger(
f"discord.cog.{self.__class__.__name__.lower()}"
)
self.todolists = {} # Dictionary to hold todo lists for each user
self.message_tracker = {} # Dictionary to track messages for each user


@app_commands.guilds(discord.Object(id=settings.DEBUG_GUILD_ID))
@app_commands.command(name="todo", description="creates todo list")
async def todo(self, interaction: discord.Interaction):
user_id = interaction.user.id
task_list = self.todolists.get(user_id, [])
description_dynamic = "\n".join(task_list) if task_list else "No tasks in your todo list."
embed = discord.Embed(
title = f"{interaction.user.name}'s Todo List",
description = description_dynamic,
color = colors.PING,
)
await interaction.response.send_message(embed=embed)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider making this response ephemeral

Pass ephemeral=True if the message is only for the user, to prevent channel clutter.

Suggested change
await interaction.response.send_message(embed=embed)
await interaction.response.send_message(embed=embed, ephemeral=True)

message = await interaction.original_response()

self.message_tracker[user_id] = message.id # Track the message ID for the user

#reaction buttons
await message.add_reaction("➕")
await message.add_reaction("❌")
await message.add_reaction("✅")
self.bot.og_user_id = user_id # Store the original user ID for later checks

@commands.Cog.listener()
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User):
# Ignore bot reactions
if user.bot:
return

# Check if the reaction is on a tracked message
message = reaction.message
message_id = message.id
if message_id not in self.message_tracker.values():
return

user_id = user.id
if user.id != self.bot.og_user_id:
await message.channel.send(f"{user.mention}, you can only manage your own todo list.", delete_after=5)
return

if reaction.emoji == "➕":
await self.add_task(reaction.message, user)
elif reaction.emoji == "❌":
await self.remove_task(reaction.message, user)
elif reaction.emoji == "✅":
await self.close_task_list(reaction.message, user)
else:
message.send(f"{user.mention}, unknown reaction.", delete_after=5)
async def add_task(self, message, user):
await message.channel.send(f"{user.mention}, what task would you like to add?", delete_after=10)

def check(m):
return m.author == user and m.channel == message.channel

try:
reply = await self.bot.wait_for("message", check=check, timeout=30.0)
task = reply.content.strip()
await reply.delete()
if task:
self.todolists.setdefault(user.id, []).append(task)
await self.update_embed(message, user.id)
except Exception:
await message.channel.send(f"{user.mention}, task add timed out or failed.", delete_after=5)

async def remove_task(self, message, user):
await message.channel.send(f"{user.mention}, this feature is not implemented yet.", delete_after=5)
async def close_task_list(self, message, user):
await message.channel.send(f"{user.mention}, this feature is not implemented yet.", delete_after=5)

async def update_embed(self, message, user_id):
task_list = self.todolists.get(user_id, [])
new_description = "\n".join(task_list) if task_list else "No tasks in your todo list."

embed = message.embeds[0]
embed.description = new_description
await message.edit(embed=embed)
async def setup(bot: commands.Bot):
await bot.add_cog(todoCog(bot))