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

55 lines
1005 B
Lua
Raw Normal View History

local doc = [[
/roll <nDr>
Returns a set of dice rolls, where n is the number of rolls and r is the range. If only a range is given, returns only one roll.
2015-07-03 00:15:52 +02:00
]]
local triggers = {
'^/roll[@'..bot.username..']*'
2015-07-03 00:15:52 +02:00
}
local action = function(msg)
2015-07-03 00:15:52 +02:00
local input = msg.text_lower:input()
2015-07-03 00:15:52 +02:00
if not input then
sendReply(msg, doc)
return
2015-07-03 00:15:52 +02:00
end
local count, range
if input:match('^[%d]+d[%d]+$') then
count, range = input:match('([%d]+)d([%d]+)')
elseif input:match('^d?[%d]+$') then
count = 1
range = input:match('^d?([%d]+)$')
2015-07-03 00:15:52 +02:00
else
sendReply(msg, doc)
return
2015-07-03 00:15:52 +02:00
end
count = tonumber(count)
range = tonumber(range)
2015-07-03 00:15:52 +02:00
if range < 2 then
sendReply(msg, 'The minimum range is 2.')
return
2015-07-03 00:15:52 +02:00
end
if range > 1000 or count > 1000 then
sendReply(msg, 'The maximum range and count are 1000.')
return
2015-07-03 00:15:52 +02:00
end
local message = ''
for i = 1, count do
message = message .. math.random(range) .. '\t'
2015-07-03 00:15:52 +02:00
end
sendReply(msg, message)
2015-07-03 00:15:52 +02:00
end
return {
action = action,
triggers = triggers,
doc = doc
}