This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/miku/plugins/soundboard.lua
Andreas Bielawski 557405af2f - get_txt hinzugefügt
- Gronkh-Soundboard ins Soundboard integriert
2016-08-17 18:15:05 +02:00

66 lines
2.1 KiB
Lua

local soundboard = {}
function soundboard:init(config)
soundboard.triggers = {
"^/(sound) (.+)$",
"^/(gronkh) (.+)$"
}
soundboard.inline_triggers = {
"^(sound) (.+)$",
"^(gronkh) (.+)$"
}
soundboard.doc = [[*
]]..config.cmd_pat..[[sound/gronkh* _<Sound>_: Sendet einen Sound
*]]..config.cmd_pat..[[sound/gronkh* _<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'
local GRONKH_URL = 'http://code.ponywave.de/workspace/mikubot/gronkhsounds'
function soundboard:inline_callback(inline_query, config, matches)
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
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, 2)
end
function soundboard:action(msg, config, matches)
local board = matches[1]
local input = matches[2]
if input:match('^[Ll][Ii][Ss][Tt][Ee]$') then
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'
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