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.
|
|
|
|
|
|
|
|
local triggers = {
|
|
|
|
'^/modhelp[@'..bot.username..']*$',
|
|
|
|
'^/modlist[@'..bot.username..']*$',
|
|
|
|
'^/modcast[@'..bot.username..']*',
|
2015-12-13 22:31:22 +01:00
|
|
|
'^/modadd[@'..bot.username..']*$',
|
|
|
|
'^/modrem[@'..bot.username..']*$',
|
|
|
|
'^/modprom[@'..bot.username..']*$',
|
|
|
|
'^/moddem[@'..bot.username..']*',
|
2015-11-25 03:22:04 +01:00
|
|
|
'^/modkick[@'..bot.username..']*',
|
|
|
|
'^/modban[@'..bot.username..']*',
|
|
|
|
}
|
|
|
|
|
|
|
|
local commands = {
|
|
|
|
|
|
|
|
['^/modhelp[@'..bot.username..']*$'] = function(msg)
|
|
|
|
|
|
|
|
local moddat = load_data('moderation.json')
|
|
|
|
|
|
|
|
if not moddat[msg.chat.id_str] then
|
|
|
|
return config.errors.moderation
|
2015-08-18 11:55:25 +02:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local message = [[
|
|
|
|
/modlist - List the moderators and administrators of this group.
|
|
|
|
Moderator commands:
|
|
|
|
/modkick - Kick a user from this group.
|
|
|
|
/modban - Ban a user from this group.
|
|
|
|
Administrator commands:
|
|
|
|
/add - Add this group to the moderation system.
|
|
|
|
/remove - Remove this group from the moderation system.
|
|
|
|
/promote - Promote a user to a moderator.
|
|
|
|
/demote - Demote a moderator to a user.
|
|
|
|
/modcast - Send a broadcast to every moderated group.
|
|
|
|
]]
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
return message
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local moddat = load_data('moderation.json')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not moddat[msg.chat.id_str] then
|
|
|
|
return config.errors.moderation
|
2015-08-18 11:55:25 +02:00
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local message = ''
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
for k,v in pairs(moddat[msg.chat.id_str]) do
|
|
|
|
message = message .. ' - ' .. v .. ' (' .. k .. ')\n'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if message ~= '' then
|
|
|
|
message = 'Moderators for ' .. msg.chat.title .. ':\n' .. message .. '\n'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
message = message .. 'Administrators for ' .. config.moderation.realm_name .. ':\n'
|
|
|
|
for k,v in pairs(config.moderation.admins) do
|
|
|
|
message = message .. ' - ' .. v .. ' (' .. k .. ')\n'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
return message
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local message = msg.text:input()
|
|
|
|
if not message then
|
|
|
|
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
|
|
|
|
return config.errors.not_admin
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local moddat = load_data('moderation.json')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
for k,v in pairs(moddat) do
|
|
|
|
sendMessage(k, message)
|
|
|
|
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
|
|
|
|
return config.errors.not_admin
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local moddat = load_data('moderation.json')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if moddat[msg.chat.id_str] then
|
|
|
|
return 'I am already moderating this group.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
moddat[msg.chat.id_str] = {}
|
|
|
|
save_data('moderation.json', moddat)
|
|
|
|
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
|
|
|
|
return config.errors.not_admin
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local moddat = load_data('moderation.json')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not moddat[msg.chat.id_str] then
|
|
|
|
return config.errors.moderation
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
moddat[msg.chat.id_str] = nil
|
|
|
|
save_data('moderation.json', moddat)
|
|
|
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local moddat = load_data('moderation.json')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not moddat[msg.chat.id_str] then
|
|
|
|
return config.errors.moderation
|
|
|
|
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
|
|
|
|
return config.errors.not_admin
|
|
|
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if moddat[msg.chat.id_str][modid] then
|
|
|
|
return modname .. ' is already a moderator.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
moddat[msg.chat.id_str][modid] = modname
|
|
|
|
save_data('moderation.json', moddat)
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local moddat = load_data('moderation.json')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not moddat[msg.chat.id_str] then
|
|
|
|
return config.errors.moderation
|
|
|
|
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
|
|
|
|
return config.errors.not_admin
|
|
|
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not moddat[msg.chat.id_str][modid] then
|
|
|
|
return 'User is not a moderator.'
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local modname = moddat[msg.chat.id_str][modid]
|
|
|
|
moddat[msg.chat.id_str][modid] = nil
|
|
|
|
save_data('moderation.json', moddat)
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local moddat = load_data('moderation.json')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not moddat[msg.chat.id_str] then
|
|
|
|
return config.errors.moderation
|
|
|
|
end
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not moddat[msg.chat.id_str][msg.from.id_str] then
|
|
|
|
if not config.moderation.admins[msg.from.id_str] then
|
|
|
|
return config.errors.not_mod
|
|
|
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if moddat[msg.chat.id_str][userid] or config.moderation.admins[userid] then
|
|
|
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local moddat = load_data('moderation.json')
|
2015-07-29 00:13:46 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not moddat[msg.chat.id_str] then
|
|
|
|
return config.errors.moderation
|
|
|
|
end
|
2015-08-18 11:55:25 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if not moddat[msg.chat.id_str][msg.from.id_str] then
|
|
|
|
if not config.moderation.admins[msg.from.id_str] then
|
|
|
|
return config.errors.not_mod
|
|
|
|
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
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
if moddat[msg.chat.id_str][userid] or config.moderation.admins[userid] then
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
if output then
|
|
|
|
sendReply(msg, output)
|
|
|
|
end
|
|
|
|
return
|
2015-07-29 00:13:46 +02:00
|
|
|
end
|
|
|
|
end
|
2015-11-25 03:22:04 +01:00
|
|
|
|
2015-07-29 00:13:46 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2015-11-25 03:22:04 +01:00
|
|
|
action = action,
|
|
|
|
triggers = triggers
|
2015-07-29 00:13:46 +02:00
|
|
|
}
|