From 68fed25b495b77bc50313b6471fa93301c116c84 Mon Sep 17 00:00:00 2001 From: yago Date: Sun, 4 Jan 2015 14:22:28 +0100 Subject: [PATCH] can define if command is for privileged users only --- bot/bot.lua | 22 ++++++++++++++-------- plugins/plugins.lua | 3 ++- plugins/stats.lua | 4 +--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index 36171fc..a0deba0 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -86,16 +86,22 @@ function do_action(msg) -- print("Trying", text, "against", pattern) matches = { string.match(text, pattern) } if matches[1] then - print(" matches",pattern) + print(" matches", pattern) if desc.run ~= nil then - result = desc.run(msg, matches) - -- print(" sending", result) - if (result) then - local result2 = do_lex(msg, result) - if (result2 == nil) then - result2 = result + -- 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) + -- print(" sending", result) + if (result) then + local result2 = do_lex(msg, result) + if (result2 == nil) then + result2 = result + end + _send_msg(receiver, result2) end - _send_msg(receiver, result2) end end end diff --git a/plugins/plugins.lua b/plugins/plugins.lua index 157f434..63410f7 100644 --- a/plugins/plugins.lua +++ b/plugins/plugins.lua @@ -106,5 +106,6 @@ return { "^!plugins? (disable) (.*)$", "^!plugins? (reload)$" }, - run = run + run = run, + privileged = true } \ No newline at end of file diff --git a/plugins/stats.lua b/plugins/stats.lua index 320f8c5..70ce32e 100644 --- a/plugins/stats.lua +++ b/plugins/stats.lua @@ -12,7 +12,7 @@ function update_user_stats(msg) local from_id = tostring(msg.from.id) local to_id = tostring(msg.to.id) 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. local user_last_name = msg.from.last_name local user_print_name = msg.from.print_name @@ -79,9 +79,7 @@ local function run(msg, matches) else print ("update stats") update_user_stats(msg) - print(socket.gettime()) save_stats() - print(socket.gettime()) end end