Comparison

mod_muc_log/mod_muc_log.lua @ 1343:7dbde05b48a9

all the things: Remove trailing whitespace
author Florian Zeitz <florob@babelmonkeys.de>
date Tue, 11 Mar 2014 18:44:01 +0100
parent 1325:b21236b6b8d8
child 1357:67990f8d8228
comparison
equal deleted inserted replaced
1342:0ae065453dc9 1343:7dbde05b48a9
16 16
17 -- Module Definitions 17 -- Module Definitions
18 18
19 function log_if_needed(event) 19 function log_if_needed(event)
20 local stanza = event.stanza; 20 local stanza = event.stanza;
21 21
22 if (stanza.name == "presence") or 22 if (stanza.name == "presence") or
23 (stanza.name == "iq") or 23 (stanza.name == "iq") or
24 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") 24 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat")
25 then 25 then
26 local node, host = split_jid(stanza.attr.to); 26 local node, host = split_jid(stanza.attr.to);
32 local today = os.date("%y%m%d"); 32 local today = os.date("%y%m%d");
33 local now = os.date("%X") 33 local now = os.date("%X")
34 local muc_to = nil 34 local muc_to = nil
35 local muc_from = nil; 35 local muc_from = nil;
36 local already_joined = false; 36 local already_joined = false;
37 37
38 if room._data.hidden then -- do not log any data of private rooms 38 if room._data.hidden then -- do not log any data of private rooms
39 return; 39 return;
40 end 40 end
41 if not room._data.logging then -- do not log where logging is not enabled 41 if not room._data.logging then -- do not log where logging is not enabled
42 return; 42 return;
43 end 43 end
44 44
45 if stanza.name == "presence" and stanza.attr.type == nil then 45 if stanza.name == "presence" and stanza.attr.type == nil then
46 muc_from = stanza.attr.to; 46 muc_from = stanza.attr.to;
47 if room._occupants and room._occupants[stanza.attr.to] then 47 if room._occupants and room._occupants[stanza.attr.to] then
48 already_joined = true; 48 already_joined = true;
49 stanza:tag("alreadyJoined"):text("true"); 49 stanza:tag("alreadyJoined"):text("true");
50 end 50 end
51 elseif stanza.name == "iq" and stanza.attr.type == "set" then -- kick, to is the room, from is the admin, nick who is kicked is attr of iq->query->item 51 elseif stanza.name == "iq" and stanza.attr.type == "set" then -- kick, to is the room, from is the admin, nick who is kicked is attr of iq->query->item
52 if stanza.tags[1] and stanza.tags[1].name == "query" then 52 if stanza.tags[1] and stanza.tags[1].name == "query" then
53 local tmp = stanza.tags[1]; 53 local tmp = stanza.tags[1];
54 if tmp.tags[1] ~= nil and tmp.tags[1].name == "item" and tmp.tags[1].attr.nick then 54 if tmp.tags[1] ~= nil and tmp.tags[1].name == "item" and tmp.tags[1].attr.nick then
72 72
73 if (muc_from or muc_to) then 73 if (muc_from or muc_to) then
74 local data = data_load(node, host, datastore .. "/" .. today); 74 local data = data_load(node, host, datastore .. "/" .. today);
75 local realFrom = stanza.attr.from; 75 local realFrom = stanza.attr.from;
76 local realTo = stanza.attr.to; 76 local realTo = stanza.attr.to;
77 77
78 if data == nil then 78 if data == nil then
79 data = {}; 79 data = {};
80 end 80 end
81 81
82 stanza.attr.from = muc_from; 82 stanza.attr.from = muc_from;
83 stanza.attr.to = muc_to; 83 stanza.attr.to = muc_to;
84 data[#data + 1] = "<stanza time=\"".. now .. "\">" .. tostring(stanza) .. "</stanza>\n"; 84 data[#data + 1] = "<stanza time=\"".. now .. "\">" .. tostring(stanza) .. "</stanza>\n";
85 stanza.attr.from = realFrom; 85 stanza.attr.from = realFrom;
86 stanza.attr.to = realTo; 86 stanza.attr.to = realTo;
129 end); 129 end);
130 130
131 module:hook("message/bare", log_if_needed, 1); 131 module:hook("message/bare", log_if_needed, 1);
132 if log_presences then 132 if log_presences then
133 module:hook("iq/bare", log_if_needed, 1); 133 module:hook("iq/bare", log_if_needed, 1);
134 module:hook("presence/full", log_if_needed, 1); 134 module:hook("presence/full", log_if_needed, 1);
135 end 135 end
136 136
137 module:log("debug", "module mod_muc_log loaded!"); 137 module:log("debug", "module mod_muc_log loaded!");