Created
February 22, 2016 21:28
-
-
Save IotaSpencer/be64389d193407244a50 to your computer and use it in GitHub Desktop.
Sinatra route send to an IRC channel
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
post "/commit/?" do | |
config = YAML.load(File.open("gl-bot.yaml", "r")) | |
Thread.new do | |
socket = TCPSocket.open(config["host"], config["port"]) | |
socket.puts("NICK #{config["nick"]}") | |
socket.puts("USER #{config["nick"]} 8 * : #{config["realname"]}") | |
#socket.puts("JOIN #{IRC_CHANNEL}") # don"t join, just send the msg directly -- make sure the channel is /mode -n | |
# Don"t send anything to the channel until we"ve been successfully authorized by the IRC server to do so | |
while line = socket.gets | |
if line.include? "376 #{config["nick"]}" | |
break | |
end | |
end | |
json = JSON.parse(request.env["rack.input"].read) | |
#socket.puts("JOIN #{config["channel"]}") | |
# socket.puts "PRIVMSG #{config["channel"]} :Hi" | |
socket.puts "PRIVMSG #{config["channel"]} :#{json["repository"]["full_name"]} by #{json["head_commit"]["author"]["name"]}" | |
socket.puts "PRIVMSG #{config["channel"]} :Change: 03,99+#{json["head_commit"]["added"].length}/04,99-#{json["head_commit"]["removed"].length}/08,99±#{json["head_commit"]["modified"].length}" | |
json["commits"].each do |commit| | |
socket.puts "PRIVMSG #{config["channel"]} :09,99#{commit["message"]} | 04,99#{commit["id"][0..6]}" | |
end | |
socket.puts "QUIT :ElectroCommits bot!" | |
socket.close | |
Thread.stop | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment