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

View File

@ -54,61 +54,61 @@ 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()
return { return {
description = "Plugin to update user stats.", description = "Plugin to update user stats.",
usage = "!stats: Returns a list of Username [telegram_id]: msg_num", usage = "!stats: Returns a list of Username [telegram_id]: msg_num",
patterns = { patterns = {
".*", ".*",
"^!(stats)" "^!(stats)"
}, },
run = run run = run
} }
end end