Module: ChatgptAssistant::Bots::Discord::Actions
- Included in:
- DiscordBot
- Defined in:
- lib/chatgpt_assistant/bots/discord/actions.rb
Instance Method Summary collapse
- #create_chat_action ⇒ Object
- #discord_created(chat) ⇒ Object
- #help_action ⇒ Object
- #hist_action ⇒ Object
- #list_action ⇒ Object
- #login_action ⇒ Object
- #sl_chat_action(chat_to_select) ⇒ Object
- #start_action ⇒ Object
Instance Method Details
#create_chat_action ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/chatgpt_assistant/bots/discord/actions.rb', line 76 def create_chat_action title = evnt..content.split[1..].join(" ") mode = nil if title.include? ":" mode = title.split(":").last.to_i title = title.split(":").first end actors = AwesomeChatgptActors::CastControl.actors return "invalid mode" unless (mode.to_i >= 1 && mode.to_i <= actors.size + 1) || mode.nil? return "invalid chat title" if title.nil? || title.empty? return "chat title already exists" if user.chat_by_title(title) actor_name = actors[mode.to_i - 1] if mode actor = AwesomeChatgptActors::Actor.new(role: actor_name, language: config.language) if actor_name chat = Chat.new(user_id: user.id, status: 0, title: title, actor: actor_name, prompt: actor.prompt) if actor chat = Chat.new(user_id: user.id, status: 0, title: title) unless actor return "Something went wrong", msg.chat.id unless chat chat.save ? (chat) : ([:chat_creation]) end |
#discord_created(chat) ⇒ Object
97 98 99 100 |
# File 'lib/chatgpt_assistant/bots/discord/actions.rb', line 97 def discord_created(chat) evnt.respond "Intructions sended to actor:\n#{chat.prompt}" unless chat.actor.nil? evnt.respond [:chat_created] if evnt.present? end |
#help_action ⇒ Object
46 47 48 |
# File 'lib/chatgpt_assistant/bots/discord/actions.rb', line 46 def help_action start_action end |
#hist_action ⇒ Object
63 64 65 66 67 |
# File 'lib/chatgpt_assistant/bots/discord/actions.rb', line 63 def hist_action = Message.where(chat_id: chat.id).order(:created_at) .each { |m| "#{m.role} - #{m.content}\n#{m.created_at.strftime("%d/%m/%Y %H:%M")}" } "This is the end of the chat history" end |
#list_action ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/chatgpt_assistant/bots/discord/actions.rb', line 50 def list_action chats = user.chats = Discordrb::Webhooks::Embed.new( title: "Hello, #{evnt.user.name}!", description: "Your chats:", color: "00FF00", fields: chats.map { |field| { name: field.title, value: field.actor || "No prompt" } } ) evnt.respond nil, false, end |
#login_action ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/chatgpt_assistant/bots/discord/actions.rb', line 7 def login_action user_email, user_password = .split(":") case discord_user_auth(user_email, user_password, evnt.user.id) when "user not found" [:user_not_found] when "wrong password" puts "wrong password" [:wrong_password] when find_user(email: user_email).email [:user_logged_in] end end |
#sl_chat_action(chat_to_select) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/chatgpt_assistant/bots/discord/actions.rb', line 69 def sl_chat_action(chat_to_select) @chat = user.chat_by_title(chat_to_select) [:chat_not_found] if chat.nil? user.update(current_chat_id: chat.id) if chat [:chat_selected] if chat end |
#start_action ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chatgpt_assistant/bots/discord/actions.rb', line 20 def start_action fields = %w[login start help new_chat sl_chat ask list hist connect disconnect speak] values_hash = { login: "Account login, use: #{discord_prefix}login email:password", start: "Start the bot, use: #{discord_prefix}start", help: "Show this message, use: #{discord_prefix}help", new_chat: "Create a new chat, use: #{discord_prefix}new_chat chat_name", sl_chat: "Select a chat, use: #{discord_prefix}sl_chat chat_name", ask: "Ask a question, use: #{discord_prefix}ask question", list: "List all chats, use: #{discord_prefix}list", hist: "Show chat history, use: #{discord_prefix}hist", connect: "Connect to voice channel, use: #{discord_prefix}connect", disconnect: "Disconnect from voice channel, use: #{discord_prefix}disconnect", speak: "Speak in voice channel, use: #{discord_prefix}speak question" } = Discordrb::Webhooks::Embed.new( title: "Hello, #{evnt.user.name}!", description: "I'm ChatGPT Assistant, see my commands below:", color: "00FF00", fields: fields.map { |field| { name: field, value: values_hash[field.to_sym] } } ) evnt.respond nil, false, end |