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-04-11 06:04:47 +02:00
|
|
|
local moderation = {}
|
|
|
|
|
|
|
|
local bindings = require('bindings')
|
|
|
|
local utilities = require('utilities')
|
2016-02-21 20:28:40 +01:00
|
|
|
|
2016-02-23 04:58:32 +01:00
|
|
|
local antisquig = {}
|
2015-11-25 03:22:04 +01:00
|
|
|
|
|
|
|
local commands = {
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
['^/modhelp$'] = function(self, msg)
|
2015-11-25 03:22:04 +01:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.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-04-11 06:04:47 +02:00
|
|
|
bindings.sendMessage(self, 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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
['^/modlist$'] = function(self, msg)
|
2015-09-07 17:19:36 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.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-04-11 06:04:47 +02:00
|
|
|
for k,v in pairs(self.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-04-11 06:04:47 +02:00
|
|
|
output = output .. '*Administrators for* _' .. self.config.moderation.realm_name .. '_ *:*\n'
|
|
|
|
for k,v in pairs(self.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-04-11 06:04:47 +02:00
|
|
|
bindings.sendMessage(self, 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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
['^/modcast'] = function(self, msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-08 23:12:02 +02:00
|
|
|
local output = utilities.input(msg.text)
|
2016-02-23 04:58:32 +01:00
|
|
|
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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if msg.chat.id ~= self.config.moderation.admin_group then
|
2015-11-25 03:22:04 +01:00
|
|
|
return 'This command must be run in the administration group.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.config.moderation.admins[msg.from.id_str] then
|
|
|
|
return self.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-04-11 06:04:47 +02:00
|
|
|
for k,_ in pairs(self.database.moderation) do
|
|
|
|
bindings.sendMessage(self, 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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
['^/modadd$'] = function(self, msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.config.moderation.admins[msg.from.id_str] then
|
|
|
|
return self.config.moderation.errors.not_admin
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if self.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-04-11 06:04:47 +02:00
|
|
|
self.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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
['^/modrem$'] = function(self, msg)
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.config.moderation.admins[msg.from.id_str] then
|
|
|
|
return self.config.moderation.errors.not_admin
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.database.moderation[msg.chat.id_str] then
|
|
|
|
return self.config.moderation.errors.moderation
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
self.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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
['^/modprom$'] = function(self, msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.database.moderation[msg.chat.id_str] then return end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.config.moderation.admins[msg.from.id_str] then
|
|
|
|
return self.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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if self.config.moderation.admins[modid] then
|
2015-11-25 03:22:04 +01:00
|
|
|
return modname .. ' is already an administrator.'
|
2015-08-09 02:53:46 +02:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if self.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-04-11 06:04:47 +02:00
|
|
|
self.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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
['^/moddem'] = function(self, msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.database.moderation[msg.chat.id_str] then return end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.config.moderation.admins[msg.from.id_str] then
|
|
|
|
return self.config.moderation.errors.not_admin
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-08 23:12:02 +02:00
|
|
|
local modid = utilities.input(msg.text)
|
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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if self.config.moderation.admins[modid] then
|
|
|
|
return self.config.moderation.admins[modid] .. ' is an administrator.'
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.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-04-11 06:04:47 +02:00
|
|
|
local modname = self.database.moderation[msg.chat.id_str][modid]
|
|
|
|
self.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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
['/modkick'] = function(self, msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.database.moderation[msg.chat.id_str] then return end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.database.moderation[msg.chat.id_str][msg.from.id_str] then
|
|
|
|
if not self.config.moderation.admins[msg.from.id_str] then
|
|
|
|
return self.config.moderation.errors.not_mod
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-08 23:12:02 +02:00
|
|
|
local userid = utilities.input(msg.text)
|
2015-11-25 03:22:04 +01:00
|
|
|
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-04-11 06:04:47 +02:00
|
|
|
if self.database.moderation[msg.chat.id_str][userid] or self.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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
bindings.sendMessage(self, self.config.moderation.admin_group, '/kick ' .. userid .. ' from ' .. math.abs(msg.chat.id))
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
bindings.sendMessage(self, self.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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
['^/modban'] = function(self, msg)
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.database.moderation[msg.chat.id_str] then return end
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.database.moderation[msg.chat.id_str][msg.from.id_str] then
|
|
|
|
if not self.config.moderation.admins[msg.from.id_str] then
|
|
|
|
return self.config.moderation.errors.not_mod
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
|
|
|
end
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-04-08 23:12:02 +02:00
|
|
|
local userid = utilities.input(msg.text)
|
2015-11-25 03:22:04 +01:00
|
|
|
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-04-11 06:04:47 +02:00
|
|
|
if self.database.moderation[msg.chat.id_str][userid] or self.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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
bindings.sendMessage(self.config.moderation.admin_group, '/ban ' .. userid .. ' from ' .. math.abs(msg.chat.id))
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
bindings.sendMessage(self.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-04-11 06:04:47 +02:00
|
|
|
function moderation:init()
|
|
|
|
if not self.database.moderation then
|
|
|
|
self.database.moderation = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.config.moderation.antisquig then
|
|
|
|
commands['[\216-\219][\128-\191]'] = function(msg)
|
2016-01-08 04:30:12 +01:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if not self.database.moderation[msg.chat.id_str] then return true end
|
|
|
|
if self.config.moderation.admins[msg.from.id_str] then return true end
|
|
|
|
if self.database.moderation[msg.chat.id_str][msg.from.id_str] then return true end
|
2016-01-08 04:30:12 +01:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
if antisquig[msg.from.id] == true then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
antisquig[msg.from.id] = true
|
2016-01-08 04:30:12 +01:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
bindings.sendReply(self, msg, self.config.moderation.errors.antisquig)
|
|
|
|
bindings.sendMessage(self, self.config.moderation.admin_group, '/kick ' .. msg.from.id .. ' from ' .. math.abs(msg.chat.id))
|
|
|
|
bindings.sendMessage(self, self.config.moderation.admin_group, 'ANTISQUIG: ' .. msg.from.first_name .. ' kicked from ' .. msg.chat.title .. '.')
|
2016-01-08 04:30:12 +01:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
2016-01-08 04:30:12 +01:00
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
moderation.triggers = {}
|
|
|
|
for trigger,_ in pairs(commands) do
|
|
|
|
if trigger[-1] == '$' then
|
|
|
|
moderation.triggers:insert(trigger:sub(1, -2)..'@'..self.info.username..'$')
|
|
|
|
else
|
|
|
|
moderation.triggers:insert(trigger..'%s+[^%s]*')
|
|
|
|
moderation.triggers:insert(trigger..'@'..self.info.username..'%s+[^%s]*')
|
|
|
|
moderation.triggers:insert(trigger..'$')
|
|
|
|
moderation.triggers:insert(trigger..'@'..self.info.username..'$')
|
|
|
|
end
|
|
|
|
end
|
2016-01-08 04:30:12 +01:00
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
function moderation:action(msg)
|
2015-11-25 03:22:04 +01:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
for trigger,command in pairs(commands) do
|
|
|
|
if string.match(msg.text_lower, trigger) then
|
|
|
|
local output = command(self, msg)
|
2016-01-08 04:30:12 +01:00
|
|
|
if output == true then
|
|
|
|
return true
|
|
|
|
elseif output then
|
2016-04-11 06:04:47 +02:00
|
|
|
bindings.sendReply(self, msg, output)
|
2015-11-25 03:22:04 +01:00
|
|
|
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.
|
2016-04-11 06:04:47 +02:00
|
|
|
function moderation:cron()
|
2016-01-08 04:30:12 +01:00
|
|
|
|
|
|
|
antisquig = {}
|
|
|
|
|
2015-07-29 00:13:46 +02:00
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return moderation
|