2015-11-25 03:22:04 +01:00
|
|
|
-- Moderation for Liberbot groups.
|
|
|
|
-- The bot must be made an admin.
|
|
|
|
-- Put this near the top, after blacklist.
|
|
|
|
-- If you want to enable antisquig, put that at the top, before blacklist.
|
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation then
|
|
|
|
database.moderation = {}
|
|
|
|
end
|
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
local antisquig = {}
|
2015-11-25 03:22:04 +01:00
|
|
|
|
|
|
|
local commands = {
|
|
|
|
|
|
|
|
['^/modhelp[@'..bot.username..']*$'] = function(msg)
|
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str] then return end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
local output = [[
|
|
|
|
*Users:*
|
|
|
|
• /modlist - List the moderators and administrators of this group.
|
|
|
|
*Moderators:*
|
|
|
|
• /modkick - Kick a user from this group.
|
|
|
|
• /modban - Ban a user from this group.
|
|
|
|
*Administrators:*
|
|
|
|
• /modadd - Add this group to the moderation system.
|
|
|
|
• /modrem - Remove this group from the moderation system.
|
|
|
|
• /modprom - Promote a user to a moderator.
|
|
|
|
• /moddem - Demote a moderator to a user.
|
|
|
|
• /modcast - Send a broadcast to every moderated group.
|
2015-11-25 03:22:04 +01:00
|
|
|
]]
|
2016-02-23 04:58:32 +01:00
|
|
|
output = output:gsub('\t', '')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
end,
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
['^/modlist[@'..bot.username..']*$'] = function(msg)
|
2015-09-07 17:19:36 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str] then return end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
local output = ''
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
for k,v in pairs(database.moderation[msg.chat.id_str]) do
|
2016-02-23 04:58:32 +01:00
|
|
|
output = output .. '• ' .. v .. ' (' .. k .. ')\n'
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
if output ~= '' then
|
|
|
|
output = '*Moderators for* _' .. msg.chat.title .. '_ *:*\n' .. output
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
output = output .. '*Administrators for* _' .. config.moderation.realm_name .. '_ *:*\n'
|
2015-11-25 03:22:04 +01:00
|
|
|
for k,v in pairs(config.moderation.admins) do
|
2016-02-23 04:58:32 +01:00
|
|
|
output = output .. '• ' .. v .. ' (' .. k .. ')\n'
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
end,
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
['^/modcast[@'..bot.username..']*'] = function(msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
local output = msg.text:input()
|
|
|
|
if not output then
|
2015-11-25 03:22:04 +01:00
|
|
|
return 'You must include a message.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if msg.chat.id ~= config.moderation.admin_group then
|
|
|
|
return 'This command must be run in the administration group.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not config.moderation.admins[msg.from.id_str] then
|
2016-02-23 04:58:32 +01:00
|
|
|
return config.moderation.errors.not_admin
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
output = '*Admin Broadcast:*\n' .. output
|
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
for k,v in pairs(database.moderation) do
|
2016-02-23 04:58:32 +01:00
|
|
|
sendMessage(k, output, true, nil, true)
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
return 'Your broadcast has been sent.'
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
end,
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-12-13 22:31:22 +01:00
|
|
|
['^/modadd[@'..bot.username..']*$'] = function(msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not config.moderation.admins[msg.from.id_str] then
|
2016-02-23 04:58:32 +01:00
|
|
|
return config.moderation.errors.not_admin
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if database.moderation[msg.chat.id_str] then
|
2015-11-25 03:22:04 +01:00
|
|
|
return 'I am already moderating this group.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
database.moderation[msg.chat.id_str] = {}
|
2015-11-25 03:22:04 +01:00
|
|
|
return 'I am now moderating this group.'
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
end,
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-12-13 22:31:22 +01:00
|
|
|
['^/modrem[@'..bot.username..']*$'] = function(msg)
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not config.moderation.admins[msg.from.id_str] then
|
2016-02-23 04:58:32 +01:00
|
|
|
return config.moderation.errors.not_admin
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str] then
|
2016-02-23 04:58:32 +01:00
|
|
|
return config.moderation.errors.moderation
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
database.moderation[msg.chat.id_str] = nil
|
2015-11-25 03:22:04 +01:00
|
|
|
return 'I am no longer moderating this group.'
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
end,
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-12-13 22:31:22 +01:00
|
|
|
['^/modprom[@'..bot.username..']*$'] = function(msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str] then return end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not config.moderation.admins[msg.from.id_str] then
|
2016-02-23 04:58:32 +01:00
|
|
|
return config.moderation.errors.not_admin
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not msg.reply_to_message then
|
|
|
|
return 'Promotions must be done via reply.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local modid = tostring(msg.reply_to_message.from.id)
|
|
|
|
local modname = msg.reply_to_message.from.first_name
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if config.moderation.admins[modid] then
|
|
|
|
return modname .. ' is already an administrator.'
|
2015-08-09 02:53:46 +02:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if database.moderation[msg.chat.id_str][modid] then
|
2015-11-25 03:22:04 +01:00
|
|
|
return modname .. ' is already a moderator.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
database.moderation[msg.chat.id_str][modid] = modname
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
return modname .. ' is now a moderator.'
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
end,
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-12-13 22:31:22 +01:00
|
|
|
['^/moddem[@'..bot.username..']*'] = function(msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str] then return end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not config.moderation.admins[msg.from.id_str] then
|
2016-02-23 04:58:32 +01:00
|
|
|
return config.moderation.errors.not_admin
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local modid = msg.text:input()
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not modid then
|
|
|
|
if msg.reply_to_message then
|
|
|
|
modid = tostring(msg.reply_to_message.from.id)
|
|
|
|
else
|
|
|
|
return 'Demotions must be done via reply or specification of a moderator\'s ID.'
|
|
|
|
end
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if config.moderation.admins[modid] then
|
|
|
|
return config.moderation.admins[modid] .. ' is an administrator.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str][modid] then
|
2015-11-25 03:22:04 +01:00
|
|
|
return 'User is not a moderator.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
local modname = database.moderation[msg.chat.id_str][modid]
|
|
|
|
database.moderation[msg.chat.id_str][modid] = nil
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
return modname .. ' is no longer a moderator.'
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
end,
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
['/modkick[@'..bot.username..']*'] = function(msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str] then return end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str][msg.from.id_str] then
|
2015-11-25 03:22:04 +01:00
|
|
|
if not config.moderation.admins[msg.from.id_str] then
|
2016-02-23 04:58:32 +01:00
|
|
|
return config.moderation.errors.not_mod
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local userid = msg.text:input()
|
|
|
|
local usernm = userid
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-27 00:40:01 +01:00
|
|
|
if msg.reply_to_message then
|
|
|
|
userid = tostring(msg.reply_to_message.from.id)
|
|
|
|
usernm = msg.reply_to_message.from.first_name
|
|
|
|
end
|
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not userid then
|
2015-11-27 00:40:01 +01:00
|
|
|
return 'Kicks must be done via reply or specification of a user/bot\'s ID or username.'
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if database.moderation[msg.chat.id_str][userid] or config.moderation.admins[userid] then
|
2015-11-25 03:22:04 +01:00
|
|
|
return 'You cannot kick a moderator.'
|
|
|
|
end
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
sendMessage(config.moderation.admin_group, '/kick ' .. userid .. ' from ' .. math.abs(msg.chat.id))
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
sendMessage(config.moderation.admin_group, usernm .. ' kicked from ' .. msg.chat.title .. ' by ' .. msg.from.first_name .. '.')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
end,
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
['^/modban[@'..bot.username..']*'] = function(msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str] then return end
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str][msg.from.id_str] then
|
2015-11-25 03:22:04 +01:00
|
|
|
if not config.moderation.admins[msg.from.id_str] then
|
2016-02-23 04:58:32 +01:00
|
|
|
return config.moderation.errors.not_mod
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
|
|
|
end
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local userid = msg.text:input()
|
|
|
|
local usernm = userid
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2015-11-27 00:40:01 +01:00
|
|
|
if msg.reply_to_message then
|
|
|
|
userid = tostring(msg.reply_to_message.from.id)
|
|
|
|
usernm = msg.reply_to_message.from.first_name
|
|
|
|
end
|
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not userid then
|
2015-11-27 00:40:01 +01:00
|
|
|
return 'Kicks must be done via reply or specification of a user/bot\'s ID or username.'
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-09-07 17:19:36 +02:00
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if database.moderation[msg.chat.id_str][userid] or config.moderation.admins[userid] then
|
2015-11-25 03:22:04 +01:00
|
|
|
return 'You cannot ban a moderator.'
|
|
|
|
end
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
sendMessage(config.moderation.admin_group, '/ban ' .. userid .. ' from ' .. math.abs(msg.chat.id))
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
sendMessage(config.moderation.admin_group, usernm .. ' banned from ' .. msg.chat.title .. ' by ' .. msg.from.first_name .. '.')
|
2015-08-18 11:55:25 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-07-29 00:13:46 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
if config.moderation.antisquig then
|
2016-01-08 04:30:12 +01:00
|
|
|
commands['[\216-\219][\128-\191]'] = function(msg)
|
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
if not database.moderation[msg.chat.id_str] then return true end
|
2016-01-08 04:30:12 +01:00
|
|
|
if config.moderation.admins[msg.from.id_str] then return true end
|
2016-02-21 20:28:40 +01:00
|
|
|
if database.moderation[msg.chat.id_str][msg.from.id_str] then return true end
|
2016-01-08 04:30:12 +01:00
|
|
|
|
|
|
|
if antisquig[msg.from.id] == true then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
antisquig[msg.from.id] = true
|
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
sendReply(msg, config.moderation.errors.antisquig)
|
2016-01-08 04:30:12 +01:00
|
|
|
sendMessage(config.moderation.admin_group, '/kick ' .. msg.from.id .. ' from ' .. math.abs(msg.chat.id))
|
|
|
|
sendMessage(config.moderation.admin_group, 'ANTISQUIG: ' .. msg.from.first_name .. ' kicked from ' .. msg.chat.title .. '.')
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local triggers = {}
|
|
|
|
for k,v in pairs(commands) do
|
|
|
|
table.insert(triggers, k)
|
|
|
|
end
|
|
|
|
|
2015-07-29 00:13:46 +02:00
|
|
|
local action = function(msg)
|
2015-11-25 03:22:04 +01:00
|
|
|
|
|
|
|
for k,v in pairs(commands) do
|
2015-12-13 22:31:22 +01:00
|
|
|
if string.match(msg.text_lower, k) then
|
2015-11-25 03:22:04 +01:00
|
|
|
local output = v(msg)
|
2016-01-08 04:30:12 +01:00
|
|
|
if output == true then
|
|
|
|
return true
|
|
|
|
elseif output then
|
2015-11-25 03:22:04 +01:00
|
|
|
sendReply(msg, output)
|
|
|
|
end
|
|
|
|
return
|
2015-07-29 00:13:46 +02:00
|
|
|
end
|
|
|
|
end
|
2015-11-25 03:22:04 +01:00
|
|
|
|
2016-01-08 04:30:12 +01:00
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
-- When a user is kicked for squiggles, his ID is added to this table.
|
2016-01-08 04:30:12 +01:00
|
|
|
-- That user will not be kicked again as long as his ID is in the table.
|
|
|
|
-- The table is emptied every five seconds.
|
|
|
|
-- Thus the bot will not spam the group or admin group when a user posts more than one infringing messages.
|
|
|
|
local cron = function()
|
|
|
|
|
|
|
|
antisquig = {}
|
|
|
|
|
2015-07-29 00:13:46 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2015-11-25 03:22:04 +01:00
|
|
|
action = action,
|
2016-01-08 04:30:12 +01:00
|
|
|
triggers = triggers,
|
|
|
|
cron = cron
|
2015-07-29 00:13:46 +02:00
|
|
|
}
|