administration.lua:
version 1.3 reply-based commands will now work as you would expect when replying to add/remove messages some information messages have been changed
This commit is contained in:
parent
f102eeb135
commit
664c2296ad
@ -1,6 +1,6 @@
|
|||||||
--[[
|
--[[
|
||||||
administration.lua
|
administration.lua
|
||||||
Version 1.2
|
Version 1.3
|
||||||
Part of the otouto project.
|
Part of the otouto project.
|
||||||
© 2016 topkecleon <drew@otou.to>
|
© 2016 topkecleon <drew@otou.to>
|
||||||
GNU General Public License, version 2
|
GNU General Public License, version 2
|
||||||
@ -53,7 +53,7 @@ for k,v in pairs(database.administration) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
local sender = dofile('lua-tg/sender.lua')
|
local sender = dofile('lua-tg/sender.lua')
|
||||||
tg = sender(localhost, config.cli_port)
|
local tg = sender(localhost, config.cli_port)
|
||||||
local last_admin_cron = os.date('%M', os.time())
|
local last_admin_cron = os.date('%M', os.time())
|
||||||
|
|
||||||
local flags = {
|
local flags = {
|
||||||
@ -135,10 +135,16 @@ local get_target = function(msg)
|
|||||||
|
|
||||||
local target = {}
|
local target = {}
|
||||||
if msg.reply_to_message then
|
if msg.reply_to_message then
|
||||||
target.id = msg.reply_to_message.from.id
|
local user = msg.reply_to_message.from
|
||||||
target.name = msg.reply_to_message.from.first_name
|
if msg.reply_to_message.new_chat_participant then
|
||||||
if msg.reply_to_message.from.last_name then
|
user = msg.reply_to_message.new_chat_participant
|
||||||
target.name = target.name .. ' ' .. msg.reply_to_message.from.last_name
|
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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
target.name = 'User'
|
target.name = 'User'
|
||||||
@ -557,7 +563,7 @@ local commands = {
|
|||||||
sendReply(msg, target.err)
|
sendReply(msg, target.err)
|
||||||
return
|
return
|
||||||
elseif target.rank > 1 then
|
elseif target.rank > 1 then
|
||||||
sendReply(msg, target.name .. ' cannot be kicked: Too privileged.')
|
sendReply(msg, target.name .. ' is too privileged to be kicked.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
kick_user(target.id, msg.chat.id)
|
kick_user(target.id, msg.chat.id)
|
||||||
@ -581,7 +587,7 @@ local commands = {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
if target.rank > 1 then
|
if target.rank > 1 then
|
||||||
sendReply(msg, target.name .. ' cannot be banned: Too privileged.')
|
sendReply(msg, target.name .. ' is too privileged to be banned.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if database.administration[msg.chat.id_str].bans[target.id_str] then
|
if database.administration[msg.chat.id_str].bans[target.id_str] then
|
||||||
@ -611,7 +617,7 @@ local commands = {
|
|||||||
end
|
end
|
||||||
if not database.administration[msg.chat.id_str].bans[target.id_str] then
|
if not database.administration[msg.chat.id_str].bans[target.id_str] then
|
||||||
if database.blacklist[target.id_str] then
|
if database.blacklist[target.id_str] then
|
||||||
sendReply(msg, target.name .. ' is banned globally.')
|
sendReply(msg, target.name .. ' is globally banned.')
|
||||||
else
|
else
|
||||||
sendReply(msg, target.name .. ' is not banned.')
|
sendReply(msg, target.name .. ' is not banned.')
|
||||||
end
|
end
|
||||||
@ -798,7 +804,7 @@ local commands = {
|
|||||||
end
|
end
|
||||||
local target = get_target(msg)
|
local target = get_target(msg)
|
||||||
if target.rank > 1 then
|
if target.rank > 1 then
|
||||||
sendReply(msg, target.name .. ' cannot be promoted: Already privileged.')
|
sendReply(msg, target.name .. ' is already a moderator or greater.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
||||||
@ -853,7 +859,7 @@ local commands = {
|
|||||||
end
|
end
|
||||||
local target = get_target(msg)
|
local target = get_target(msg)
|
||||||
if target.rank > 2 then
|
if target.rank > 2 then
|
||||||
sendReply(msg, target.name .. ' cannot be promoted: Already privileged.')
|
sendReply(msg, target.name .. ' is already a governor or greater.')
|
||||||
return
|
return
|
||||||
elseif target.rank == 2 then
|
elseif target.rank == 2 then
|
||||||
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
||||||
@ -910,11 +916,11 @@ local commands = {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
if target.rank > 3 then
|
if target.rank > 3 then
|
||||||
sendReply(msg, target.name .. ' cannot be banned: Too privileged.')
|
sendReply(msg, target.name .. ' is too privileged to be globally banned.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if database.blacklist[target.id_str] then
|
if database.blacklist[target.id_str] then
|
||||||
sendReply(msg, target.name .. ' is already banned globally.')
|
sendReply(msg, target.name .. ' is already globally banned.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for k,v in pairs(database.administration) do
|
for k,v in pairs(database.administration) do
|
||||||
@ -944,7 +950,7 @@ local commands = {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not database.blacklist[target.id_str] then
|
if not database.blacklist[target.id_str] then
|
||||||
sendReply(msg, target.name .. ' is not banned globally.')
|
sendReply(msg, target.name .. ' is not globally banned.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
database.blacklist[target.id_str] = nil
|
database.blacklist[target.id_str] = nil
|
||||||
@ -968,7 +974,7 @@ local commands = {
|
|||||||
end
|
end
|
||||||
local target = get_target(msg)
|
local target = get_target(msg)
|
||||||
if target.rank > 3 then
|
if target.rank > 3 then
|
||||||
sendReply(msg, target.name .. ' cannot be promoted: Already privileged.')
|
sendReply(msg, target.name .. ' is already an administrator or greater.')
|
||||||
return
|
return
|
||||||
elseif target.rank == 2 then
|
elseif target.rank == 2 then
|
||||||
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
||||||
@ -1043,11 +1049,21 @@ local commands = {
|
|||||||
|
|
||||||
action = function(msg)
|
action = function(msg)
|
||||||
local input = msg.text:input()
|
local input = msg.text:input()
|
||||||
if not input then
|
if input then
|
||||||
input = msg.chat.id_str
|
if database.administration[input] then
|
||||||
end
|
|
||||||
database.administration[input] = nil
|
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.')
|
sendReply(msg, 'I am no longer administrating this group.')
|
||||||
|
else
|
||||||
|
sendReply(msg, 'I do not administrate this group.')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1096,7 +1112,7 @@ for i,v in ipairs(commands) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local action = function(msg) -- wee nesting
|
local action = function(msg)
|
||||||
for i,v in ipairs(commands) do
|
for i,v in ipairs(commands) do
|
||||||
for key,val in pairs(v.triggers) do
|
for key,val in pairs(v.triggers) do
|
||||||
if msg.text_lower:match(val) then
|
if msg.text_lower:match(val) then
|
||||||
|
Reference in New Issue
Block a user