comparison mod_measure_message_length/mod_measure_message_length.lua @ 2372:b1b120e654ff

mod_measure_message_length: Collect statistics on number of bytes, words and lines in messages
author Kim Alvefur <zash@zash.se>
date Thu, 17 Nov 2016 23:13:59 +0100
parents
children 6e70d354b7d8
comparison
equal deleted inserted replaced
2371:b41957bf4fd3 2372:b1b120e654ff
1 local bytes = module:measure("bytes", "sizes");
2 local lines = module:measure("lines", "count");
3 local words = module:measure("words", "count");
4
5 local function measure_length(event)
6 local body = event.stanza:get_child_text("body");
7 if body then
8 bytes(#body);
9 lines(select(2, body:gsub("[^\n]+","")));
10 words(select(2, body:gsub("%S+","")));
11 end
12 end
13
14 module:hook("message/full", measure_length);
15 module:hook("message/bare", measure_length);
16 module:hook("message/host", measure_length);
17
18 module:hook("pre-message/full", measure_length);
19 module:hook("pre-message/bare", measure_length);
20 module:hook("pre-message/host", measure_length);
21