Skip to content

Instantly share code, notes, and snippets.

@sunlightlabs
Created September 1, 2009 16:01
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 sunlightlabs/179178 to your computer and use it in GitHub Desktop.
Save sunlightlabs/179178 to your computer and use it in GitHub Desktop.
### Taken from http://blog.pothoven.net/2008/09/campfire-activity-notifier-for-gnome.html
### Posted here in case that site disappears, and so I can find it more easily
#!/usr/bin/env ruby
# == Synopsis
# Program to monitor a campfire chat room
# Modified from code provided at: http://www.snailbyte.com/2007/09/13/campfire-activity-notifier-for-kde/
#
# == Usage
# campfireMonitor [roomName] [roomName] ...
#
# == Author
# Steven Pothoven and Snailbyte Ltd.
require 'rubygems'
require 'tinder'
require "cgi"
class App
VERSION = '0.1.1'
def initialize arguments, stdin
# default settings
campfireSubdomain = 'mySubdomain'
campfireUsername = 'user@email.com'
campfirePassword = 'password'
roomNames = ['Room1', 'Room2']
if arguments.length > 0
roomNames = arguments
end
@ui = 'gnome'
@campfireIconPath = '/path/to/campfire-logo.png'
# define you favorite audio player and audio file here for audio notifications
@soundCommand = 'mplayer /usr/share/sounds/pop.wav'
@campfire = Tinder::Campfire.new campfireSubdomain
if @campfire.login campfireUsername, campfirePassword
alert nil, "CampfireMonitor", "Successfully logged in #{campfireUsername}"
@rooms = roomNames.collect { |roomName| @campfire.find_room_by_name roomName }
# remove any invalid rooms
@rooms.delete(nil);
@rooms.each do |room|
notify room, "CampfireMonitor", "Entered room."
notify room, "CampfireMonitor", "Topic is: #{room.topic}.".gsub("'","")
notify room, "CampfireMonitor", "Current users are: #{room.users}.".gsub("'","")
end
else
alert nil, "CampfireMonitor", "Failed to log in #{campfireUsername}"
end
end
# display notifcation message
def notify room, user, msg
if msg and msg.size > 0
msg = CGI.unescapeHTML(msg);
if @ui == 'kde'
system "dcop knotify default notify eventname \'#{user}\' \'#{''+room.name+': ' unless room.nil?} #{msg}\' '' '' 16 2"
elsif @ui == 'gnome'
system "notify-send -i #{@campfireIconPath} '#{user}' '#{''+room.name+': ' unless room.nil?} #{msg}'"
else
puts "#{room.name+':' unless room.nil?}#{user} - #{msg}"
end
end
end
# notify with sound
def alert room, user, msg
notify room, user, msg
if @soundCommand and @soundCommand.length > 0
system @soundCommand
end
end
def run
# first get any missed messages for today
threads = []
@rooms.each do |room|
thread = Thread.new do
room.transcript(Date.today).last(3).each do |m|
if !m.nil? and m[:message] and m[:message].size > 1
notify room, m[:person], m[:message].gsub("'","")
end
end
end
threads << thread
end
threads.each { |thread| thread.join}
# listen for more messages
threads = []
@rooms.each do |room|
thread = Thread.new do
notify room, "CampfireMonitor", "Waiting for messages..."
room.listen do |m|
if !m.nil? and m[:message].size > 1
unless m[:person] == "Ad"
alert room, m[:person], m[:message].gsub("'","")
end
end
end
end
threads << thread
end
threads.each { |thread| thread.join}
end
end
app = App.new(ARGV, STDIN)
app.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment