This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/stats.lua

28 lines
669 B
Lua
Raw Normal View History

2014-11-22 20:17:33 +01:00
function run(msg, matches)
2014-11-23 00:31:22 +01:00
vardump(_users)
-- Save stats to file
local json_users = json:encode_pretty(_users)
vardump(json_users)
file_users = io.open ("./res/users.json", "w")
file_users:write(json_users)
file_users:close()
2014-11-22 20:17:33 +01:00
local text = ""
2014-12-14 21:28:32 +01:00
local to_id = tostring(msg.to.id)
for id, user in pairs(_users[to_id]) do
2014-11-23 14:34:46 +01:00
if user.last_name == nil then
2014-12-14 21:28:32 +01:00
text = text..user.name.." ["..id.."]: "..user.msg_num.."\n"
2014-11-23 14:34:46 +01:00
else
2014-12-14 21:28:32 +01:00
text = text..user.name.." "..user.last_name.." ["..id.."]: "..user.msg_num.."\n"
2014-11-23 14:34:46 +01:00
end
2014-11-22 20:17:33 +01:00
end
return text
end
return {
description = "Numer of messages by user",
usage = "!stats",
patterns = {"^!stats"},
run = run
}