saves and print user id

This commit is contained in:
yago 2015-02-02 23:00:08 +01:00
parent 792209c607
commit 944ee5b356

View File

@ -23,6 +23,7 @@ function update_user_stats(msg)
if _stats[to_id][from_id] == nil then if _stats[to_id][from_id] == nil then
print ('New stats key from_id: '..to_id) print ('New stats key from_id: '..to_id)
_stats[to_id][from_id] = { _stats[to_id][from_id] = {
user_id = from_id,
name = user_name, name = user_name,
last_name = user_last_name, last_name = user_last_name,
print_name = user_print_name, print_name = user_print_name,
@ -32,7 +33,7 @@ function update_user_stats(msg)
print ('Updated '..to_id..' '..from_id) print ('Updated '..to_id..' '..from_id)
local actual_num = _stats[to_id][from_id].msg_num local actual_num = _stats[to_id][from_id].msg_num
_stats[to_id][from_id].msg_num = actual_num + 1 _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 _stats[to_id][from_id].last_name = user_last_name
end end
end end
@ -60,24 +61,28 @@ end
local function get_stats_status( msg ) local function get_stats_status( msg )
-- vardump(stats) -- vardump(stats)
local text = "" local text = ""
local to_id = tostring(msg.to.id) local to_id = tostring(msg.to.id)
local rank = {} local rank = {}
for id, user in pairs(_stats[to_id]) do for id, user in pairs(_stats[to_id]) do
table.insert(rank, user) table.insert(rank, user)
end end
table.sort(rank, function(a, b) table.sort(rank, function(a, b)
if a.msg_num and b.msg_num then if a.msg_num and b.msg_num then
return a.msg_num > b.msg_num return a.msg_num > b.msg_num
end end
end end
) )
for id, user in pairs(rank) do for id, user in pairs(rank) do
-- Previous versions didn't save that
user_id = user.user_id or ''
print(">> ", id, user.name) print(">> ", id, user.name)
if user.last_name == nil then 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 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
end end
print("usuarios: "..text) print("usuarios: "..text)