plugins/slap.lua

1
-- slap.lua
2
 
3
local st = require "prosody.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 = {'a large trout'}
9
   end
10
 
11
   -- slap someone
12
   local function slap(command)
13
      local who, weapon
14
      if command.param then
15
	 who = command.param
16
      else
17
	 -- slap the sender if they don't specify a target
18
	 if command.sender.nick then
19
	    who = command.sender.nick
20
	 else
21
	    who = (jid.split(command.sender.jid))
22
	 end
23
      end
24
      weapon = bot.config.weapons[math.random(#bot.config.weapons)]
25
      return string.format('/me slaps %s with %s', who, weapon)
26
   end
27
 
28
   -- pick up a weapon for slapping
29
   local function weapon(command)
30
      if command.param then
31
	 if command.param:lower() == 'excalibur' then
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.'
33
	 elseif command.param:lower() == 'paper' then
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.'
35
	 else
36
	    table.insert(bot.config.weapons, command.param)
37
	    return '/me picks up '..command.param
38
	 end
39
      else
40
	 return 'Tell me what weapon to pick up'
41
      end
42
   end
43
 
44
   -- drop a weapon
45
   local function drop(command)
46
      if command.param then
47
	 local found
48
	 for i,v in ipairs(bot.config.weapons) do
49
	    local weapons = bot.config.weapons
50
	    if v == command.param then
51
	       if #weapons == 1 then
52
		  return '/me refuses to drop his last weapon'
53
	       else
54
		  weapons[i] = weapons[#weapons]
55
		  table.remove(weapons)
56
		  found = true
57
	       end
58
	       break
59
	    end
60
	 end
61
	 if found then
62
	    return '/me drops '..command.param
63
	 else
64
	    return "/me doesn't have "..command.param
65
	 end
66
      else
67
	 return 'Tell me what to drop'
68
      end
69
   end
70
 
71
   bot:hook('commands/slap', slap)
72
   bot:hook('commands/weapon', weapon)
73
   bot:hook('commands/drop', drop)
74
end
75
 
76
-- end of slap.lua