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

66 lines
2.1 KiB
Lua
Raw Normal View History

2016-08-16 14:18:44 +02:00
local soundboard = {}
function soundboard:init(config)
soundboard.triggers = {
"^/(sound) (.+)$",
"^/(gronkh) (.+)$"
}
2016-08-16 14:18:44 +02:00
soundboard.inline_triggers = {
"^(sound) (.+)$",
"^(gronkh) (.+)$"
2016-08-16 14:18:44 +02:00
}
soundboard.doc = [[*
]]..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>'
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)
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..'"}]'
utilities.answer_inline_query(self, inline_query, results, 2)
2016-08-16 14:18:44 +02:00
end
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
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