Advertisement
Guest User

Untitled

a guest
Jul 20th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. require 'cinch'
  2.  
  3. $channels = ARGV
  4.  
  5. $votes = {}
  6.  
  7. $username = "shelvacubot"
  8.  
  9. $password = "oauth:XXXXXXXX"
  10.  
  11. def printscoreboard
  12. system("clear") or system("cls") #vaguely portable
  13. if $votes.empty?
  14. puts "No votes!"
  15. else
  16. compiled_votes = Hash.new(0)
  17. $votes.each do |_,vote|
  18. compiled_votes[vote] += 1
  19. end
  20. n = 1
  21. compiled_votes.to_a.sort_by(&:last).reverse[0..10].each do |vote, amount|
  22. puts n.to_s.rjust(2)+". #{vote}: #{amount} votes"
  23. n += 1
  24. end
  25. end
  26. end
  27.  
  28. Thread.new do
  29. loop do
  30. #I'm too lazy to unbuffer the terminal or whatever so ill just use enter to
  31. #say "clear the votes and start new vote"
  32. #using gets would just wait until it gets pressed which is bad cuz
  33. #were single-threading this bitch cuz multi thread is hard man
  34. #so I have to do a nonblock read so that raises an error when it otherwise
  35. #would block which is dumb thats hardly an exceptional circumstance
  36. #so consider this more of an if block, with everything after the read being
  37. # "if enter has been pressed"
  38.  
  39. #excepth that used to be in printscoreboard which was a horrible idea
  40. #and actually putting this in a separate thread makes it a shitton easier so here it is
  41.  
  42. gets
  43. $votes = {} # mutex isnt needed here right? right? right? right?
  44. printscoreboard
  45. end
  46. end
  47.  
  48.  
  49. bot = Cinch::Bot.new do
  50. configure do |c|
  51. c.server = "irc.chat.twitch.com"
  52. c.channels = $channels
  53. c.nick = $username
  54. c.password = $password
  55. end
  56.  
  57. on :message, /\!v(ote)?/ do |m|
  58. matchdata = /!v(ote)? ?(.*)$/.match(m.message)
  59. next if matchdata.nil?
  60. vote = matchdata[2].gsub(/[^a-zA-Z _0-9-]/,'-')
  61. vote = vote[0..30] # limit to 30 chars
  62. # or might limit to 31 or 29 , not sure, dont care
  63. $votes[m.user.nick] = vote
  64. printscoreboard
  65. end
  66. end
  67.  
  68. printscoreboard
  69.  
  70. bot.start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement