2016-02-23 12:15:48 +01:00
|
|
|
|
--[[
|
|
|
|
|
administration.lua
|
2016-03-04 23:08:21 +01:00
|
|
|
|
Version 1.4
|
2016-02-23 12:15:48 +01:00
|
|
|
|
Part of the otouto project.
|
|
|
|
|
© 2016 topkecleon <drew@otou.to>
|
|
|
|
|
GNU General Public License, version 2
|
|
|
|
|
|
|
|
|
|
This plugin provides self-hosted, single-realm group administration.
|
|
|
|
|
It requires tg (http://github.com/vysheng/tg) with supergroup support.
|
|
|
|
|
For more documentation, view the readme or the manual (otou.to/rtfm).
|
|
|
|
|
|
|
|
|
|
Remember to load this before blacklist.lua.
|
2016-02-25 10:42:13 +01:00
|
|
|
|
|
2016-03-04 23:08:21 +01:00
|
|
|
|
Important notices about updates will be here!
|
|
|
|
|
|
2016-02-23 12:15:48 +01:00
|
|
|
|
The global banlist has been merged with the blacklist. This merge will occur
|
|
|
|
|
automatically on versions 1.1 and 1.2.
|
2016-02-25 10:42:13 +01:00
|
|
|
|
|
|
|
|
|
Group rules will now be stored in tables rather than pre-numbered strings.
|
|
|
|
|
Automatic migration will be in effect in versions 1.2 and 1.3.
|
2016-02-23 12:15:48 +01:00
|
|
|
|
]]--
|
|
|
|
|
|
|
|
|
|
-- Build the administration db if nonexistent.
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if not database.administration then
|
|
|
|
|
database.administration = {
|
|
|
|
|
global = {
|
|
|
|
|
admins = {}
|
|
|
|
|
}
|
2016-02-20 11:07:20 +01:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-23 12:15:48 +01:00
|
|
|
|
-- Create the blacklist db if nonexistant.
|
|
|
|
|
database.blacklist = database.blacklist or {}
|
|
|
|
|
|
|
|
|
|
-- Migration code: Remove this in v1.3.
|
|
|
|
|
-- Global ban list has been merged with blacklist.
|
|
|
|
|
if database.administration.global.bans then
|
|
|
|
|
for k in pairs(database.administration.global.bans) do
|
|
|
|
|
database.blacklist[k] = true
|
|
|
|
|
end
|
|
|
|
|
database.administration.global.bans = nil
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-25 10:42:13 +01:00
|
|
|
|
-- Migration code: Remove this in v1.4.
|
|
|
|
|
-- Rule lists have been converted from strings to tables.
|
|
|
|
|
for k,v in pairs(database.administration) do
|
|
|
|
|
if type(v.rules) == 'string' then
|
|
|
|
|
local t = {}
|
|
|
|
|
for l in v.rules:gmatch('(.-)\n') do
|
|
|
|
|
table.insert(t, l:sub(6))
|
|
|
|
|
end
|
|
|
|
|
v.rules = t
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-20 11:07:20 +01:00
|
|
|
|
local sender = dofile('lua-tg/sender.lua')
|
2016-03-04 23:08:21 +01:00
|
|
|
|
tg = sender('localhost', config.cli_port)
|
2016-02-20 11:07:20 +01:00
|
|
|
|
|
|
|
|
|
local flags = {
|
|
|
|
|
[1] = {
|
|
|
|
|
name = 'unlisted',
|
|
|
|
|
desc = 'Removes this group from the group listing.',
|
2016-02-25 10:42:13 +01:00
|
|
|
|
short = 'This group is unlisted.',
|
2016-02-20 11:07:20 +01:00
|
|
|
|
enabled = 'This group is no longer listed in /groups.',
|
|
|
|
|
disabled = 'This group is now listed in /groups.'
|
|
|
|
|
},
|
|
|
|
|
[2] = {
|
|
|
|
|
name = 'antisquig',
|
|
|
|
|
desc = 'Automatically removes users who post Arabic script or RTL characters.',
|
2016-02-25 10:42:13 +01:00
|
|
|
|
short = 'This group does not allow Arabic script or RTL characters.',
|
2016-02-20 11:07:20 +01:00
|
|
|
|
enabled = 'Users will now be removed automatically for posting Arabic script and/or RTL characters.',
|
|
|
|
|
disabled = 'Users will no longer be removed automatically for posting Arabic script and/or RTL characters..',
|
2016-02-25 10:42:13 +01:00
|
|
|
|
kicked = 'You were automatically kicked from GROUPNAME for posting Arabic script and/or RTL characters.'
|
2016-02-20 11:07:20 +01:00
|
|
|
|
},
|
|
|
|
|
[3] = {
|
|
|
|
|
name = 'antisquig Strict',
|
|
|
|
|
desc = 'Automatically removes users whose names contain Arabic script or RTL characters.',
|
2016-02-25 10:42:13 +01:00
|
|
|
|
short = 'This group does not allow users whose names contain Arabic script or RTL characters.',
|
2016-02-20 11:07:20 +01:00
|
|
|
|
enabled = 'Users whose names contain Arabic script and/or RTL characters will now be removed automatically.',
|
|
|
|
|
disabled = 'Users whose names contain Arabic script and/or RTL characters will no longer be removed automatically.',
|
2016-02-25 10:42:13 +01:00
|
|
|
|
kicked = 'You were automatically kicked from GROUPNAME for having a name which contains Arabic script and/or RTL characters.'
|
2016-02-20 11:07:20 +01:00
|
|
|
|
},
|
|
|
|
|
[4] = {
|
|
|
|
|
name = 'antibot',
|
|
|
|
|
desc = 'Prevents the addition of bots by non-moderators. Only useful in non-supergroups.',
|
2016-02-25 10:42:13 +01:00
|
|
|
|
short = 'This group does not allow users to add bots.',
|
2016-02-20 11:07:20 +01:00
|
|
|
|
enabled = 'Non-moderators will no longer be able to add bots.',
|
|
|
|
|
disabled = 'Non-moderators will now be able to add bots.'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local ranks = {
|
|
|
|
|
[0] = 'Banned',
|
|
|
|
|
[1] = 'Users',
|
|
|
|
|
[2] = 'Moderators',
|
|
|
|
|
[3] = 'Governors',
|
|
|
|
|
[4] = 'Administrators',
|
|
|
|
|
[5] = 'Owner'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local get_rank = function(target, chat)
|
|
|
|
|
|
|
|
|
|
target = tostring(target)
|
|
|
|
|
if chat then
|
|
|
|
|
chat = tostring(chat)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if tonumber(target) == config.admin or tonumber(target) == bot.id then
|
|
|
|
|
return 5
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration.global.admins[target] then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return 4
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if chat and database.administration[chat] then
|
|
|
|
|
if database.administration[chat].govs[target] then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return 3
|
2016-02-21 20:28:40 +01:00
|
|
|
|
elseif database.administration[chat].mods[target] then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return 2
|
2016-02-21 20:28:40 +01:00
|
|
|
|
elseif database.administration[chat].bans[target] then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-23 12:15:48 +01:00
|
|
|
|
if database.blacklist[target] then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local get_target = function(msg)
|
|
|
|
|
|
|
|
|
|
local target = {}
|
|
|
|
|
if msg.reply_to_message then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
local user = msg.reply_to_message.from
|
|
|
|
|
if msg.reply_to_message.new_chat_participant then
|
|
|
|
|
user = msg.reply_to_message.new_chat_participant
|
|
|
|
|
elseif msg.reply_to_message.left_chat_participant then
|
|
|
|
|
user = msg.reply_to_message.left_chat_participant
|
|
|
|
|
end
|
|
|
|
|
target.id = user.id
|
|
|
|
|
target.name = user.first_name
|
|
|
|
|
if user.last_name then
|
|
|
|
|
target.name = user.first_name .. ' ' .. user.last_name
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
target.name = 'User'
|
|
|
|
|
local input = get_word(msg.text, 2)
|
|
|
|
|
if not input then
|
|
|
|
|
target.err = 'Please provide a username or ID.'
|
|
|
|
|
else
|
|
|
|
|
target.id = resolve_username(input)
|
|
|
|
|
if target.id == nil then
|
|
|
|
|
target.err = 'Sorry, I do not recognize that username.'
|
|
|
|
|
elseif target.id == false then
|
|
|
|
|
target.err = 'Invalid ID or username.'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if target.id then
|
|
|
|
|
target.id_str = tostring(target.id)
|
|
|
|
|
target.rank = get_rank(target.id, msg.chat.id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return target
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local kick_user = function(target, chat)
|
|
|
|
|
|
|
|
|
|
target = tonumber(target)
|
|
|
|
|
chat = tostring(chat)
|
|
|
|
|
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[chat].grouptype == 'group' then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
tg:chat_del_user(tonumber(chat), target)
|
|
|
|
|
else
|
|
|
|
|
tg:channel_kick(chat, target)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local get_photo = function(chat)
|
|
|
|
|
|
|
|
|
|
local filename = tg:load_chat_photo(chat)
|
|
|
|
|
if filename:find('FAIL') then
|
|
|
|
|
print('Error downloading photo for group ' .. chat .. '.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
filename = filename:gsub('Saved to ', '')
|
|
|
|
|
return filename
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-23 12:15:48 +01:00
|
|
|
|
local get_desc = function(chat_id)
|
|
|
|
|
|
|
|
|
|
local group = database.administration[tostring(chat_id)]
|
|
|
|
|
local output
|
|
|
|
|
if group.link then
|
|
|
|
|
output = '*Welcome to* [' .. group.name .. '](' .. group.link .. ')*!*'
|
|
|
|
|
else
|
|
|
|
|
output = '*Welcome to* _' .. group.name .. '_*!*'
|
|
|
|
|
end
|
|
|
|
|
if group.motd then
|
|
|
|
|
output = output .. '\n\n*Message of the Day:*\n' .. group.motd
|
|
|
|
|
end
|
|
|
|
|
if group.rules then
|
2016-03-04 23:08:21 +01:00
|
|
|
|
output = output .. '\n\n*Rules:*'
|
2016-02-25 10:42:13 +01:00
|
|
|
|
for i,v in ipairs(group.rules) do
|
2016-03-04 23:08:21 +01:00
|
|
|
|
output = output .. '\n*' .. i .. '.* ' .. v
|
2016-02-25 10:42:13 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if group.flags then
|
2016-03-04 23:08:21 +01:00
|
|
|
|
output = output .. '\n\n*Flags:*\n'
|
2016-02-25 10:42:13 +01:00
|
|
|
|
for i = 1, #flags do
|
|
|
|
|
if group.flags[i] then
|
|
|
|
|
output = output .. '• ' .. flags[i].short .. '\n'
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-02-23 12:15:48 +01:00
|
|
|
|
end
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-20 11:07:20 +01:00
|
|
|
|
local commands = {
|
|
|
|
|
|
|
|
|
|
{ -- antisquig
|
|
|
|
|
triggers = {
|
|
|
|
|
'[\216-\219][\128-\191]', -- arabic
|
2016-02-25 10:42:13 +01:00
|
|
|
|
'', -- rtl
|
|
|
|
|
'', -- other rtl
|
2016-02-20 11:07:20 +01:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
privilege = 0,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
if get_rank(msg.from.id, msg.chat.id) > 1 then
|
|
|
|
|
return true
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if not database.administration[msg.chat.id_str].flags[2] == true then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
kick_user(msg.from.id, msg.chat.id)
|
|
|
|
|
sendMessage(msg.from.id, flags[2].kicked:gsub('GROUPNAME', msg.chat.title))
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- generic
|
|
|
|
|
triggers = {
|
|
|
|
|
''
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
privilege = 0,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
|
|
|
|
|
local rank = get_rank(msg.from.id, msg.chat.id)
|
2016-02-21 20:28:40 +01:00
|
|
|
|
local group = database.administration[msg.chat.id_str]
|
2016-02-20 11:07:20 +01:00
|
|
|
|
|
|
|
|
|
-- banned
|
|
|
|
|
if rank == 0 then
|
|
|
|
|
kick_user(msg.from.id, msg.chat.id)
|
|
|
|
|
sendMessage(msg.from.id, 'Sorry, you are banned from ' .. msg.chat.title .. '.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if rank < 2 then
|
|
|
|
|
|
|
|
|
|
-- antisquig Strict
|
|
|
|
|
if group.flags[3] == true then
|
2016-02-25 10:42:13 +01:00
|
|
|
|
if msg.from.name:match('[\216-\219][\128-\191]') or msg.from.name:match('') or msg.from.name:match('') then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
kick_user(msg.from.id, msg.chat.id)
|
|
|
|
|
sendMessage(msg.from.id, flags[3].kicked:gsub('GROUPNAME', msg.chat.title))
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if msg.new_chat_participant then
|
|
|
|
|
|
|
|
|
|
msg.new_chat_participant.name = msg.new_chat_participant.first_name
|
|
|
|
|
if msg.new_chat_participant.last_name then
|
|
|
|
|
msg.new_chat_participant.name = msg.new_chat_participant.first_name .. ' ' .. msg.new_chat_participant.last_name
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- banned
|
|
|
|
|
if get_rank(msg.new_chat_participant.id, msg.chat.id) == 0 then
|
|
|
|
|
kick_user(msg.new_chat_participant.id, msg.chat.id)
|
|
|
|
|
sendMessage(msg.new_chat_participant.id, 'Sorry, you are banned from ' .. msg.chat.title .. '.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- antisquig Strict
|
|
|
|
|
if group.flags[3] == true then
|
2016-02-25 10:42:13 +01:00
|
|
|
|
if msg.new_chat_participant.name:match('[\216-\219][\128-\191]') or msg.new_chat_participant.name:match('') or msg.new_chat_participant.name:match('') then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
kick_user(msg.new_chat_participant.id, msg.chat.id)
|
|
|
|
|
sendMessage(msg.new_chat_participant.id, flags[3].kicked:gsub('GROUPNAME', msg.chat.title))
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- antibot
|
2016-02-20 11:48:24 +01:00
|
|
|
|
if msg.new_chat_participant.username and msg.new_chat_participant.username:match('bot$') then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
if rank < 2 and group.flags[4] == true then
|
|
|
|
|
kick_user(msg.new_chat_participant.id, msg.chat.id)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
else
|
2016-02-23 12:15:48 +01:00
|
|
|
|
local output = get_desc(msg.chat.id)
|
2016-02-25 10:42:13 +01:00
|
|
|
|
sendMessage(msg.new_chat_participant.id, output, true, nil, true)
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
elseif msg.new_chat_title then
|
|
|
|
|
|
|
|
|
|
if rank < 3 then
|
|
|
|
|
tg:rename_chat(msg.chat.id, group.name)
|
|
|
|
|
else
|
|
|
|
|
group.name = msg.new_chat_title
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elseif msg.new_chat_photo then
|
|
|
|
|
|
|
|
|
|
if group.grouptype == 'group' then
|
|
|
|
|
if rank < 3 then
|
|
|
|
|
tg:chat_set_photo(msg.chat.id, group.photo)
|
|
|
|
|
else
|
|
|
|
|
group.photo = get_photo(msg.chat.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elseif msg.delete_chat_photo then
|
|
|
|
|
|
|
|
|
|
if group.grouptype == 'group' then
|
|
|
|
|
if rank < 3 then
|
|
|
|
|
tg:chat_set_photo(msg.chat.id, group.photo)
|
|
|
|
|
else
|
|
|
|
|
group.photo = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- groups
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/groups[@'..bot.username..']*$',
|
|
|
|
|
'^/glist[@'..bot.username..']*$'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'groups',
|
|
|
|
|
privilege = 1,
|
|
|
|
|
interior = false,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local output = ''
|
2016-02-21 20:28:40 +01:00
|
|
|
|
for k,v in pairs(database.administration) do
|
2016-02-20 11:07:20 +01:00
|
|
|
|
-- no "global" or unlisted groups
|
|
|
|
|
if tonumber(k) and not v.flags[1] then
|
|
|
|
|
if v.link then
|
|
|
|
|
output = output .. '• [' .. v.name .. '](' .. v.link .. ')\n'
|
|
|
|
|
else
|
|
|
|
|
output = output .. '• ' .. v.name .. '\n'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if output == '' then
|
|
|
|
|
output = 'There are currently no listed groups.'
|
|
|
|
|
else
|
|
|
|
|
output = '*Groups:*\n' .. output
|
|
|
|
|
end
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- ahelp
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/ahelp[@'..bot.username..']*$'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'ahelp',
|
|
|
|
|
privilege = 1,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
2016-02-25 10:42:13 +01:00
|
|
|
|
local rank = get_rank(msg.from.id, msg.chat.id)
|
|
|
|
|
local output = '*Commands for ' .. ranks[rank] .. ':*\n'
|
|
|
|
|
for i = 1, rank do
|
|
|
|
|
for ind, val in ipairs(database.administration.global.help[i]) do
|
|
|
|
|
output = output .. '• /' .. val .. '\n'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if sendMessage(msg.from.id, output, true, nil, true) then
|
|
|
|
|
sendReply(msg, 'I have sent you the requested information in a private message.')
|
|
|
|
|
else
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- alist
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/alist[@'..bot.username..']*$',
|
|
|
|
|
'^/ops[@'..bot.username..']*$',
|
|
|
|
|
'^/oplist[@'..bot.username..']*$'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'ops',
|
|
|
|
|
privilege = 1,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local modstring = ''
|
2016-02-21 20:28:40 +01:00
|
|
|
|
for k,v in pairs(database.administration[msg.chat.id_str].mods) do
|
2016-02-20 11:07:20 +01:00
|
|
|
|
modstring = modstring .. '• ' .. v .. ' (' .. k .. ')\n'
|
|
|
|
|
end
|
|
|
|
|
if modstring ~= '' then
|
|
|
|
|
modstring = '*Moderators for* _' .. msg.chat.title .. '_ *:*\n' .. modstring
|
|
|
|
|
end
|
|
|
|
|
local govstring = ''
|
2016-02-21 20:28:40 +01:00
|
|
|
|
for k,v in pairs(database.administration[msg.chat.id_str].govs) do
|
2016-02-20 11:07:20 +01:00
|
|
|
|
govstring = govstring .. '• ' .. v .. ' (' .. k .. ')\n'
|
|
|
|
|
end
|
|
|
|
|
if govstring ~= '' then
|
|
|
|
|
govstring = '*Governors for* _' .. msg.chat.title .. '_ *:*\n' .. govstring
|
|
|
|
|
end
|
|
|
|
|
local adminstring = '*Administrators:*\n• ' .. config.admin_name .. ' (' .. config.admin .. ')\n'
|
2016-02-21 20:28:40 +01:00
|
|
|
|
for k,v in pairs(database.administration.global.admins) do
|
2016-02-20 11:07:20 +01:00
|
|
|
|
adminstring = adminstring .. '• ' .. v .. ' (' .. k .. ')\n'
|
|
|
|
|
end
|
|
|
|
|
local output = modstring .. govstring .. adminstring
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-23 12:15:48 +01:00
|
|
|
|
{ -- desc
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/desc[@'..bot.username..']*$',
|
|
|
|
|
'^/description[@'..bot.username..']*$'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'description',
|
|
|
|
|
privilege = 1,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local output = get_desc(msg.chat.id)
|
2016-02-25 10:42:13 +01:00
|
|
|
|
if sendMessage(msg.from.id, output, true, nil, true) then
|
|
|
|
|
sendReply(msg, 'I have sent you the requested information in a private message.')
|
|
|
|
|
else
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
2016-02-23 12:15:48 +01:00
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-20 11:07:20 +01:00
|
|
|
|
{ -- rules
|
|
|
|
|
triggers = {
|
2016-02-23 12:15:48 +01:00
|
|
|
|
'^/rules[@'..bot.username..']*$'
|
2016-02-20 11:07:20 +01:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'rules',
|
|
|
|
|
privilege = 1,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local output = 'No rules have been set for ' .. msg.chat.title .. '.'
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str].rules then
|
2016-02-25 10:42:13 +01:00
|
|
|
|
output = '*Rules for* _' .. msg.chat.title .. '_ *:*\n'
|
|
|
|
|
for i,v in ipairs(database.administration[msg.chat.id_str].rules) do
|
|
|
|
|
output = output .. '*' .. i .. '.* ' .. v .. '\n'
|
|
|
|
|
end
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- motd
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/motd[@'..bot.username..']*',
|
|
|
|
|
'^/description[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'motd',
|
|
|
|
|
privilege = 1,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local output = 'No MOTD has been set for ' .. msg.chat.title .. '.'
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str].motd then
|
|
|
|
|
output = '*MOTD for* _' .. msg.chat.title .. '_ *:*\n' .. database.administration[msg.chat.id_str].motd
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- link
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/link[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'link',
|
|
|
|
|
privilege = 1,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local output = 'No link has been set for ' .. msg.chat.title .. '.'
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str].link then
|
|
|
|
|
output = '[' .. msg.chat.title .. '](' .. database.administration[msg.chat.id_str].link .. ')'
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- kickme
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/leave[@'..bot.username..']*',
|
|
|
|
|
'^/kickme[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'leave',
|
|
|
|
|
privilege = 1,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
if get_rank(msg.from.id) == 5 then
|
|
|
|
|
local output = 'I can\'t let you do that, ' .. msg.from.first_name .. '.'
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
elseif msg.chat.type == 'supergroup' then
|
|
|
|
|
local output = 'Leave this group manually or you will be unable to rejoin.'
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
else
|
|
|
|
|
kick_user(msg.from.id, msg.chat.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- kick
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/kick[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'kick <user>',
|
|
|
|
|
privilege = 2,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.err then
|
|
|
|
|
sendReply(msg, target.err)
|
|
|
|
|
return
|
|
|
|
|
elseif target.rank > 1 then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is too privileged to be kicked.')
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
kick_user(target.id, msg.chat.id)
|
|
|
|
|
sendMessage(msg.chat.id, target.name .. ' has been kicked.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- ban
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/ban[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'ban <user>',
|
|
|
|
|
privilege = 2,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.err then
|
|
|
|
|
sendReply(msg, target.err)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if target.rank > 1 then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is too privileged to be banned.')
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str].bans[target.id_str] then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is already banned.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
kick_user(target.id, msg.chat.id)
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].bans[target.id_str] = true
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendMessage(msg.chat.id, target.name .. ' has been banned.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- unban
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/unban[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'unban <user>',
|
|
|
|
|
privilege = 2,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.err then
|
|
|
|
|
sendReply(msg, target.err)
|
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if not database.administration[msg.chat.id_str].bans[target.id_str] then
|
2016-02-23 12:15:48 +01:00
|
|
|
|
if database.blacklist[target.id_str] then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is globally banned.')
|
2016-02-20 11:07:20 +01:00
|
|
|
|
else
|
|
|
|
|
sendReply(msg, target.name .. ' is not banned.')
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].bans[target.id_str] = nil
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendMessage(msg.chat.id, target.name .. ' has been unbanned.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-25 10:42:13 +01:00
|
|
|
|
{ -- changerule
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/changerule',
|
|
|
|
|
'^/changerule@' .. bot.username
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'changerule <i> <newrule>',
|
|
|
|
|
privilege = 3,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local usage = 'usage: `/changerule <i> <newrule>`\n`/changerule <i> -- `deletes.'
|
|
|
|
|
local input = msg.text:input()
|
|
|
|
|
if not input then
|
|
|
|
|
sendMessage(msg.chat.id, usage, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local rule_num = input:match('^%d+')
|
|
|
|
|
if not rule_num then
|
|
|
|
|
local output = 'Please specify which rule you want to change.\n' .. usage
|
|
|
|
|
sendMessage(msg.chat.id, output, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
rule_num = tonumber(rule_num)
|
|
|
|
|
local rule_new = input:input()
|
|
|
|
|
if not rule_new then
|
|
|
|
|
local output = 'Please specify the new rule.\n' .. usage
|
|
|
|
|
sendMessage(msg.chat.id, output, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if not database.administration[msg.chat.id_str].rules then
|
|
|
|
|
local output = 'Sorry, there are no rules to change. Please use /setrules.\n' .. usage
|
|
|
|
|
sendMessage(msg.chat.id, output, true, msg.message_id, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if not database.administration[msg.chat.id_str].rules[rule_num] then
|
|
|
|
|
rule_num = #database.administration[msg.chat.id_str].rules + 1
|
|
|
|
|
end
|
|
|
|
|
if rule_new == '--' or rule_new == '—' then
|
|
|
|
|
if database.administration[msg.chat.id_str].rules[rule_num] then
|
|
|
|
|
table.remove(database.administration[msg.chat.id_str].rules, rule_num)
|
|
|
|
|
sendReply(msg, 'That rule has been deleted.')
|
|
|
|
|
else
|
|
|
|
|
sendReply(msg, 'There is no rule with that number.')
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
database.administration[msg.chat.id_str].rules[rule_num] = rule_new
|
|
|
|
|
local output = '*' .. rule_num .. '*. ' .. rule_new
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-20 11:07:20 +01:00
|
|
|
|
{ -- setrules
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/setrules[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'setrules <rule1> \\n \\[rule2] ...',
|
|
|
|
|
privilege = 3,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local input = msg.text:match('^/setrules[@'..bot.username..']*(.+)')
|
|
|
|
|
if not input then
|
|
|
|
|
sendReply(msg, '/setrules [rule]\n<rule>\n[rule]\n...')
|
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-25 10:42:13 +01:00
|
|
|
|
database.administration[msg.chat.id_str].rules = {}
|
2016-02-20 11:07:20 +01:00
|
|
|
|
input = input:trim() .. '\n'
|
2016-02-25 10:42:13 +01:00
|
|
|
|
local output = '*Rules for* _' .. msg.chat.title .. '_ *:*\n'
|
|
|
|
|
local i = 1
|
|
|
|
|
for l in input:gmatch('(.-)\n') do
|
|
|
|
|
output = output .. '*' .. i .. '.* ' .. l .. '\n'
|
2016-02-20 11:07:20 +01:00
|
|
|
|
i = i + 1
|
2016-02-25 10:42:13 +01:00
|
|
|
|
table.insert(database.administration[msg.chat.id_str].rules, l:trim())
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- setmotd
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/setmotd[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'setmotd <motd>',
|
|
|
|
|
privilege = 3,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local input = msg.text:input()
|
|
|
|
|
if not input then
|
|
|
|
|
sendReply(msg, '/' .. command)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
input = input:trim()
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].motd = input
|
2016-02-20 11:07:20 +01:00
|
|
|
|
local output = '*MOTD for* _' .. msg.chat.title .. '_ *:*\n' .. input
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- setlink
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/setlink[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'setlink <link>',
|
|
|
|
|
privilege = 3,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local input = msg.text:input()
|
|
|
|
|
if not input then
|
|
|
|
|
sendReply(msg, '/' .. command)
|
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].link = input
|
2016-02-20 11:07:20 +01:00
|
|
|
|
local output = '[' .. msg.chat.title .. '](' .. input .. ')'
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- flags
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/flags?[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'flag <i>',
|
|
|
|
|
privilege = 3,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local input = msg.text:input()
|
|
|
|
|
if input then
|
|
|
|
|
input = get_word(input, 1)
|
|
|
|
|
input = tonumber(input)
|
|
|
|
|
if not input or not flags[input] then input = false end
|
|
|
|
|
end
|
|
|
|
|
if not input then
|
|
|
|
|
local output = '*Flags for* _' .. msg.chat.title .. '_ *:*\n'
|
|
|
|
|
for i,v in ipairs(flags) do
|
2016-02-21 20:28:40 +01:00
|
|
|
|
local status = database.administration[msg.chat.id_str].flags[i] or false
|
2016-02-25 10:42:13 +01:00
|
|
|
|
output = output .. '`[' .. i .. ']` *' .. v.name .. '*` = ' .. tostring(status) .. '`\n• ' .. v.desc .. '\n'
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
sendMessage(msg.chat.id, output, true, nil, true)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local output
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str].flags[input] == true then
|
|
|
|
|
database.administration[msg.chat.id_str].flags[input] = false
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, flags[input].disabled)
|
|
|
|
|
else
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].flags[input] = true
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, flags[input].enabled)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- mod
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/mod[@'..bot.username..']*$'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'mod <user>',
|
|
|
|
|
privilege = 3,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
if not msg.reply_to_message then
|
|
|
|
|
sendReply(msg, 'This command must be run via reply.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.rank > 1 then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is already a moderator or greater.')
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
tg:channel_set_admin(msg.chat.id, target, 1)
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].mods[target.id_str] = target.name
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is now a moderator.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- demod
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/demod[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'demod <user>',
|
|
|
|
|
privilege = 3,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.err then
|
|
|
|
|
sendReply(msg, target.err)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if target.rank ~= 2 then
|
|
|
|
|
sendReply(msg, target.name .. ' is not a moderator.')
|
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
tg:channel_set_admin(msg.chat.id, target, 0)
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is no longer a moderator.')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- gov
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/gov[@'..bot.username..']*$'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'gov <user>',
|
|
|
|
|
privilege = 4,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
if not msg.reply_to_message then
|
|
|
|
|
sendReply(msg, 'This command must be run via reply.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.rank > 2 then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is already a governor or greater.')
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return
|
|
|
|
|
elseif target.rank == 2 then
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
tg:channel_set_admin(msg.chat.id, target, 1)
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].govs[target.id_str] = target.name
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is now a governor.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
2016-03-04 23:08:21 +01:00
|
|
|
|
{ -- degov
|
2016-02-20 11:07:20 +01:00
|
|
|
|
triggers = {
|
|
|
|
|
'^/degov[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'degov <user>',
|
|
|
|
|
privilege = 4,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.err then
|
|
|
|
|
sendReply(msg, target.err)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if target.rank ~= 3 then
|
|
|
|
|
sendReply(msg, target.name .. ' is not a governor.')
|
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
tg:channel_set_admin(msg.chat.id, target, 0)
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].govs[target.id_str] = nil
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is no longer a governor.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- hammer
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/hammer[@'..bot.username..']*',
|
|
|
|
|
'^/banall[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'hammer <user>',
|
|
|
|
|
privilege = 4,
|
|
|
|
|
interior = false,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.err then
|
|
|
|
|
sendReply(msg, target.err)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
if target.rank > 3 then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is too privileged to be globally banned.')
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-23 12:15:48 +01:00
|
|
|
|
if database.blacklist[target.id_str] then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is already globally banned.')
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
for k,v in pairs(database.administration) do
|
2016-02-20 11:07:20 +01:00
|
|
|
|
if tonumber(k) then
|
|
|
|
|
kick_user(target.id, k)
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-02-23 12:15:48 +01:00
|
|
|
|
database.blacklist[target.id_str] = true
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, target.name .. ' has been globally banned.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- unhammer
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/unhammer[@'..bot.username..']*',
|
|
|
|
|
'^/unbanall[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'unhammer <user>',
|
|
|
|
|
privilege = 4,
|
|
|
|
|
interior = false,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.err then
|
|
|
|
|
sendReply(msg, target.err)
|
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-23 12:15:48 +01:00
|
|
|
|
if not database.blacklist[target.id_str] then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is not globally banned.')
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-23 12:15:48 +01:00
|
|
|
|
database.blacklist[target.id_str] = nil
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, target.name .. ' has been globally unbanned.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- admin
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/admin[@'..bot.username..']*$'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'admin <user>',
|
|
|
|
|
privilege = 5,
|
|
|
|
|
interior = false,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
if not msg.reply_to_message then
|
|
|
|
|
sendReply(msg, 'This command must be run via reply.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.rank > 3 then
|
2016-02-27 04:06:38 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is already an administrator or greater.')
|
2016-02-20 11:07:20 +01:00
|
|
|
|
return
|
|
|
|
|
elseif target.rank == 2 then
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
2016-02-20 11:07:20 +01:00
|
|
|
|
elseif target.rank == 3 then
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].govs[target.id_str] = nil
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration.global.admins[target.id_str] = target.name
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is now an administrator.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- deadmin
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/deadmin[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'deadmin <user>',
|
|
|
|
|
privilege = 5,
|
|
|
|
|
interior = false,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local target = get_target(msg)
|
|
|
|
|
if target.rank ~= 4 then
|
|
|
|
|
sendReply(msg, target.name .. ' is not an administrator.')
|
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration.global.admins[target.id_str] = nil
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, target.name .. ' is no longer an administrator.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- gadd
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/gadd[@'..bot.username..']*$'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'gadd',
|
|
|
|
|
privilege = 5,
|
|
|
|
|
interior = false,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if database.administration[msg.chat.id_str] then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
sendReply(msg, 'I am already administrating this group.')
|
|
|
|
|
return
|
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str] = {
|
2016-02-20 11:07:20 +01:00
|
|
|
|
mods = {},
|
|
|
|
|
govs = {},
|
|
|
|
|
bans = {},
|
|
|
|
|
flags = {},
|
|
|
|
|
grouptype = msg.chat.type,
|
|
|
|
|
name = msg.chat.title,
|
|
|
|
|
founded = os.time()
|
|
|
|
|
}
|
|
|
|
|
if msg.chat.type == 'group' then
|
2016-02-21 20:28:40 +01:00
|
|
|
|
database.administration[msg.chat.id_str].photo = get_photo(msg.chat.id)
|
|
|
|
|
database.administration[msg.chat.id_str].link = tg:export_chat_link(msg.chat.id)
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
sendReply(msg, 'I am now administrating this group.')
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- grem
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/grem[@'..bot.username..']*',
|
|
|
|
|
'^/gremove[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'gremove \\[chat]',
|
|
|
|
|
privilege = 5,
|
|
|
|
|
interior = true,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local input = msg.text:input()
|
2016-02-27 04:06:38 +01:00
|
|
|
|
if input then
|
|
|
|
|
if database.administration[input] then
|
|
|
|
|
database.administration[input] = nil
|
|
|
|
|
sendReply(msg, 'I am no longer administrating that group.')
|
|
|
|
|
else
|
|
|
|
|
sendReply(msg, 'I do not administrate that group.')
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if database.administration[msg.chat.id_str] then
|
|
|
|
|
database.administration[msg.chat.id_str] = nil
|
|
|
|
|
sendReply(msg, 'I am no longer administrating this group.')
|
|
|
|
|
else
|
|
|
|
|
sendReply(msg, 'I do not administrate this group.')
|
|
|
|
|
end
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ -- broadcast
|
|
|
|
|
triggers = {
|
|
|
|
|
'^/broadcast[@'..bot.username..']*'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
command = 'broadcast <message>',
|
|
|
|
|
privilege = 5,
|
|
|
|
|
interior = false,
|
|
|
|
|
|
|
|
|
|
action = function(msg)
|
|
|
|
|
local input = msg.text:input()
|
|
|
|
|
if not input then
|
|
|
|
|
sendReply(msg, 'Give me something to broadcast.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
input = '*Admin Broadcast:*\n' .. input
|
2016-02-21 20:28:40 +01:00
|
|
|
|
for k,v in pairs(database.administration) do
|
2016-02-20 11:07:20 +01:00
|
|
|
|
if tonumber(k) then
|
|
|
|
|
sendMessage(k, input, true, nil, true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 12:15:48 +01:00
|
|
|
|
-- Generate trigger table.
|
2016-02-20 11:07:20 +01:00
|
|
|
|
local triggers = {}
|
|
|
|
|
for i,v in ipairs(commands) do
|
2016-03-04 23:08:21 +01:00
|
|
|
|
for ind, val in ipairs(v.triggers) do
|
2016-02-20 11:07:20 +01:00
|
|
|
|
table.insert(triggers, val)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-25 10:42:13 +01:00
|
|
|
|
database.administration.global.help = {}
|
2016-03-04 23:08:21 +01:00
|
|
|
|
for i,v in ipairs(ranks) do
|
2016-02-25 10:42:13 +01:00
|
|
|
|
database.administration.global.help[i] = {}
|
|
|
|
|
end
|
|
|
|
|
for i,v in ipairs(commands) do
|
|
|
|
|
if v.command then
|
|
|
|
|
table.insert(database.administration.global.help[v.privilege], v.command)
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2016-02-25 10:42:13 +01:00
|
|
|
|
|
2016-02-20 11:07:20 +01:00
|
|
|
|
|
2016-02-27 04:06:38 +01:00
|
|
|
|
local action = function(msg)
|
2016-02-20 11:07:20 +01:00
|
|
|
|
for i,v in ipairs(commands) do
|
|
|
|
|
for key,val in pairs(v.triggers) do
|
|
|
|
|
if msg.text_lower:match(val) then
|
2016-02-21 20:28:40 +01:00
|
|
|
|
if v.interior and not database.administration[msg.chat.id_str] then
|
2016-02-20 11:07:20 +01:00
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
if msg.chat.type ~= 'private' and get_rank(msg.from.id, msg.chat.id) < v.privilege then
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
local res = v.action(msg)
|
|
|
|
|
if res ~= true then
|
|
|
|
|
return res
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local cron = function()
|
2016-03-05 19:15:53 +01:00
|
|
|
|
tg = sender(localhost, config.cli_port)
|
2016-02-20 11:07:20 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local command = 'groups'
|
|
|
|
|
local doc = '`Returns a list of administrated groups.\nUse /ahelp for more administrative commands.`'
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
action = action,
|
|
|
|
|
triggers = triggers,
|
|
|
|
|
cron = cron,
|
|
|
|
|
doc = doc,
|
|
|
|
|
command = command
|
|
|
|
|
}
|