Comparison

mod_motd_sequential/mod_motd_sequential.lua @ 234:abcb59ab355c

Add new motd_sequential module. This module lets you define numbered messages shown to each user in order, but only once per user, and persistent across server restarts. Useful for notifying users of added features and changes in an incremental fashion.
author Jeff Mitchell <jeffrey.mitchell@gmail.com>
date Wed, 04 Aug 2010 22:29:51 +0000
child 1343:7dbde05b48a9
comparison
equal deleted inserted replaced
233:4ff8068b4d94 234:abcb59ab355c
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- Copyright (C) 2010 Jeff Mitchell
5 --
6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information.
8 --
9
10 local host = module:get_host();
11 local motd_jid = module:get_option("motd_jid") or host;
12 local datamanager = require "util.datamanager";
13 local ipairs = ipairs;
14 local motd_sequential_messages = module:get_option("motd_sequential_messages") or {};
15 local motd_messagesets = {};
16 local max = 1;
17 for i, message in ipairs(motd_sequential_messages) do
18 motd_messagesets[i] = message;
19 max = i;
20 end
21
22 local st = require "util.stanza";
23
24 module:hook("resource-bind",
25 function (event)
26 local session = event.session;
27 local alreadyseen_list = datamanager.load(session.username, session.host, "motd_sequential_seen") or { max = 0 };
28 local alreadyseen = alreadyseen_list["max"] + 1;
29 local mod_stanza;
30 for i = alreadyseen, max do
31 motd_stanza =
32 st.message({ to = session.username..'@'..session.host, from = motd_jid })
33 :tag("body"):text(motd_messagesets[i]);
34 core_route_stanza(hosts[host], motd_stanza);
35 module:log("debug", "MOTD send to user %s@%s", session.username, session.host);
36 end
37 alreadyseen_list["max"] = max;
38 datamanager.store(session.username, session.host, "motd_sequential_seen", alreadyseen_list);
39 end);