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/plugins/dice.lua
topkecleon 60570e90f3 added cron jobs for plugins
added example plugin with documentation
added liberbot-compliant flood control
	see Liberbot Support for details on getting compliant
added Kickass Torrent plugin
various bugfixes
all files seem to have been marked changed due to a shift in platform
	I will do a clean clone and testing to ensure there is no issue.
2015-08-28 23:15:01 -07:00

68 lines
1.3 KiB
Lua
Executable File

local PLUGIN = {}
PLUGIN.doc = [[
/roll [arg]
Roll a die. Use any positive number for range or use D&D notation.
Example: /roll 4D100 will roll a 100-sided die four times.
]]
PLUGIN.triggers = {
'^/roll'
}
function PLUGIN.action(msg)
math.randomseed(os.time())
local input = get_input(msg.text)
if not input then
input = 6
else
input = string.upper(input)
end
if tonumber(input) then
range = tonumber(input)
rolls = 1
elseif string.find(input, 'D') then
local dloc = string.find(input, 'D')
if dloc == 1 then
rolls = 1
else
rolls = string.sub(input, 1, dloc-1)
end
range = string.sub(input, dloc+1)
if not tonumber(rolls) or not tonumber(range) then
return send_msg(msg, config.locale.errors.argument)
end
else
return send_msg(msg, config.locale.errors.argument)
end
if tonumber(rolls) == 1 then
results = 'Random (1-' .. range .. '):\t'
elseif tonumber(rolls) > 1 then
results = rolls .. 'D' .. range .. ':\n'
else
return send_msg(msg, config.locale.errors.syntax)
end
if tonumber(range) < 2 then
return send_msg(msg, config.locale.errors.syntax)
end
if tonumber(rolls) > 100 or tonumber(range) > 100000 then
return send_msg(msg, 'Max 100D100000')
end
for i = 1, tonumber(rolls) do
results = results .. math.random(range) .. '\t'
end
send_msg(msg, results)
end
return PLUGIN