2015-11-25 03:22:04 +01:00
|
|
|
-- Requires that the "fortune" program is installed on your computer.
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
local fortune = {}
|
|
|
|
|
2016-06-07 06:31:34 +02:00
|
|
|
local utilities = require('otouto.utilities')
|
2015-11-25 03:22:04 +01:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
function fortune:init(config)
|
2016-04-11 06:04:47 +02:00
|
|
|
local s = io.popen('fortune'):read('*all')
|
|
|
|
if s:match('not found$') then
|
|
|
|
print('fortune is not installed on this computer.')
|
|
|
|
print('fortune.lua will not be enabled.')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
fortune.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('fortune').table
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
fortune.command = 'fortune'
|
2016-07-25 11:03:35 +02:00
|
|
|
fortune.doc = 'Returns a UNIX fortune.'
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
function fortune:action(msg)
|
2015-11-25 03:22:04 +01:00
|
|
|
|
2016-04-29 06:12:04 +02:00
|
|
|
local fortunef = io.popen('fortune')
|
|
|
|
local output = fortunef:read('*all')
|
2016-05-08 01:30:48 +02:00
|
|
|
output = '```\n' .. output .. '\n```'
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
2016-04-29 06:12:04 +02:00
|
|
|
fortunef:close()
|
2015-11-25 03:22:04 +01:00
|
|
|
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return fortune
|