Skip to content

Instantly share code, notes, and snippets.

@jrk
Created May 2, 2009 18:53
Show Gist options
  • Save jrk/105668 to your computer and use it in GitHub Desktop.
Save jrk/105668 to your computer and use it in GitHub Desktop.
Simple Campfire-Jabber relay daemon in Ruby

From http://superjared.com/entry/new-projects/#campfire_to_jabber

A proxy between Campfire and Jabber. Built in Ruby using Tinder and xmpp4r-simple to utilize Campfire and Jabber respectively. It also uses the "daemons" gem to spawn a long-running process. For each Campfire room in which you want to chat, you must also create a Jabber user, which was simple since I run my own Jabber server.

To install, first install the required gems:

sudo gem install tinder xmpp4r-simple daemons

Then place camper.rb in a place you don’t mind seeing .pid files, and configure it accordingly. Keep in mind that you can run several chats from the single configuration. Once configured, you should be able to start and stop the daemon:

ruby camper.rb start
ruby camper.rb stop
# The MIT License
#
# Copyright (c) 2008 Jared Kuolt
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# Version: 0.1, Feb 5 2008
require 'rubygems'
require 'tinder'
require 'xmpp4r-simple'
require 'daemons'
deliver_to = 'me@example.com'
rooms = [
{
:jabber => {:user => 'myoffice@example.com',:pass => 'mypassword'},
:campfire => {:user => 'user@example.com', :pass => 'anotherpassword', :room => "Chat Room", :domain => 'example', :ssl => true}
},
]
rooms.each do |room|
Daemons.run_proc(room[:campfire][:room]) do
im = Jabber::Simple.new(room[:jabber][:user], room[:jabber][:pass])
campfire = Tinder::Campfire.new room[:campfire][:domain], :ssl => room[:campfire][:ssl]
campfire.login room[:campfire][:user], room[:campfire][:pass]
chat = campfire.find_room_by_name room[:campfire][:room]
while true
chat.listen.each do |msg|
text = "#{msg[:person]}: #{msg[:message]}".gsub(/(\\n)+/, "\n").gsub(/\\u003C(.+?)\\u003E/, '')
im.deliver(deliver_to, text) if msg[:person].to_s != ''
end
im.received_messages { |msg| chat.speak msg.body if msg.type == :chat }
sleep 2
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment