F*cking tabs

This commit is contained in:
yago 2015-02-11 22:00:00 +01:00
parent 3d0b3a64f8
commit 522bfc9d14

View File

@ -54,49 +54,49 @@ end
local function save_stats() local function save_stats()
-- Save stats to file -- Save stats to file
serialize_to_file(_stats, _file_stats) serialize_to_file(_stats, _file_stats)
end 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 -- Previous versions didn't save that
user_id = user.user_id or '' 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_id.."]: "..user.msg_num.."\n" text = text..user.name.." ["..user_id.."]: "..user.msg_num.."\n"
else else
text = text..user.name.." "..user.last_name.." ["..user_id.."]: "..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)
return text return text
end end
local function run(msg, matches) local function run(msg, matches)
if matches[1] == "stats" then -- Hack if matches[1] == "stats" then -- Hack
return get_stats_status(msg) return get_stats_status(msg)
else else
print ("update stats") print ("update stats")
update_user_stats(msg) update_user_stats(msg)
save_stats() save_stats()
end end
end end
_stats = read_file_stats() _stats = read_file_stats()