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
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)