49 lines
1.6 KiB
Lua
49 lines
1.6 KiB
Lua
local soundboard = {}
|
|
|
|
function soundboard:init(config)
|
|
soundboard.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('sound', true).table
|
|
soundboard.inline_triggers = {
|
|
"^sounds? (.+)$"
|
|
}
|
|
soundboard.doc = [[*
|
|
]]..config.cmd_pat..[[sound* _<Sound>_: Sendet einen Sound
|
|
*]]..config.cmd_pat..[[sound* _<Liste>_: Sendet eine Liste aller Sounds
|
|
]]
|
|
end
|
|
soundboard.command = 'sound <Sound>'
|
|
|
|
-- local BASE_URL = 'http://code.ponywave.de/workspace/mikubot/sounds'
|
|
local BASE_URL = 'http://kyouko.local/sounds'
|
|
|
|
function soundboard:inline_callback(inline_query, config, matches)
|
|
local input = matches[1]
|
|
local url = BASE_URL..'/'..string.lower(input)..'.mp3'
|
|
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..'"}]'
|
|
utilities.answer_inline_query(self, inline_query, results, 3600)
|
|
end
|
|
|
|
function soundboard:action(msg, config)
|
|
local input = utilities.input_from_msg(msg)
|
|
if not input then
|
|
utilities.send_reply(self, msg, soundboard.doc, true)
|
|
return
|
|
end
|
|
|
|
if input:match('^[Ll][Ii][Ss][Tt][Ee]$') then
|
|
utilities.send_reply(self, msg, '<a href="https://ponywave.de/a/sounds">Hier findest du eine Liste aller Sounds!</a>', 'HTML')
|
|
return
|
|
end
|
|
|
|
local url = BASE_URL..'/'..string.lower(input)..'.mp3'
|
|
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
|