Mercurial > prosody-modules
comparison mod_muclogging/mod_muclogging.lua @ 47:99ff520519fe
mod_muclogging: initial checkin
| author | Thilo Cestonaro <thilo@cestona.ro> |
|---|---|
| date | Fri, 16 Oct 2009 23:46:29 +0200 |
| parents | |
| children | a96d3f37d845 |
comparison
equal
deleted
inserted
replaced
| 46:ea756d96584f | 47:99ff520519fe |
|---|---|
| 1 -- Copyright (C) 2009 Thilo Cestonaro | |
| 2 -- | |
| 3 -- This project is MIT/X11 licensed. Please see the | |
| 4 -- COPYING file in the source package for more information. | |
| 5 -- | |
| 6 local prosody = prosody; | |
| 7 local splitJid = require "util.jid".split; | |
| 8 local bareJid = require "util.jid".bare; | |
| 9 local config_get = require "core.configmanager".get; | |
| 10 | |
| 11 function logIfNeeded(e) | |
| 12 local stanza, origin = e.stanza, e.origin; | |
| 13 if (stanza.name == "presence") or | |
| 14 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") | |
| 15 then | |
| 16 local node, host, resource = splitJid(stanza.attr.to); | |
| 17 if node ~= nil and host ~= nil then | |
| 18 local bare = node .. "@" .. host; | |
| 19 if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then | |
| 20 local room = prosody.hosts[host].muc.rooms[bare] | |
| 21 local logFolder = config_get(host, "core", "logFolder"); | |
| 22 if logFolder ~= nil then | |
| 23 local today = os.date("%y%m%d"); | |
| 24 local now = os.date("%X") | |
| 25 local fn = logFolder .. "/" .. today .. "_" .. bare .. ".log"; | |
| 26 local mucFrom = nil; | |
| 27 | |
| 28 if stanza.name == "presence" and stanza.attr.type == nil then | |
| 29 mucFrom = stanza.attr.to; | |
| 30 else | |
| 31 for jid, nick in pairs(room._jid_nick) do | |
| 32 if jid == stanza.attr.from then | |
| 33 mucFrom = nick; | |
| 34 end | |
| 35 end | |
| 36 end | |
| 37 | |
| 38 if mucFrom ~= nil then | |
| 39 module:log("debug", "try to open room log: %s", fn); | |
| 40 local f = assert(io.open(fn, "a")); | |
| 41 local realFrom = stanza.attr.from; | |
| 42 local realTo = stanza.attr.to; | |
| 43 stanza.attr.from = mucFrom; | |
| 44 stanza.attr.to = nil; | |
| 45 f:write("<stanza time=\"".. now .. "\">" .. tostring(stanza) .. "</stanza>\n"); | |
| 46 stanza.attr.from = realFrom; | |
| 47 stanza.attr.to = realTo; | |
| 48 f:close() | |
| 49 end | |
| 50 end | |
| 51 end | |
| 52 end | |
| 53 end | |
| 54 return; | |
| 55 end | |
| 56 | |
| 57 module:hook("pre-message/bare", logIfNeeded, 500); | |
| 58 module:hook("pre-presence/full", logIfNeeded, 500); | |
| 59 | |
| 60 module:log("debug", "loaded ..."); |
