Merge branch 'master' of git://github.com/but3k4/telegram-bot into but3k4-master

This commit is contained in:
yago
2015-02-02 22:42:59 +01:00
3 changed files with 52 additions and 32 deletions

View File

@@ -61,12 +61,23 @@ local function get_stats_status( msg )
-- vardump(stats)
local text = ""
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
print(">> ", id, user.name)
if user.last_name == nil then
text = text..user.name.." ["..id.."]: "..user.msg_num.."\n"
text = text..user.name..": "..user.msg_num.."\n"
else
text = text..user.name.." "..user.last_name.." ["..id.."]: "..user.msg_num.."\n"
text = text..user.name.." "..user.last_name..": "..user.msg_num.."\n"
end
end
print("usuarios: "..text)
@@ -75,7 +86,7 @@ end
local function run(msg, matches)
if matches[1] == "stats" then -- Hack
return get_stats_status(msg)
return get_stats_status(msg)
else
print ("update stats")
update_user_stats(msg)
@@ -86,7 +97,7 @@ end
_stats = read_file_stats()
return {
description = "Numer of messages by user",
description = "Number of messages by user",
usage = "!stats",
patterns = {
".*",
@@ -95,4 +106,4 @@ return {
run = run
}
end
end