-
Notifications
You must be signed in to change notification settings - Fork 0
Onboarding brian #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
woweiseng
wants to merge
4
commits into
main
Choose a base branch
from
onboarding-brian
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
src/capy_app/frontend/cogs/onboarding/brian_onboarding_cog.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| 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)) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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=Trueif the message is only for the user, to prevent channel clutter.