annotate mod_track_muc_joins/README.markdown @ 2409:b426f1d46938

mod_track_muc_joins/README: Add some example code
author Kim Alvefur <zash@zash.se>
date Sat, 03 Dec 2016 15:01:15 +0100
parents 73096d8d924c
children e327b06b9a1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 ---
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 summary: Keep track of joined chat rooms
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 ...
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
2409
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
5 # Introduction
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
6
2081
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 This module attempts to keep track of what MUC chat rooms users have
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 joined. It's not very useful on its own, but can be used by other
73096d8d924c mod_track_muc_joins: Module to keep track of joined MUC rooms
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 modules to influence decisions.
2409
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
10
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
11 # Usage
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
12
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
13 Rooms joined and the associated nickname is kept in a table field
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
14 `rooms_joined` on the users session.
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
15
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
16 An example:
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
17
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
18 ``` lua
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
19 local jid_bare = require"util.jid".bare;
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
20
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
21 module:hook("message/full", function (event)
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
22 local stanza = event.stanza;
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
23 local session = prosody.full_sessions[stanza.attr.to];
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
24 if not session then
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
25 return -- No such session
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
26 end
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
27
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
28 local joined_rooms = session.joined_rooms;
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
29 if not joined_rooms then
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
30 return -- This session hasn't joined any rooms at all
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
31 end
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
32
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
33 -- joined_rooms is a map of room JID -> room nickname
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
34 local nickname = joined_rooms[jid_bare(stanza.attr.from)];
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
35 if nickname then
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
36 session.log("info", "Got a MUC message from %s", stanza.attr.from);
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
37
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
38 local body = stanza:get_child_text("body");
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
39 if body and body:find(nickname, 1, true) then
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
40 session.log("info", "The message contains my nickname!");
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
41 end
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
42 end
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
43 end);
b426f1d46938 mod_track_muc_joins/README: Add some example code
Kim Alvefur <zash@zash.se>
parents: 2081
diff changeset
44 ```