Stats are private by Chat

This commit is contained in:
yago 2014-12-14 21:28:32 +01:00
parent fe05645a39
commit 5bbf754d73
3 changed files with 31 additions and 20 deletions

View File

@ -78,7 +78,6 @@ function _send_msg( destination, text)
local iterations = math.ceil(len / msg_text_max)
for i = 1, iterations, 1 do
print ("iteracion: "..i)
local inital_c = i * msg_text_max - msg_text_max
local final_c = i * msg_text_max
-- dont worry about if text length < msg_text_max
@ -98,7 +97,6 @@ function load_config()
print("Allowed user: " .. user)
end
end
-- print("Torrent path: " .. config.torrent_path)
f:close()
return config
end
@ -125,22 +123,26 @@ end
function update_user_stats(msg)
-- Save user to _users table
local from_id = tostring(msg.from.id)
local to_id = tostring(msg.to.id)
local user_name = get_name(msg)
-- If last name is nil dont save last_name.
local user_last_name = msg.from.last_name
local user_print_name = msg.from.print_name
if _users[from_id] == nil then
_users[from_id] = {
if _users[to_id] == nil then
_users[to_id] = {}
end
if _users[to_id][from_id] == nil then
_users[to_id][from_id] = {
name = user_name,
last_name = user_last_name,
print_name = user_print_name,
msg_num = 1
}
else
local actual_num = _users[from_id].msg_num
_users[from_id].msg_num = actual_num + 1
local actual_num = _users[to_id][from_id].msg_num
_users[to_id][from_id].msg_num = actual_num + 1
-- And update last_name
_users[from_id].last_name = user_last_name
_users[to_id][from_id].last_name = user_last_name
end
end
@ -159,15 +161,6 @@ function load_user_stats()
end
end
function get_receiver(msg)
if msg.to.type == 'user' then
return 'user#id'..msg.from.id
end
if msg.to.type == 'chat' then
return 'chat#id'..msg.to.id
end
end
function on_our_id (id)
our_id = id
end

View File

@ -1,3 +1,19 @@
function get_receiver(msg)
if msg.to.type == 'user' then
return 'user#id'..msg.from.id
end
if msg.to.type == 'chat' then
return 'chat#id'..msg.to.id
end
end
function is_chat_msg( msg )
if msg.to.type == 'chat' then
return true
end
return false
end
function string.random(length)
math.randomseed(os.time())
local str = "";

View File

@ -8,11 +8,13 @@ function run(msg, matches)
file_users:close()
local text = ""
for id, user in pairs(_users) do
local to_id = tostring(msg.to.id)
for id, user in pairs(_users[to_id]) do
if user.last_name == nil then
text = text..user.name..": "..user.msg_num.."\n"
text = text..user.name.." ["..id.."]: "..user.msg_num.."\n"
else
text = text..user.name.." "..user.last_name..": "..user.msg_num.."\n"
text = text..user.name.." "..user.last_name.." ["..id.."]: "..user.msg_num.."\n"
end
end
return text