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

47 lines
925 B
Lua
Raw Normal View History

floodcontrol = {}
local triggers = {
'/floodcontrol'
}
local action = function(msg)
local input, output
if msg.from.id ~= 100547061 then -- Only acknowledge Liberbot.
if not config.admins[msg.from.id] then -- or an admin. :)
return
end
end
input = get_input(msg.text) -- Remove the first word from the input.
input = JSON.decode(input) -- Parse the JSON into a table.
if not input.groupid then return end -- If no group is specified, end.
if not input.duration then -- If no duration is specified, set it to 5min.
input.duration = 600
end
floodcontrol[input.groupid] = os.time() + input.duration
local s = input.groupid .. ' silenced for ' .. input.duration .. ' seconds.'
send_message(-34496439, s)
end
local cron = function()
for k,v in pairs(floodcontrol) do
if os.time() > v then
floodcontrol[k] = nil
end
end
end
return {
triggers = triggers,
action = action,
cron = cron
}