Module: ChatgptAssistant::Bots::Discord::ChatActions

Included in:
DiscordBot
Defined in:
lib/chatgpt_assistant/bots/discord/chat_actions.rb

Instance Method Summary collapse

Instance Method Details

#answer_actionObject



21
22
23
24
# File 'lib/chatgpt_assistant/bots/discord/chat_actions.rb', line 21

def answer_action
  response = chatter.chat(message.content, chat.id, error_messages[:something_went_wrong])
  send_message response
end

#ask_actionObject



7
8
9
10
11
12
# File 'lib/chatgpt_assistant/bots/discord/chat_actions.rb', line 7

def ask_action
  @chat = Chat.where(id: user.current_chat_id).last
  send_message error_messages[:chat_not_found] if chat.nil?
  @message = Message.new(chat_id: chat.id, content: message, role: "user") if chat
  (message.save ? answer_action : send_message(error_messages[:message_not_saved])) if chat
end

#private_message_actionObject



14
15
16
17
18
19
# File 'lib/chatgpt_assistant/bots/discord/chat_actions.rb', line 14

def private_message_action
  @chat = Chat.where(id: user.current_chat_id).last
  send_message error_messages[:chat_not_found] if chat.nil?
  @message = Message.new(chat_id: chat.id, content: message, role: "user") if chat
  (message.save ? answer_action : send_message(error_messages[:message_not_saved])) if chat
end

#send_message(text) ⇒ Object



26
27
28
29
# File 'lib/chatgpt_assistant/bots/discord/chat_actions.rb', line 26

def send_message(text)
  messages = parse_message(text, 2000)
  messages.each { |m| evnt.respond m }
end