2016-08-16 14:18:44 +02:00
|
|
|
local soundboard = {}
|
|
|
|
|
|
|
|
function soundboard:init(config)
|
2016-08-17 18:15:05 +02:00
|
|
|
soundboard.triggers = {
|
|
|
|
"^/(sound) (.+)$",
|
|
|
|
"^/(gronkh) (.+)$"
|
|
|
|
}
|
2016-08-16 14:18:44 +02:00
|
|
|
soundboard.inline_triggers = {
|
2016-08-17 18:15:05 +02:00
|
|
|
"^(sound) (.+)$",
|
|
|
|
"^(gronkh) (.+)$"
|
2016-08-16 14:18:44 +02:00
|
|
|
}
|
|
|
|
soundboard.doc = [[*
|
2016-08-17 18:15:05 +02:00
|
|
|
]]..config.cmd_pat..[[sound/gronkh* _<Sound>_: Sendet einen Sound
|
|
|
|
*]]..config.cmd_pat..[[sound/gronkh* _<Liste>_: Sendet eine Liste aller Sounds
|
2016-08-16 14:18:44 +02:00
|
|
|
]]
|
|
|
|
end
|
|
|
|
soundboard.command = 'sound <Sound>'
|
|
|
|
|
2016-08-17 18:15:05 +02:00
|
|
|
local BASE_URL = 'http://code.ponywave.de/workspace/mikubot/sounds'
|
|
|
|
--local BASE_URL = 'http://kyouko.local/sounds'
|
|
|
|
local GRONKH_URL = 'http://code.ponywave.de/workspace/mikubot/gronkhsounds'
|
2016-08-16 14:18:44 +02:00
|
|
|
|
|
|
|
function soundboard:inline_callback(inline_query, config, matches)
|
2016-08-17 18:15:05 +02:00
|
|
|
local board = matches[1]
|
|
|
|
local input = matches[2]
|
|
|
|
if board == 'sound' then
|
|
|
|
url = BASE_URL..'/'..string.lower(input)..'.mp3'
|
|
|
|
elseif board == 'gronkh' then
|
|
|
|
url = GRONKH_URL..'/'..string.lower(input)..'.mp3'
|
|
|
|
end
|
2016-08-16 14:18:44 +02:00
|
|
|
local _, code = get_http_header(url)
|
|
|
|
if code ~= 200 then utilities.answer_inline_query(self, inline_query, nil, 5, true) return end
|
|
|
|
local results = '[{"type":"audio","id":"7900","title":"'..input..'","audio_url":"'..url..'"}]'
|
2016-08-17 18:15:05 +02:00
|
|
|
utilities.answer_inline_query(self, inline_query, results, 2)
|
2016-08-16 14:18:44 +02:00
|
|
|
end
|
|
|
|
|
2016-08-17 18:15:05 +02:00
|
|
|
function soundboard:action(msg, config, matches)
|
|
|
|
local board = matches[1]
|
|
|
|
local input = matches[2]
|
2016-08-16 14:18:44 +02:00
|
|
|
|
|
|
|
if input:match('^[Ll][Ii][Ss][Tt][Ee]$') then
|
2016-08-17 18:15:05 +02:00
|
|
|
if board == 'sound' then
|
|
|
|
utilities.send_reply(self, msg, '<a href="https://ponywave.de/a/sounds">Hier findest du eine Liste aller Sounds!</a>', 'HTML')
|
|
|
|
return
|
|
|
|
elseif board == 'gronkh' then
|
|
|
|
utilities.send_reply(self, msg, '<a href="https://ponywave.de/a/gronkhsounds">Hier findest du eine Liste aller Gronkh-Sounds!</a>', 'HTML')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if board == 'sound' then
|
|
|
|
url = BASE_URL..'/'..string.lower(input)..'.mp3'
|
|
|
|
elseif board == 'gronkh' then
|
|
|
|
url = GRONKH_URL..'/'..string.lower(input)..'.mp3'
|
2016-08-16 14:18:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local sound = download_to_file(url)
|
|
|
|
if not sound then
|
|
|
|
utilities.send_reply(self, msg, config.errors.results)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
utilities.send_audio(self, msg.chat.id, sound, msg.message_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
return soundboard
|