Comparison

mod_stanza_counter/mod_stanza_counter.lua @ 534:3d6e0e037dab

mod_stanza_counter: removed a few empty lines.
author Marco Cirillo <maranda@lightwitch.org>
date Sun, 08 Jan 2012 03:52:06 +0000
parent 436:e4a1f0425380
child 1343:7dbde05b48a9
comparison
equal deleted inserted replaced
533:47b9053dba38 534:3d6e0e037dab
12 presence = { incoming=0, outgoing=0 } 12 presence = { incoming=0, outgoing=0 }
13 } 13 }
14 end 14 end
15 15
16 -- Setup on server start 16 -- Setup on server start
17 local function setup() 17 local function setup() init_counter() end
18 init_counter();
19 end
20 18
21 -- Basic Stanzas' Counters 19 -- Basic Stanzas' Counters
22 local function iq_callback(check) 20 local function iq_callback(check)
23 return function(self) 21 return function(self)
24 local origin, stanza = self.origin, self.stanza 22 local origin, stanza = self.origin, self.stanza
25 if not prosody.stanza_counter then init_counter() end 23 if not prosody.stanza_counter then init_counter() end
26 if check then 24 if check then
27 if not stanza.attr.to or hosts[jid_bare(stanza.attr.to)] then return nil; 25 if not stanza.attr.to or hosts[jid_bare(stanza.attr.to)] then return nil
28 else 26 else
29 prosody.stanza_counter.iq["outgoing"] = prosody.stanza_counter.iq["outgoing"] + 1 27 prosody.stanza_counter.iq["outgoing"] = prosody.stanza_counter.iq["outgoing"] + 1
30 end 28 end
31 else 29 else
32 prosody.stanza_counter.iq["incoming"] = prosody.stanza_counter.iq["incoming"] + 1 30 prosody.stanza_counter.iq["incoming"] = prosody.stanza_counter.iq["incoming"] + 1
37 local function mes_callback(check) 35 local function mes_callback(check)
38 return function(self) 36 return function(self)
39 local origin, stanza = self.origin, self.stanza 37 local origin, stanza = self.origin, self.stanza
40 if not prosody.stanza_counter then init_counter() end 38 if not prosody.stanza_counter then init_counter() end
41 if check then 39 if check then
42 if not stanza.attr.to or hosts[jid_bare(stanza.attr.to)] then return nil; 40 if not stanza.attr.to or hosts[jid_bare(stanza.attr.to)] then return nil
43 else 41 else
44 prosody.stanza_counter.message["outgoing"] = prosody.stanza_counter.message["outgoing"] + 1 42 prosody.stanza_counter.message["outgoing"] = prosody.stanza_counter.message["outgoing"] + 1
45 end 43 end
46 else 44 else
47 prosody.stanza_counter.message["incoming"] = prosody.stanza_counter.message["incoming"] + 1 45 prosody.stanza_counter.message["incoming"] = prosody.stanza_counter.message["incoming"] + 1
52 local function pre_callback(check) 50 local function pre_callback(check)
53 return function(self) 51 return function(self)
54 local origin, stanza = self.origin, self.stanza 52 local origin, stanza = self.origin, self.stanza
55 if not prosody.stanza_counter then init_counter() end 53 if not prosody.stanza_counter then init_counter() end
56 if check then 54 if check then
57 if not stanza.attr.to or hosts[jid_bare(stanza.attr.to)] then return nil; 55 if not stanza.attr.to or hosts[jid_bare(stanza.attr.to)] then return nil
58 else 56 else
59 prosody.stanza_counter.presence["outgoing"] = prosody.stanza_counter.presence["outgoing"] + 1 57 prosody.stanza_counter.presence["outgoing"] = prosody.stanza_counter.presence["outgoing"] + 1
60 end 58 end
61 else 59 else
62 prosody.stanza_counter.presence["incoming"] = prosody.stanza_counter.presence["incoming"] + 1 60 prosody.stanza_counter.presence["incoming"] = prosody.stanza_counter.presence["incoming"] + 1
63 end 61 end
64 end 62 end
65 end 63 end
66
67
68 64
69 -- Hook all pre-stanza events. 65 -- Hook all pre-stanza events.
70 module:hook("pre-iq/bare", iq_callback(true), 140) 66 module:hook("pre-iq/bare", iq_callback(true), 140)
71 module:hook("pre-iq/full", iq_callback(true), 140) 67 module:hook("pre-iq/full", iq_callback(true), 140)
72 module:hook("pre-iq/host", iq_callback(true), 140) 68 module:hook("pre-iq/host", iq_callback(true), 140)
92 module:hook("presence/full", pre_callback(false), 140) 88 module:hook("presence/full", pre_callback(false), 140)
93 module:hook("presence/host", pre_callback(false), 140) 89 module:hook("presence/host", pre_callback(false), 140)
94 90
95 -- Hook server start to initialize the counter. 91 -- Hook server start to initialize the counter.
96 module:hook("server-started", setup) 92 module:hook("server-started", setup)
97