mod_motd_sequential/mod_motd_sequential.lua
author Kim Alvefur <zash@zash.se>
Sun, 25 Jan 2015 13:04:02 +0100
changeset 1593 3e4d15ae2133
parent 1343 7dbde05b48a9
permissions -rw-r--r--
mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
     1
-- Prosody IM
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
     2
-- Copyright (C) 2008-2010 Matthew Wild
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
     3
-- Copyright (C) 2008-2010 Waqas Hussain
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
     4
-- Copyright (C) 2010 Jeff Mitchell
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 234
diff changeset
     5
--
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
     6
-- This project is MIT/X11 licensed. Please see the
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
     7
-- COPYING file in the source package for more information.
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
     8
--
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
     9
1593
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    10
local st = require "util.stanza";
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    11
local jid_prep = require"util.jid".prep;
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
    12
1593
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    13
local motd_messages = module:get_option_array("motd_sequential_messages", {});
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    14
local motd_jid = jid_prep(module:get_option_string("motd_jid", module.host));
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    15
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    16
if #motd_messages == 0 then return; end
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    17
if not motd_jid then module:log("error", "Invalid jid: %s", module:get_option_string("motd_jid", module.host)); return; end
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    18
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    19
local seen = module:open_store("motd_sequential_seen");
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
    20
1593
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    21
module:hook("presence/bare", function (event)
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    22
	local session, stanza = event.origin, event.stanza;
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    23
	if session.username and not session.presence
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    24
	and not stanza.attr.type and not stanza.attr.to then
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    25
		local alreadyseen_list = seen:get(session.username) or { max = 0 };
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    26
		local alreadyseen = alreadyseen_list.max + 1;
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    27
		for i = alreadyseen, #motd_messages do
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    28
			if motd_messages[i] then
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    29
				session.send(st.message({ to = session.full_jid, from = motd_jid }, motd_messages[i]));
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    30
				module:log("debug", "MOTD send to user %s@%s", session.username, session.host);
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    31
			end
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    32
		end
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    33
		alreadyseen_list.max = max;
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    34
		seen:set(session.username, alreadyseen_list);
3e4d15ae2133 mod_storage_gdbm: Use require directly instead of util.import (which is not available in prosodyctl, breaks adduser etc)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
    35
	end
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
Jeff Mitchell <jeffrey.mitchell@gmail.com>
parents:
diff changeset
    36
end);