Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yagop committed Feb 11, 2015
2 parents 7d25e0a + b610511 commit 2937be7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 42 deletions.
14 changes: 10 additions & 4 deletions bot/bot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
76 changes: 38 additions & 38 deletions plugins/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2937be7

Please sign in to comment.