plugins/rtbl_admin.lua

changeset 168
1c2b8d10ceed
parent 167
2073137bc943
child 171
7362add76bcd
equal deleted inserted replaced
167:2073137bc943 168:1c2b8d10ceed
5 function riddim.plugins.rtbl_admin(bot) 5 function riddim.plugins.rtbl_admin(bot)
6 bot.stream:add_plugin("pubsub"); 6 bot.stream:add_plugin("pubsub");
7 7
8 local config = bot.config.rtbl_admin; 8 local config = bot.config.rtbl_admin;
9 9
10 local permitted_affiliations = config.permitted_affiliations or { admin = true, owner = true };
11
10 bot:hook("commands/rtbl-add", function (command) 12 bot:hook("commands/rtbl-add", function (command)
13 if config.control_room ~= (command.room and command.room.jid) then
14 return;
15 elseif not permitted_affiliations[command.sender.affiliation] then
16 return "You have insufficient permissions to use this command";
17 end
11 local reported_jid = command.param and jid.prep(command.param:match("^%S+")); 18 local reported_jid = command.param and jid.prep(command.param:match("^%S+"));
12 local hash = sha256(reported_jid, true); 19 local hash = sha256(reported_jid, true);
13 bot.stream.pubsub(config.host, config.node):publish( 20 bot.stream.pubsub(config.host, config.node):publish(
14 hash, -- item id 21 hash, -- item id
15 nil, -- options (not implemented anyway) 22 nil, -- options (not implemented anyway)
23 return; 30 return;
24 end 31 end
25 command:reply("RTBL entry added"); 32 command:reply("RTBL entry added");
26 end 33 end
27 ); 34 );
35 return true;
28 end); 36 end);
29 37
30 bot:hook("commands/rtbl-remove", function (command) 38 bot:hook("commands/rtbl-remove", function (command)
39 if config.control_room ~= (command.room and command.room.jid) then
40 return;
41 elseif not permitted_affiliations[command.sender.affiliation] then
42 return "You have insufficient permissions to use this command";
43 end
31 local reported_jid = command.param and jid.prep(command.param:match("^%S+")); 44 local reported_jid = command.param and jid.prep(command.param:match("^%S+"));
32 local hash = sha256(reported_jid, true); 45 local hash = sha256(reported_jid, true);
33 bot.stream.pubsub(config.host, config.node):retract( 46 bot.stream.pubsub(config.host, config.node):retract(
34 hash, -- item id 47 hash, -- item id
35 true, -- notify subscribers 48 true, -- notify subscribers
39 return; 52 return;
40 end 53 end
41 command:reply("RTBL entry removed"); 54 command:reply("RTBL entry removed");
42 end 55 end
43 ); 56 );
57 return true;
44 end); 58 end);
45 end 59 end

mercurial