Created
February 28, 2012 09:24
-
-
Save frimik/1931502 to your computer and use it in GitHub Desktop.
IRC notification script (Uses supybot-notify, or a similar IRC bot)
This file contains hidden or 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 | |
| # Send privmsg (IRC notifications). | |
| # Contacts a supybot-notify service, on a currently hardcoded host and port, | |
| # and sends either the message sent as a parameter, or pipes everything from | |
| # standard input | |
| # | |
| # Author: Mikael Fridh <mfridh@marinsoftware.com> | |
| # Copyright (c) 2012 Marin Software | |
| # | |
| # ChangeLog | |
| # * Tue Jan 03 2012 Mikael Fridh <mfridh@marinsoftware.com> - 0.1 | |
| # - Initial version | |
| # | |
| require 'socket' | |
| require 'logger' | |
| require 'syslog' | |
| require 'rubygems' | |
| require 'optparse' | |
| program = File.basename($0) | |
| channel = nil | |
| verbose = false | |
| optparse = OptionParser.new do |opts| | |
| opts.banner = "Usage: #{program} -c '#channel' 'the message'" | |
| opts.on("-cMANDATORY", "--channel=MANDATORY", | |
| "The message recipient.") do |c| | |
| channel = c | |
| end | |
| opts.on("-v", "--verbose", | |
| "Enable verbose mode.") do |v| | |
| verbose = true | |
| end | |
| begin | |
| ARGV << "-h" if ARGV.size < 1 | |
| opts.parse!(ARGV) | |
| rescue OptionParser::ParseError | |
| $stderr.print "Error: " + $! + "\n" | |
| exit | |
| end | |
| end.parse! | |
| message = ARGV.first || nil | |
| client = TCPSocket.open('supybot-notify', '5050') | |
| if (!message) then | |
| STDIN.each_line do |line| | |
| line.chomp! | |
| line.gsub!(/([^\t]*)(\t)/) { $1 + " " * (8 - $1.length % 8) } | |
| unless line.empty? | |
| p "#{channel} #{line}" if verbose | |
| client.send("#{channel} #{line}\n", 0) # 0 means standard packet | |
| end | |
| end | |
| else | |
| client.send("#{channel} #{message}", 0) | |
| end | |
| client.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment