aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc/util.lib.lua
blob: d03b4d6b1b73c42bbafdfb8f742fcd6607224588 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- Prosody IM
-- Copyright (C) 2008-2010 Matthew Wild
-- Copyright (C) 2008-2010 Waqas Hussain
-- Copyright (C) 2014 Daurnimator
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--

local _M = {};

_M.valid_affiliations = {
	outcast = -1;
	none = 0;
	member = 1;
	admin = 2;
	owner = 3;
};

_M.valid_roles = {
	none = 0;
	visitor = 1;
	participant = 2;
	moderator = 3;
};

local kickable_error_conditions = {
	["gone"] = true;
	["internal-server-error"] = true;
	["item-not-found"] = true;
	["jid-malformed"] = true;
	["recipient-unavailable"] = true;
	["redirect"] = true;
	["remote-server-not-found"] = true;
	["remote-server-timeout"] = true;
	["service-unavailable"] = true;
	["malformed error"] = true;
};
function _M.is_kickable_error(stanza)
	local cond = select(2, stanza:get_error()) or "malformed error";
	return kickable_error_conditions[cond];
end

local muc_x_filters = {
	["http://jabber.org/protocol/muc"] = true;
	["http://jabber.org/protocol/muc#user"] = true;
}
local function muc_x_filter(tag)
	if muc_x_filters[tag.attr.xmlns] then
		return nil;
	end
	return tag;
end
function _M.filter_muc_x(stanza)
	return stanza:maptags(muc_x_filter);
end

function _M.only_with_min_role(role)
	local min_role_value = _M.valid_roles[role];
	return function (nick, occupant)
		if _M.valid_roles[occupant.role or "none"] >= min_role_value then
			return true;
		end
	end;
end

return _M;