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/cowsay.lua

40 lines
1.2 KiB
Lua
Raw Normal View History

local cowsay = {}
function cowsay:init(config)
cowsay.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('cowsay', true).table
cowsay.inline_triggers = {'^cow (.+)$'}
cowsay.doc = '\n*/cowsay* _<Text>_'
end
cowsay.command = 'cowsay <Text>'
function cowsay:inline_callback(inline_query, config, matches)
local input = matches[1]
2016-08-24 17:18:17 +02:00
if string.match(input, '"') then abort_inline_query(inline_query) return end
local text = '```'..run_command('cowsay "'..input..'"')..'```'
local text = text:gsub('\\', '\\\\')
2016-08-24 23:44:45 +02:00
local results = '[{"type":"article","id":"7912","title":"Muh!","description":"'..input..'","thumb_url":"http://img.ponywave.de/di/DQG2/cow.jpg","input_message_content":{"message_text":"'..text..'","parse_mode":"Markdown"}}]'
2016-08-24 17:18:17 +02:00
utilities.answer_inline_query(inline_query, results, 2)
end
function cowsay:action(msg, config)
local input = utilities.input_from_msg(msg)
if not input then
2016-08-24 17:18:17 +02:00
utilities.send_reply(msg, cowsay.doc, true)
return
end
if string.match(input, '"') then
text = 'Vergiss es!'
else
text = '```'..run_command('cowsay "'..input..'"')..'```'
end
2016-08-24 17:18:17 +02:00
utilities.send_reply(msg, text, true)
end
return cowsay