daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Dec 9th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # encoding: UTF-8
  2. require 'fiber'
  3. require 'cinch'
  4.  
  5. SIDES_OF_A_DIE = 6
  6.  
  7. class Staging
  8.   attr_accessor :locker
  9.  
  10.   def initialize
  11.     @locker = "nobody"
  12.   end
  13. end
  14.  
  15. staging = Staging.new
  16.  
  17. def peat_sez(context, message)
  18.   context.reply("¯\\(°_o)/¯ (#{message})")
  19. end
  20.  
  21. bot = Cinch::Bot.new do
  22.   configure do |c|
  23.     c.nick = ENV["NICK"]
  24.     c.server = ENV["SERVER"]
  25.     c.channels = [ENV["ROOM"]]
  26.   end
  27.  
  28.   on :message, /!all(.*)/ do |context, message|
  29.     context.reply(self.bot.user_list.map { |u| u.to_s }.join(" ") + " - LISTEN UP!")
  30.     context.reply(message)
  31.   end
  32.  
  33.   on :message, "!staging" do |m|
  34.     peat_sez(m, staging.locker)
  35.   end
  36.  
  37.   on :message, /^\!number(.*)/ do |m, max_guess|
  38.  
  39.     max_guess = max_guess.to_i
  40.     if max_guess <= 1
  41.       peat_sez(m, "Usage: !number <n>")
  42.       next
  43.     end
  44.  
  45.     @number_target = rand(max_guess) + 1
  46.     @last_guesser = nil
  47.     peat_sez(m, "I've picked a number between 1 and #{max_guess}. Use !guess to hit it!")
  48.   end
  49.  
  50.   on :message, /^\!guess(.*)/ do |m, guess|
  51.  
  52.     if @number_target.nil?
  53.       peat_sez(m, "Heh, nice try. Use !number first before guessing, #{m.user.nick}")
  54.       next
  55.     elsif m.user == @last_guesser
  56.       peat_sez(m, "Uh...no. You were the last person to guess, #{m.user.nick}. Wait ur turn.")
  57.       next
  58.     end
  59.  
  60.     guess = guess.to_i
  61.     if guess == 0
  62.       peat_sez(m, "Oh come now, #{m.user.nick}, do you take me for a fool?")
  63.       next
  64.     else
  65.       @last_guesser = m.user
  66.     end
  67.  
  68.     if guess == @number_target
  69.       peat_sez(m, "BOOOOO0000000MMMM!!!1111one:   #{m.user.nick} YOU WIN!")
  70.       @number_target = nil
  71.     elsif guess < @number_target
  72.       peat_sez(m, "^^^ Higher, #{m.user.nick}, HIGHER!  ^^^^^^")
  73.     else # guess > target
  74.       peat_sez(m, "vvvvv Lower, #{m.user.nick}, LOWER vvvvvvvv")
  75.     end
  76.   end
  77.  
  78.  
  79.   on :message, "!roll" do |m|
  80.     next unless @fiber && @fiber.alive?
  81.  
  82.     roll = rand(@limit) + 1
  83.     nick = m.user.nick
  84.  
  85.     next if @attempts[nick]
  86.  
  87.     @attempts.merge!(nick => roll)
  88.  
  89.     peat_sez(m, "#{m.user.nick}: #{roll}")
  90.   end
  91.  
  92.   on :message, /^\!rolloff(.*)/ do |m, limit|
  93.     next if @fiber && @fiber.alive?
  94.  
  95.     @attempts = {}
  96.     @limit    = limit.to_i > 1 ? limit.to_i : SIDES_OF_A_DIE
  97.  
  98.     @fiber = Fiber.new do
  99.       sleep 10
  100.  
  101.       high_score = @attempts.sort_by { |nick, roll| roll }.last.last
  102.       @winners   = @attempts.select { |nick, roll| roll  == high_score }
  103.     end
  104.  
  105.     @fiber.resume
  106.  
  107.     winning_names = @winners.map(&:first)
  108.  
  109.     if winning_names.length == 1
  110.       peat_sez(m, "W1NN4R: #{winning_names.first}!!!111one")
  111.     else
  112.       peat_sez(m, "TIE!!: #{winning_names.join(", ")}!!!111one")
  113.     end
  114.   end
  115.  
  116.   on :message, "!lockstaging" do |m|
  117.     if staging.locker == "nobody"
  118.       staging.locker = m.user.nick
  119.  
  120.       peat_sez(m, "l0ck3d t3h st4g3")
  121.     else
  122.       peat_sez(m, "nice try d00d -- #{staging.locker}'s g07 17 l0ck3d")
  123.     end
  124.   end
  125.  
  126.   on :message, "!lockproduction" do |m|
  127.     peat_sez(m, "D3pL000Y1NG 70 Pr0DUC710N!!!111one")
  128.   end
  129.  
  130.   on :message, "!unlockproduction" do |m|
  131.     peat_sez(m, "2 L473 2 A90l0G1Z3, L0L!!!one")
  132.   end
  133.  
  134.   on :message, "!unlockstaging" do |m|
  135.     if m.user.nick == staging.locker
  136.       staging.locker = "nobody"
  137.  
  138.       peat_sez(m, "unl0ck3d t3h st4g3")
  139.     else
  140.       peat_sez(m, "nice try d00d -- #{staging.locker}'s g07 17 l0ck3d")
  141.     end
  142.   end
  143.  
  144.   on :message, /peat/ do |m|
  145.     peat_sez(m, "m4k1n t3h c0d3z 3v3n b3773r!!!111one")
  146.   end
  147. end
  148.  
  149. bot.start
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand