Comparison

plugins/adhoc/mod_adhoc.lua @ 9331:2f634cc02eac

mod_adhoc: Use util.iterators.sorted_pairs() to sort commands
author Matthew Wild <mwild1@gmail.com>
date Fri, 21 Sep 2018 14:37:18 +0100
parent 9222:fe8abac62682
child 9571:5c475f6e89a4
comparison
equal deleted inserted replaced
9330:36badabc85ce 9331:2f634cc02eac
3 -- 3 --
4 -- This file is MIT/X11 licensed. Please see the 4 -- This file is MIT/X11 licensed. Please see the
5 -- COPYING file in the source package for more information. 5 -- COPYING file in the source package for more information.
6 -- 6 --
7 7
8 local it = require "util.iterators";
8 local st = require "util.stanza"; 9 local st = require "util.stanza";
9 local keys = require "util.iterators".keys;
10 local array_collect = require "util.array".collect;
11 local is_admin = require "core.usermanager".is_admin; 10 local is_admin = require "core.usermanager".is_admin;
12 local jid_split = require "util.jid".split; 11 local jid_split = require "util.jid".split;
13 local adhoc_handle_cmd = module:require "adhoc".handle_cmd; 12 local adhoc_handle_cmd = module:require "adhoc".handle_cmd;
14 local xmlns_cmd = "http://jabber.org/protocol/commands"; 13 local xmlns_cmd = "http://jabber.org/protocol/commands";
15 local commands = {}; 14 local commands = {};
52 51
53 local from = stanza.attr.from; 52 local from = stanza.attr.from;
54 local admin = is_admin(from, stanza.attr.to); 53 local admin = is_admin(from, stanza.attr.to);
55 local global_admin = is_admin(from); 54 local global_admin = is_admin(from);
56 local username, hostname = jid_split(from); 55 local username, hostname = jid_split(from);
57 local nodes = array_collect(keys(commands)):sort(); 56 for node, command in it.sorted_pairs(commands) do
58 for _, node in ipairs(nodes) do
59 local command = commands[node];
60 if (command.permission == "admin" and admin) 57 if (command.permission == "admin" and admin)
61 or (command.permission == "global_admin" and global_admin) 58 or (command.permission == "global_admin" and global_admin)
62 or (command.permission == "local_user" and hostname == module.host) 59 or (command.permission == "local_user" and hostname == module.host)
63 or (command.permission == "user") then 60 or (command.permission == "user") then
64 reply:tag("item", { name = command.name, 61 reply:tag("item", { name = command.name,