class Robut::Plugin::RockPaperScissors

Rock Paper Scissors

Public Instance Methods

handle(time, sender_nick, message) click to toggle source
# File lib/robut-rps.rb, line 11
def handle(time, sender_nick, message)
  if sent_to_me?(message)
    words = words(message)

    return unless words[0] == "rps" && (words[1] == "rock" || words[1] == "scissors" || words[1] == "paper")

    answers = ["rock",
               "paper",
               "scissors"]
    choice = answers[random(answers.length)]

    if choice == words[1]
      reply "We both threw #{choice}. It's a tie!"
      return
    end

    win = false
    win = true if choice == "rock" && words[1] == "paper"
    win = true if choice == "paper" && words[1] == "scissors"
    win = true if choice == "scissors" && words[1] == "rock"
    reply("You threw #{words[1]} which beats #{choice}. You win!") if win
    reply("I threw #{choice} which beats #{words[1]}. You lose!") unless win

  end

end
random(c) click to toggle source
# File lib/robut-rps.rb, line 38
def random(c)
  rand(c)
end
usage() click to toggle source
# File lib/robut-rps.rb, line 7
def usage
  ["#{at_nick} rps <rock|paper|scissors>"]
end