-
Notifications
You must be signed in to change notification settings - Fork 9
/
phoenix.rb
30 lines (26 loc) · 874 Bytes
/
phoenix.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'api-ai-ruby'
require 'discordrb'
bot = Discordrb::Bot.new token: ENV['BOT_TOKEN'], ignore_bots: true
sessions = {}
bot.ready do |event|
puts "Logged in as #{bot.profile.username} (ID:#{bot.profile.id}) | #{bot.servers.size} servers"
bot.game = ENV['BOT_GAME']
end
bot.message do |event|
if event.server && !event.author.roles.any?
str = "#{event.channel.id}_CLIENT_TOKEN"
if ENV[str]
if !sessions[event.channel.id]
sessions[event.channel.id] = ApiAiRuby::Client.new( :client_access_token => ENV[str] )
end
response = sessions[event.channel.id].text_request event.message.content[0,255]
speech = response[:result][:fulfillment][:speech]
if speech && !speech.empty?
event.channel.start_typing
sleep 1
event.respond "#{event.author.mention}, #{speech}"
end
end
end
end
bot.run