plugins/slap.lua

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

mercurial