can define if command is for privileged users only

This commit is contained in:
yago 2015-01-04 14:22:28 +01:00
parent e22d2670fd
commit 68fed25b49
3 changed files with 17 additions and 12 deletions

View File

@ -86,8 +86,13 @@ function do_action(msg)
-- print("Trying", text, "against", pattern) -- print("Trying", text, "against", pattern)
matches = { string.match(text, pattern) } matches = { string.match(text, pattern) }
if matches[1] then if matches[1] then
print(" matches",pattern) print(" matches", pattern)
if desc.run ~= nil then if desc.run ~= nil then
-- If plugin is for privileged user
if desc.privileged and not is_sudo(msg) then
local text = 'This plugin requires privileged user'
send_msg(receiver, text, ok_cb, false)
else
result = desc.run(msg, matches) result = desc.run(msg, matches)
-- print(" sending", result) -- print(" sending", result)
if (result) then if (result) then
@ -101,6 +106,7 @@ function do_action(msg)
end end
end end
end end
end
end end
-- If text is longer than 4096 chars, send multiple msg. -- If text is longer than 4096 chars, send multiple msg.

View File

@ -106,5 +106,6 @@ return {
"^!plugins? (disable) (.*)$", "^!plugins? (disable) (.*)$",
"^!plugins? (reload)$" "^!plugins? (reload)$"
}, },
run = run run = run,
privileged = true
} }

View File

@ -12,7 +12,7 @@ function update_user_stats(msg)
local from_id = tostring(msg.from.id) local from_id = tostring(msg.from.id)
local to_id = tostring(msg.to.id) local to_id = tostring(msg.to.id)
local user_name = get_name(msg) local user_name = get_name(msg)
print ('New message from '..user_name..'['..to_id..']'..'['..from_id..']') print ('New message from '..user_name..'['..from_id..']'..' to '..to_id)
-- If last name is nil dont save last_name. -- If last name is nil dont save last_name.
local user_last_name = msg.from.last_name local user_last_name = msg.from.last_name
local user_print_name = msg.from.print_name local user_print_name = msg.from.print_name
@ -79,9 +79,7 @@ local function run(msg, matches)
else else
print ("update stats") print ("update stats")
update_user_stats(msg) update_user_stats(msg)
print(socket.gettime())
save_stats() save_stats()
print(socket.gettime())
end end
end end