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/blacklist.lua
topkecleon 02a7d411fa Database is now centralized. All data is stored in tables within the database table,
which is automatically saved. Please be sure to always stop the bot with /halt to
prevent data loss.
2016-02-21 14:28:40 -05:00

50 lines
1.1 KiB
Lua
Executable File

-- This plugin will allow the admin to blacklist users who will be unable to
-- use the bot. This plugin should be at the top of your plugin list in config.
if not database.blacklist then
database.blacklist = {}
end
local triggers = {
''
}
local action = function(msg)
if database.blacklist[msg.from.id_str] then
return -- End if the sender is blacklisted.
end
if not string.match(msg.text_lower, '^/blacklist') then
return true
end
if msg.from.id ~= config.admin then
return -- End if the user isn't admin.
end
local input = msg.text:input()
if not input then
if msg.reply_to_message then
input = tostring(msg.reply_to_message.from.id)
else
sendReply(msg, 'You must use this command via reply or by specifying a user\'s ID.')
return
end
end
if database.blacklist[input] then
database.blacklist[input] = nil
sendReply(msg, input .. ' has been removed from the blacklist.')
else
database.blacklist[input] = true
sendReply(msg, input .. ' has been added to the blacklist.')
end
end
return {
action = action,
triggers = triggers
}