-
Notifications
You must be signed in to change notification settings - Fork 1
/
say.rb
28 lines (21 loc) · 972 Bytes
/
say.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
class Say < AbsPlugin
def command
/^\/say ([a-zA-Z0-9\s|éèùòàì|\?\!|\'|\,|\:|\.|\"|\;]*?)$/
end
def show_usage
bot.api.send_message(chat_id: message.chat.id, text: "you can let me talk by typing:\n/say [sentence you'd like me to read]")
end
def do_stuff(match_results)
sentence = match_results[1]
sentence.gsub!('"', %q{\\\"})
if sentence.size < 140
temp_name = "#{BotConfig.config['temp_directory']}/#{Time.now.to_i}"
system("espeak -s 120 \"#{sentence}\" --stdout > #{temp_name}first_audio.wav")
system("opusenc #{temp_name}first_audio.wav #{temp_name}_audio.ogg")
bot.api.sendAudio(chat_id: message.chat.id, audio: Faraday::UploadIO.new("#{temp_name}_audio.ogg", 'ogg/vorbis'))
File.delete("#{temp_name}first_audio.wav", "#{temp_name}_audio.ogg")
else
bot.api.send_message(chat_id: message.chat.id, text: "Sorry, my brain can't compute more than 140 characters 😅")
end
end
end