Skip to content

Instantly share code, notes, and snippets.

@stammy
Forked from max-mapper/IRC_mention_notifier.rb
Created September 8, 2010 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stammy/570759 to your computer and use it in GitHub Desktop.
Save stammy/570759 to your computer and use it in GitHub Desktop.
# PROBLEM: when someone replies to you publicly in an IRC channel you may not be
# notified of it if you are away from your computer. The common format for public
# replies looks like this:
#
# <jchris> maxo_: yeah mine is way better
#
# SOLUTION: Sign up for notifo as both a supplier and a consumer, and install the
# notifo app on your smartphone. Execute this in cron every minute to have new
# mentions sent to your phone as push notifications.
#
# This is configured for IRSSI style logs, you can tweak the pattern matching to
# match whatever logs you want
#
# You will also want to execute this once with the notifo.post line commented out
# so that it adds all vestigial mentions to the running list of mentions to ignore
require 'notifo'
require 'redis'
require 'digest/md5'
notifo = Notifo.new("NOTIFO_SUPPLIER_USERNAME","NOTIFO_SUPPLIER_SECRET")
redis = Redis.new
publics, privates = [], []
files.each do |file|
if file =~ /#/
publics << file
else
privates << {:name => file.split(PATH_TO_IRSSI_LOGS)[1].split('.log')[0], :file => file}
end
end
privates = privates.compact
publics.each do |file|
File.read(file).each_line do |line|
digest = Digest::MD5.hexdigest(line)
if line =~ /YOUR_IRC_USERNAME(,|:)/
unless redis.sismember "irc_notifications", digest
redis.sadd "irc_notifications", Digest::MD5.hexdigest(line)
notifo.post(NOTIFO_SUPPLIER_USERNAME,line)
end
end
end
end
privates.each do |pm|
File.read(pm[:file]).each_line do |line|
digest = Digest::MD5.hexdigest(line)
if line.include? "<#{pm[:name]}>"
unless redis.sismember "irc_notifications", digest
redis.sadd "irc_notifications", Digest::MD5.hexdigest(line)
notifo.post(NOTIFO_SUPPLIER_USERNAME,line)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment