Merge branch 'develop'

This commit is contained in:
yago 2015-02-11 22:02:01 +01:00
commit 2937be7b77
2 changed files with 48 additions and 42 deletions

View File

@ -5,7 +5,7 @@ json = (loadfile "./libs/JSON.lua")()
serpent = (loadfile "./libs/serpent.lua")()
require("./bot/utils")
VERSION = '0.8.5'
VERSION = '0.8.6'
function on_msg_receive (msg)
vardump(msg)
@ -63,12 +63,18 @@ end
function do_action(msg)
local receiver = get_receiver(msg)
local text = msg.text
if msg.text == nil then
-- Not a text message, make text the same as what tg shows so
-- we can match on it. The plugin is resposible for handling
text = '['..msg.media.type..']'
-- Not a text message, make text the same as what tg shows so
-- we can match on it. The plugin is resposible for handling
if msg.media ~= nil then
text = '['..msg.media.type..']'
end
end
-- We can't do anything
if msg.text == nil return false end
msg.text = do_lex(msg, text)
for name, desc in pairs(plugins) do

View File

@ -54,61 +54,61 @@ end
local function save_stats()
-- Save stats to file
serialize_to_file(_stats, _file_stats)
-- Save stats to file
serialize_to_file(_stats, _file_stats)
end
local function get_stats_status( msg )
-- vardump(stats)
local text = ""
-- vardump(stats)
local text = ""
local to_id = tostring(msg.to.id)
local rank = {}
local rank = {}
for id, user in pairs(_stats[to_id]) do
table.insert(rank, user)
end
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
)
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
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_id.."]: "..user.msg_num.."\n"
else
text = text..user.name.." "..user.last_name.." ["..user_id.."]: "..user.msg_num.."\n"
end
end
print("usuarios: "..text)
return text
print(">> ", id, user.name)
if user.last_name == nil then
text = text..user.name.." ["..user_id.."]: "..user.msg_num.."\n"
else
text = text..user.name.." "..user.last_name.." ["..user_id.."]: "..user.msg_num.."\n"
end
end
print("usuarios: "..text)
return text
end
local function run(msg, matches)
if matches[1] == "stats" then -- Hack
return get_stats_status(msg)
else
print ("update stats")
update_user_stats(msg)
if matches[1] == "stats" then -- Hack
return get_stats_status(msg)
else
print ("update stats")
update_user_stats(msg)
save_stats()
end
end
end
_stats = read_file_stats()
return {
description = "Plugin to update user stats.",
usage = "!stats: Returns a list of Username [telegram_id]: msg_num",
patterns = {
".*",
"^!(stats)"
},
run = run
description = "Plugin to update user stats.",
usage = "!stats: Returns a list of Username [telegram_id]: msg_num",
patterns = {
".*",
"^!(stats)"
},
run = run
}
end
end