Module: Brainiac::Plugins::Discord::Reactions

Defined in:
lib/brainiac/plugins/discord/reactions.rb

Overview

Discord reaction handler.

Handles MESSAGE_REACTION_ADD events:

  • ❌ to cancel an active agent session
  • ❔/❓ to peek at the agent's thinking (last 10/20 lines)
  • 🧠 to stream the full thinking log to a thread
  • Non-reserved emojis logged as feedback to the agent's persona

Class Method Summary collapse

Class Method Details

.handle(reaction_data, agent_key, bot_token, bot_user_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/brainiac/plugins/discord/reactions.rb', line 15

def handle(reaction_data, agent_key, bot_token, bot_user_id)
  channel_id = reaction_data["channel_id"]
  message_id = reaction_data["message_id"]
  user_id = reaction_data["user_id"]
  emoji = reaction_data["emoji"]
  emoji_name = emoji["name"]

  agent_name = agent_display_name(agent_key) || agent_key.capitalize

  # Ignore reactions from bots (including self)
  return if user_id == bot_user_id

  case emoji_name
  when "", ""
    handle_thinking_peek(agent_key, agent_name, channel_id, message_id, bot_token, line_count: emoji_name == "" ? 10 : 20)
  when "🧠"
    handle_thinking_stream(agent_key, agent_name, channel_id, message_id, bot_token)
  when ""
    handle_cancel(agent_key, agent_name, channel_id, message_id, bot_token)
  else
    unless Api::RESERVED_EMOJIS.include?(emoji_name)
      Thread.new do
        log_emoji_feedback(channel_id, message_id, user_id, emoji_name, agent_key, agent_name, bot_token)
      rescue StandardError => e
        LOG.warn "[Discord:#{agent_name}] Feedback logging failed: #{e.message}" if defined?(LOG)
      end
    end
  end
end