Class: Cinch::Plugins::Timebomb

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/timebomb.rb

Defined Under Namespace

Classes: Bomb

Constant Summary collapse

Colors =
%w{red orange yellow green blue indigo violet black
white grey brown pink mauve beige aquamarine chartreuse bisque
crimson fuchsia gold ivory khaki lavender lime magenta maroon
navi olive plum silver tan teal turquoise}

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Timebomb

Returns a new instance of Timebomb


10
11
12
13
14
# File 'lib/cinch/plugins/timebomb.rb', line 10

def initialize(*args)
  super

  @bombs = {}
end

Instance Method Details

#cut_wire(m, wire) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cinch/plugins/timebomb.rb', line 60

def cut_wire(m, wire)
  bomb = @bombs[m.channel]
  return unless bomb
  return unless bomb.user == m.user

  if bomb.correct_wire == wire.downcase
    m.reply "%s cut the %s wire. This has defused the bomb!" % [m.user, wire.capitalize]
  else
    m.channel.kick(m.user, "snip... *BOOM!*")
  end
  @bombs[m.channel] = nil
  bomb.timer.stop
end

#plant_bomb(m, whom) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cinch/plugins/timebomb.rb', line 26

def plant_bomb(m, whom)
  whom = User(whom)
  return unless m.channel.users[whom]
  return unless config[:channels].any? {|s| Channel(s) == m.channel}

  if whom == @bot
    m.channel.kick(m.user, "I will not tolerate this!")
    return
  end

  if @bombs[m.channel]
    m.channel.action "points at the bulge in the back of #{@bombs[m.channel].user}'s pants."
    return
  end

  min_duration = config[:min_duration] || 10
  max_duration = config[:max_duration] || 30
  num_wires    = config[:wires]        ||  6
  duration     = rand(max_duration - min_duration) + min_duration
  wires        = Colors.sample(num_wires)

  m.channel.action "stuffs the bomb into %s's pants. The display reads [%d] seconds." % [whom, duration]
  m.reply "Defuse the bomb by cutting the correct wire. There are %d wires. They are %s" % [num_wires, wires.map {|s|
                                                                                              s.capitalize }.join(", ")]


  timer = Timer(duration, shots: 1) do
    m.channel.kick(m.user, "*BOOM!*")
    @bombs[m.channel] = nil
  end

  @bombs[m.channel] = Bomb.new(whom, timer, wires.sample)
end