Last active
February 21, 2016 22:28
-
-
Save celediel/7f8b56e3d3c245c01f5d to your computer and use it in GitHub Desktop.
Russian Roulette plugin for Cinch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding=utf-8 | |
# These are all very annoying. | |
# rubocop:disable Metrics/LineLength, Metrics/ClassLength, Metrics/CyclomaticComplexity | |
# rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize | |
module Cinch | |
module Plugins | |
# Roulette game | |
class Roulette | |
include Cinch::Plugin | |
set :prefix, /^\./ | |
private | |
def initialize(*args) | |
super | |
@shells = {} | |
@shot = {} | |
end | |
public | |
match(/spin$/, method: :spin) | |
def spin(m) | |
@shells[m.channel] = 6 | |
@shot[m.channel] = rand(1..@shells[m.channel]) | |
lines = '=' * 10 | |
puts "#{lines}\nShells left: #{@shells[m.channel]}" | |
puts "Hot shot: #{@shot[m.channel]}\n#{lines}" | |
m.action_reply 'spins the chamber!' | |
end | |
match(/rr$/, method: :rr) | |
def rr(m) | |
# just starting? | |
@shells[m.channel] = 6 if @shells[m.channel].nil? | |
@shot[m.channel] = rand(1..@shells[m.channel]) if @shot[m.channel].nil? | |
shooter = m.user.nick | |
# Cheating in the console | |
lines = '=' * 10 | |
puts "#{lines}\nShells left: #{@shells[m.channel]}" | |
puts "Hot shot: #{@shot[m.channel]}\n#{lines}" | |
if @shot[m.channel] == @shells[m.channel] | |
@shells[m.channel] = 6 | |
@shot[m.channel] = rand(1..@shells[m.channel]) | |
m.reply 'Bang!' | |
m.channel.kick(shooter, 'Bad luck, you\'re dead!') | |
else | |
m.reply 'Click!' | |
@shells[m.channel] -= 1 | |
end | |
end | |
end | |
end | |
end | |
# vim:tabstop=2 softtabstop=2 expandtab shiftwidth=2 smarttab foldmethod=syntax: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment