|
1 -- slap.lua |
|
2 |
|
3 local st = require 'util.stanza' |
|
4 |
|
5 function riddim.plugins.slap(bot) |
|
6 if type(bot.config.weapons) ~= 'table' then |
|
7 -- start off with something to slap people with |
|
8 bot.config.weapons = {'large trout'} |
|
9 end |
|
10 |
|
11 -- reply to message (but don't prepend the sender's nick like groupchat's |
|
12 -- event:reply does) |
|
13 local function bare_reply(command, reply) |
|
14 if command.stanza.attr.type == 'groupchat' then |
|
15 local r = st.reply(command.stanza) |
|
16 local room_jid = jid.bare(command.sender.jid); |
|
17 if bot.rooms[room_jid] then |
|
18 bot.rooms[room_jid]:send(r:tag("body"):text(reply)); |
|
19 end |
|
20 else |
|
21 return command:reply(reply); |
|
22 end |
|
23 end |
|
24 |
|
25 -- slap someone |
|
26 local function slap(command) |
|
27 local who, weapon |
|
28 if command.param then |
|
29 who = command.param |
|
30 else |
|
31 -- slap the sender if they don't specify a target |
|
32 if bot.rooms[jid.bare(command.sender.jid)] then |
|
33 who = select(3, jid.split(command.sender.jid)) |
|
34 else |
|
35 who = (jid.split(command.sender.jid)) |
|
36 end |
|
37 end |
|
38 weapon = bot.config.weapons[math.random(#bot.config.weapons)] |
|
39 bare_reply(command, string.format('/me slaps %s with %s', who, weapon)) |
|
40 end |
|
41 |
|
42 -- pick up a weapon for slapping |
|
43 local function weapon(command) |
|
44 if command.param then |
|
45 if command.param:lower() == 'excalibur' then |
|
46 command:reply '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.' |
|
47 elseif command.param:lower() == 'paper' then |
|
48 bare_reply(command, '"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.') |
|
49 else |
|
50 table.insert(bot.config.weapons, command.param) |
|
51 bare_reply(command, '/me picks up '..command.param) |
|
52 end |
|
53 else |
|
54 command:reply 'Tell me what weapon to pick up' |
|
55 end |
|
56 end |
|
57 |
|
58 -- drop a weapon |
|
59 local function drop(command) |
|
60 if command.param then |
|
61 local found |
|
62 for i,v in ipairs(bot.config.weapons) do |
|
63 local weapons = bot.config.weapons |
|
64 if v == command.param then |
|
65 if #weapons == 1 then |
|
66 bare_reply(command, '/me refuses to drop his last weapon') |
|
67 else |
|
68 weapons[i] = weapons[#weapons] |
|
69 table.remove(weapons) |
|
70 found = true |
|
71 end |
|
72 break |
|
73 end |
|
74 end |
|
75 if found then |
|
76 bare_reply(command, '/me drops '..command.param) |
|
77 else |
|
78 bare_reply(command, "/me doesn't have "..command.param) |
|
79 end |
|
80 else |
|
81 command:reply 'Tell me what to drop' |
|
82 end |
|
83 end |
|
84 |
|
85 bot:hook('commands/slap', slap) |
|
86 bot:hook('commands/weapon', weapon) |
|
87 bot:hook('commands/drop', drop) |
|
88 end |
|
89 |
|
90 -- end of slap.lua |