!stats command

This commit is contained in:
yago 2014-11-22 20:17:33 +01:00
parent e19a0b7e6b
commit a1f5c7c9fa
2 changed files with 21 additions and 8 deletions

View File

@ -3,7 +3,7 @@
URL = require("socket.url")
json = (loadfile "./bot/JSON.lua")()
VERSION = 'v0.7.1'
VERSION = 'v0.7.2'
-- taken from http://stackoverflow.com/a/11130774/3163199
function scandir(directory)
@ -16,7 +16,7 @@
end
function on_msg_receive (msg)
vardump(msg)
--vardump(msg)
if msg_valid(msg) == false then
return
@ -226,16 +226,15 @@
end
function update_user_stats(msg)
-- Save user to users table
if (users[msg.from.id] == nil) then
users[msg.from.id] = {
-- Save user to _users table
if (_users[msg.from.id] == nil) then
_users[msg.from.id] = {
name = get_name(msg),
msg_num = 1
}
else
users[msg.from.id].msg_num = users[msg.from.id].msg_num + 1
_users[msg.from.id].msg_num = _users[msg.from.id].msg_num + 1
end
print (msg.from.print_name .. ": "..users[msg.from.id].msg_num)
end
function get_receiver(msg)
@ -275,7 +274,7 @@
-- Start and load values
config = load_config()
our_id = 0
users = {}
_users = {}
now = os.time()
-- load plugins

14
plugins/stats.lua Normal file
View File

@ -0,0 +1,14 @@
function run(msg, matches)
local text = ""
for id, user in pairs(_users) do
text = text..user.name..": "..user.msg_num.."\n"
end
return text
end
return {
description = "Numer of messages by user",
usage = "!stats",
patterns = {"^!stats"},
run = run
}