Skip to content

Commit 3354281

Browse files
Merge pull request #76 from smokeyScraper/bot_commands
[refactor]: migrate to cog-based command architecture
2 parents 8467ab4 + ecdc688 commit 3354281

File tree

4 files changed

+46
-77
lines changed

4 files changed

+46
-77
lines changed

backend/app/core/orchestration/agent_coordinator.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ async def _handle_clear_memory_request(self, message_data: Dict[str, Any]):
7272
"""Handle requests to clear thread memory"""
7373
try:
7474
memory_thread_id = message_data.get("memory_thread_id")
75-
user_id = message_data.get("user_id")
7675
cleanup_reason = message_data.get("cleanup_reason", "manual")
7776

7877
if not memory_thread_id:
@@ -81,16 +80,6 @@ async def _handle_clear_memory_request(self, message_data: Dict[str, Any]):
8180

8281
logger.info(f"Clearing memory for thread {memory_thread_id}, reason: {cleanup_reason}")
8382

84-
# Get current state before clearing
85-
current_state_data = await self.devrel_agent.get_thread_state(memory_thread_id)
86-
87-
if current_state_data:
88-
current_state = AgentState(**current_state_data)
89-
90-
# Store to database before clearing
91-
await store_summary_to_database(current_state)
92-
logger.info(f"Stored final summary to database for user {user_id}")
93-
9483
# Clear from InMemorySaver
9584
success = await self.devrel_agent.clear_thread_memory(memory_thread_id, force_clear=True)
9685

backend/bots/discord/discord_bot.py

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ async def on_message(self, message):
4343
if message.author == self.user:
4444
return
4545

46-
# Skip if message is a command (starts with !)
47-
# TODO: Add support for commands
48-
if message.content.startswith('!'):
49-
await self.process_commands(message)
46+
# if message is a command (starts with !)
47+
ctx = await self.get_context(message)
48+
if ctx.command is not None:
49+
await self.invoke(ctx)
5050
return
5151

5252
try:
@@ -184,65 +184,3 @@ async def _handle_agent_response(self, response_data: Dict[str, Any]):
184184

185185
except Exception as e:
186186
logger.error(f"Error handling agent response: {str(e)}")
187-
188-
@commands.command(name="reset")
189-
async def reset_thread(self, ctx):
190-
"""Reset user's DevRel thread and memory"""
191-
user_id = str(ctx.author.id)
192-
193-
# Send clear memory request to agent coordinator
194-
cleanup_message = {
195-
"type": "clear_thread_memory",
196-
"memory_thread_id": user_id,
197-
"user_id": user_id,
198-
"cleanup_reason": "manual_reset"
199-
}
200-
await self.queue_manager.enqueue(cleanup_message, QueuePriority.HIGH)
201-
202-
# Clean up Discord thread tracking
203-
if user_id in self.active_threads:
204-
del self.active_threads[user_id]
205-
206-
await ctx.send("Your DevRel thread and memory have been reset. Next message will create a new thread.")
207-
208-
@commands.command(name="help_devrel")
209-
async def help_devrel(self, ctx):
210-
"""Show DevRel bot help"""
211-
embed = discord.Embed(
212-
title="DevRel Assistant Help",
213-
description="I'm here to help you with Devr.AI related questions!",
214-
)
215-
216-
embed.add_field(
217-
name="What I can do:",
218-
value="""
219-
• Answer FAQs about Devr.AI
220-
• Help with getting started
221-
• Search the web for information
222-
• Provide technical support
223-
• Guide you through onboarding
224-
""",
225-
inline=False
226-
)
227-
228-
embed.add_field(
229-
name="Example questions:",
230-
value="""
231-
• "What is Devr.AI?"
232-
• "How do I contribute?"
233-
• "Search for latest AI news"
234-
• "How to get started with LangGraph?"
235-
""",
236-
inline=False
237-
)
238-
239-
embed.add_field(
240-
name="Commands:",
241-
value="""
242-
• `!reset` - Reset your chat thread and memory
243-
• `!help_devrel` - Show this help message
244-
""",
245-
inline=False
246-
)
247-
248-
await ctx.send(embed=embed)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from discord.ext import commands
2+
import discord
3+
from app.core.orchestration.queue_manager import AsyncQueueManager, QueuePriority
4+
from bots.discord.discord_bot import DiscordBot
5+
6+
class DevRelCommands(commands.Cog):
7+
def __init__(self, bot: DiscordBot, queue_manager: AsyncQueueManager):
8+
self.bot = bot
9+
self.queue = queue_manager
10+
11+
@commands.command(name="reset")
12+
async def reset_thread(self, ctx: commands.Context):
13+
"""Reset your DevRel thread and memory."""
14+
user_id = str(ctx.author.id)
15+
cleanup = {
16+
"type": "clear_thread_memory",
17+
"memory_thread_id": user_id,
18+
"user_id": user_id,
19+
"cleanup_reason": "manual_reset"
20+
}
21+
await self.queue.enqueue(cleanup, QueuePriority.HIGH)
22+
self.bot.active_threads.pop(user_id, None)
23+
await ctx.send("Your DevRel thread & memory have been reset! Send another message to start fresh.")
24+
25+
@commands.command(name="help_devrel")
26+
async def help_devrel(self, ctx: commands.Context):
27+
"""Show DevRel assistant help."""
28+
embed = discord.Embed(
29+
title="DevRel Assistant Help",
30+
description="I can help you with Devr.AI related questions!"
31+
)
32+
embed.add_field(
33+
name="Commands",
34+
value=(
35+
"• `!reset` – Reset your DevRel thread and memory\n"
36+
"• `!help_devrel` – Show this help message"
37+
),
38+
inline=False
39+
)
40+
await ctx.send(embed=embed)

backend/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from app.core.orchestration.queue_manager import AsyncQueueManager
88
from app.core.orchestration.agent_coordinator import AgentCoordinator
99
from bots.discord.discord_bot import DiscordBot
10+
from bots.discord.discord_cogs import DevRelCommands
1011
from app.db.weaviate.weaviate_client import get_client
1112

1213
# Configure logging
@@ -29,6 +30,7 @@ def __init__(self):
2930
self.queue_manager = AsyncQueueManager()
3031
self.agent_coordinator = AgentCoordinator(self.queue_manager)
3132
self.discord_bot = DiscordBot(self.queue_manager)
33+
self.discord_bot.add_cog(DevRelCommands(self.discord_bot, self.queue_manager))
3234
self.running = False
3335

3436
async def start(self):

0 commit comments

Comments
 (0)