# HG changeset patch # User Jeff Mitchell # Date 1280960991 0 # Node ID abcb59ab355cfd0f10a7b2fea36ceeff9a7cb1d4 # Parent 4ff8068b4d942a8c2c686ec2bd2123f1610ed834 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. diff -r 4ff8068b4d94 -r abcb59ab355c mod_motd_sequential/mod_motd_sequential.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_motd_sequential/mod_motd_sequential.lua Wed Aug 04 22:29:51 2010 +0000 @@ -0,0 +1,39 @@ +-- Prosody IM +-- Copyright (C) 2008-2010 Matthew Wild +-- Copyright (C) 2008-2010 Waqas Hussain +-- Copyright (C) 2010 Jeff Mitchell +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + +local host = module:get_host(); +local motd_jid = module:get_option("motd_jid") or host; +local datamanager = require "util.datamanager"; +local ipairs = ipairs; +local motd_sequential_messages = module:get_option("motd_sequential_messages") or {}; +local motd_messagesets = {}; +local max = 1; +for i, message in ipairs(motd_sequential_messages) do + motd_messagesets[i] = message; + max = i; +end + +local st = require "util.stanza"; + +module:hook("resource-bind", + function (event) + local session = event.session; + local alreadyseen_list = datamanager.load(session.username, session.host, "motd_sequential_seen") or { max = 0 }; + local alreadyseen = alreadyseen_list["max"] + 1; + local mod_stanza; + for i = alreadyseen, max do + motd_stanza = + st.message({ to = session.username..'@'..session.host, from = motd_jid }) + :tag("body"):text(motd_messagesets[i]); + core_route_stanza(hosts[host], motd_stanza); + module:log("debug", "MOTD send to user %s@%s", session.username, session.host); + end + alreadyseen_list["max"] = max; + datamanager.store(session.username, session.host, "motd_sequential_seen", alreadyseen_list); +end);