!stats command

This commit is contained in:
yago 2014-11-22 20:17:33 +01:00
parent e19a0b7e6b
commit a1f5c7c9fa
2 changed files with 21 additions and 8 deletions

View File

@ -3,7 +3,7 @@
URL = require("socket.url") URL = require("socket.url")
json = (loadfile "./bot/JSON.lua")() json = (loadfile "./bot/JSON.lua")()
VERSION = 'v0.7.1' VERSION = 'v0.7.2'
-- taken from http://stackoverflow.com/a/11130774/3163199 -- taken from http://stackoverflow.com/a/11130774/3163199
function scandir(directory) function scandir(directory)
@ -16,7 +16,7 @@
end end
function on_msg_receive (msg) function on_msg_receive (msg)
vardump(msg) --vardump(msg)
if msg_valid(msg) == false then if msg_valid(msg) == false then
return return
@ -226,16 +226,15 @@
end end
function update_user_stats(msg) function update_user_stats(msg)
-- Save user to users table -- Save user to _users table
if (users[msg.from.id] == nil) then if (_users[msg.from.id] == nil) then
users[msg.from.id] = { _users[msg.from.id] = {
name = get_name(msg), name = get_name(msg),
msg_num = 1 msg_num = 1
} }
else else
users[msg.from.id].msg_num = users[msg.from.id].msg_num + 1 _users[msg.from.id].msg_num = _users[msg.from.id].msg_num + 1
end end
print (msg.from.print_name .. ": "..users[msg.from.id].msg_num)
end end
function get_receiver(msg) function get_receiver(msg)
@ -275,7 +274,7 @@
-- Start and load values -- Start and load values
config = load_config() config = load_config()
our_id = 0 our_id = 0
users = {} _users = {}
now = os.time() now = os.time()
-- load plugins -- load plugins

14
plugins/stats.lua Normal file
View File

@ -0,0 +1,14 @@
function run(msg, matches)
local text = ""
for id, user in pairs(_users) do
text = text..user.name..": "..user.msg_num.."\n"
end
return text
end
return {
description = "Numer of messages by user",
usage = "!stats",
patterns = {"^!stats"},
run = run
}