plugins/opdown.lua

Thu, 22 Oct 2020 15:37:43 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 22 Oct 2020 15:37:43 +0100
changeset 161
c4df517edbc1
parent 47
b84572a2e6cb
permissions
-rw-r--r--

config.docker.lua: Require RIDDIM_DEBUG=1 to enable debug mode

47
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local jid_bare = require "util.jid".bare;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 function riddim.plugins.opdown(bot)
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local admin = bot.config.admin;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- To allow anyone other than the admin to use a command,
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 -- simply add them to the table, like
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 -- opdown_map = {
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 -- op = { role = "moderator", "operator@host" }, -- operator is allowed to use !op
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 -- "admin@host" -- allowed to use all commands
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 -- }
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 -- also, bot.config.admin is allowed to do anything
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local command_map = bot.config.opdown_map or {
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 owner = { affiliation = "owner" };
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 admin = { affiliation = "admin" };
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 op = { role = "moderator" };
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 member= { affiliation = "member" };
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 down = { role = "participant",
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 affiliation = "none" };
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 --ban = { affiliation = "outcast" };
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 --kick = { role = "none" };
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 }
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 function opdown(command)
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 if not command.room then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 return "This command is only available in groupchats.";
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 local what = command_map[command.command];
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 if not what then return end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 local room = command.room;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 local who = command.param or command.sender.nick;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 local commander = command.sender;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 local actor = jid_bare(command.sender.real_jid);
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 if not actor then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 return "I don't know who you really are?";
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 if actor ~= admin then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 local allow = false;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 for i = 1,#what do
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 if what[i] == actor then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 allow = true;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 break;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 if not allow then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 for i = 1,#command_map do
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 if command_map[i] == actor then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 allow = true;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 break;
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 if not allow then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 return "I can't let you do that!";
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 if command.room.occupants[who] then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 if what.role then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 command.room:set_role(who, what.role, "As commanded");
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 if what.affiliation then
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 command.room:set_affiliation(who, what.affiliation, "As commanded");
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 for k in pairs(command_map) do
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 bot:hook("commands/" .. k, opdown);
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 end
b84572a2e6cb plugins.opdown: New plugin that gives configurable room administrative commands.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76

mercurial