From 944ee5b356f3065d9829a01d2d8605e52e4bb620 Mon Sep 17 00:00:00 2001 From: yago Date: Mon, 2 Feb 2015 23:00:08 +0100 Subject: [PATCH] saves and print user id --- plugins/stats.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/stats.lua b/plugins/stats.lua index 131f94c..7ddf803 100644 --- a/plugins/stats.lua +++ b/plugins/stats.lua @@ -23,6 +23,7 @@ function update_user_stats(msg) if _stats[to_id][from_id] == nil then print ('New stats key from_id: '..to_id) _stats[to_id][from_id] = { + user_id = from_id, name = user_name, last_name = user_last_name, print_name = user_print_name, @@ -32,7 +33,7 @@ function update_user_stats(msg) print ('Updated '..to_id..' '..from_id) local actual_num = _stats[to_id][from_id].msg_num _stats[to_id][from_id].msg_num = actual_num + 1 - -- And update last_name + _stats[to_id][from_id].user_id = from_id _stats[to_id][from_id].last_name = user_last_name end end @@ -60,24 +61,28 @@ end local function get_stats_status( msg ) -- vardump(stats) local text = "" - local to_id = tostring(msg.to.id) + local to_id = tostring(msg.to.id) local rank = {} for id, user in pairs(_stats[to_id]) do table.insert(rank, user) end + table.sort(rank, function(a, b) if a.msg_num and b.msg_num then return a.msg_num > b.msg_num end end ) + for id, user in pairs(rank) do + -- Previous versions didn't save that + user_id = user.user_id or '' print(">> ", id, user.name) if user.last_name == nil then - text = text..user.name..": "..user.msg_num.."\n" + text = text..user.name.." ["..user_id.."]: "..user.msg_num.."\n" else - text = text..user.name.." "..user.last_name..": "..user.msg_num.."\n" + text = text..user.name.." "..user.last_name.." ["..user_id.."]: "..user.msg_num.."\n" end end print("usuarios: "..text)