Skip to content

Instantly share code, notes, and snippets.

@shelvacu
Created July 20, 2016 08:04
Show Gist options
  • Save shelvacu/5517445bd1e69df977cb59c5898e3e11 to your computer and use it in GitHub Desktop.
Save shelvacu/5517445bd1e69df977cb59c5898e3e11 to your computer and use it in GitHub Desktop.
require 'cinch'
$channels = ARGV
$votes = {}
$username = "shelvacubot"
$password = "oauth:XXXXXXXX"
def printscoreboard
system("clear") or system("cls") #vaguely portable
if $votes.empty?
puts "No votes!"
else
compiled_votes = Hash.new(0)
$votes.each do |_,vote|
compiled_votes[vote] += 1
end
n = 1
compiled_votes.to_a.sort_by(&:last).reverse[0..10].each do |vote, amount|
puts n.to_s.rjust(2)+". #{vote}: #{amount} votes"
n += 1
end
end
end
Thread.new do
loop do
#I'm too lazy to unbuffer the terminal or whatever so ill just use enter to
#say "clear the votes and start new vote"
#using gets would just wait until it gets pressed which is bad cuz
#were single-threading this bitch cuz multi thread is hard man
#so I have to do a nonblock read so that raises an error when it otherwise
#would block which is dumb thats hardly an exceptional circumstance
#so consider this more of an if block, with everything after the read being
# "if enter has been pressed"
#excepth that used to be in printscoreboard which was a horrible idea
#and actually putting this in a separate thread makes it a shitton easier so here it is
gets
$votes = {} # mutex isnt needed here right? right? right? right?
printscoreboard
end
end
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.chat.twitch.com"
c.channels = $channels
c.nick = $username
c.password = $password
end
on :message, /\!v(ote)?/ do |m|
matchdata = /!v(ote)? ?(.*)$/.match(m.message)
next if matchdata.nil?
vote = matchdata[2].gsub(/[^a-zA-Z _0-9-]/,'-')
vote = vote[0..30] # limit to 30 chars
# or might limit to 31 or 29 , not sure, dont care
$votes[m.user.nick] = vote
printscoreboard
end
end
printscoreboard
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment