diff --git a/miku/plugins/soundboard.lua b/miku/plugins/soundboard.lua new file mode 100644 index 0000000..77a33fb --- /dev/null +++ b/miku/plugins/soundboard.lua @@ -0,0 +1,48 @@ +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* __: Sendet einen Sound +*]]..config.cmd_pat..[[sound* __: Sendet eine Liste aller Sounds +]] +end +soundboard.command = '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, 'Hier findest du eine Liste aller Sounds!', '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