Mercurial > prosody-modules
changeset 2081:73096d8d924c
mod_track_muc_joins: Module to keep track of joined MUC rooms
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 14 Mar 2016 13:36:12 +0100 |
parents | a435db77a5e5 |
children | 163d55777ad5 |
files | mod_track_muc_joins/README.markdown mod_track_muc_joins/mod_track_muc_joins.lua |
diffstat | 2 files changed, 44 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_track_muc_joins/README.markdown Mon Mar 14 13:36:12 2016 +0100 @@ -0,0 +1,7 @@ +--- +summary: Keep track of joined chat rooms +... + +This module attempts to keep track of what MUC chat rooms users have +joined. It's not very useful on its own, but can be used by other +modules to influence decisions.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_track_muc_joins/mod_track_muc_joins.lua Mon Mar 14 13:36:12 2016 +0100 @@ -0,0 +1,37 @@ + +module:hook("presence/full", function (event) + local stanza = event.stanza; + local session = sessions[stanza.attr.to]; + if not session then return end; + local log = session.log or module._log; + local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); + if not muc_x then return end -- Not MUC related + + local room = jid_bare(stanza.attr.from); + local joined = stanza.attr.type; + if joined == nil then + joined = true; + elseif joined == "unavailable" then + joined = nil; + else + -- Ignore errors and whatever + return; + end + + -- Check for status code 100, meaning it's their own reflected presence + for status in muc_x:childtags("status") do + log("debug", "Status code %d", status.attr.code); + if status.attr.code == "110" then + log("debug", "%s room %s", joined and "Joined" or "Left", room); + local rooms = session.rooms_joined; + if not rooms then + session.rooms_joined = { [room] = joined }; + else + rooms[room] = joined; + end + return; + end + end +end); + +-- TODO Check session.directed for outgoing presence?