plugins/slap.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 100
f90ead53573a
permissions
-rw-r--r--

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

25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
1 -- slap.lua
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
2
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
3 local st = require 'util.stanza'
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
4
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
5 function riddim.plugins.slap(bot)
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
6 if type(bot.config.weapons) ~= 'table' then
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
7 -- start off with something to slap people with
100
f90ead53573a plugins.slap: Fix the grammar, once and for all!
Kim Alvefur <zash@zash.se>
parents: 61
diff changeset
8 bot.config.weapons = {'a large trout'}
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
9 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
10
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
11 -- slap someone
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
12 local function slap(command)
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
13 local who, weapon
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
14 if command.param then
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
15 who = command.param
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
16 else
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
17 -- slap the sender if they don't specify a target
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
18 if command.sender.nick then
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
19 who = command.sender.nick
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
20 else
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
21 who = (jid.split(command.sender.jid))
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
22 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
23 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
24 weapon = bot.config.weapons[math.random(#bot.config.weapons)]
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
25 return string.format('/me slaps %s with %s', who, weapon)
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
26 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
27
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
28 -- pick up a weapon for slapping
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
29 local function weapon(command)
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
30 if command.param then
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
31 if command.param:lower() == 'excalibur' then
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
32 return 'Listen -- strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony.'
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
33 elseif command.param:lower() == 'paper' then
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
34 return '"Reverse primary thrust, Marvin." That\'s what they say to me. "Open airlock number 3, Marvin." "Marvin, can you pick up that piece of paper?" Here I am, brain the size of a planet, and they ask me to pick up a piece of paper.'
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
35 else
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
36 table.insert(bot.config.weapons, command.param)
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
37 return '/me picks up '..command.param
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
38 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
39 else
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
40 return 'Tell me what weapon to pick up'
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
41 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
42 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
43
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
44 -- drop a weapon
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
45 local function drop(command)
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
46 if command.param then
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
47 local found
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
48 for i,v in ipairs(bot.config.weapons) do
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
49 local weapons = bot.config.weapons
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
50 if v == command.param then
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
51 if #weapons == 1 then
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
52 return '/me refuses to drop his last weapon'
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
53 else
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
54 weapons[i] = weapons[#weapons]
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
55 table.remove(weapons)
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
56 found = true
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
57 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
58 break
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
59 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
60 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
61 if found then
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
62 return '/me drops '..command.param
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
63 else
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
64 return "/me doesn't have "..command.param
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
65 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
66 else
61
aca019044c51 plugins.slap: Remove special handling for actions
Kim Alvefur <zash@zash.se>
parents: 25
diff changeset
67 return 'Tell me what to drop'
25
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
68 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
69 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
70
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
71 bot:hook('commands/slap', slap)
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
72 bot:hook('commands/weapon', weapon)
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
73 bot:hook('commands/drop', drop)
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
74 end
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
75
b1f95474104f plugins.slap: Can't have a bot without this!
Hubert Chathi <hubert@uhoreg.ca>
parents:
diff changeset
76 -- end of slap.lua

mercurial