Skip to content

Instantly share code, notes, and snippets.

@techbelly
Created August 12, 2012 18:51
Show Gist options
  • Save techbelly/3333673 to your computer and use it in GitHub Desktop.
Save techbelly/3333673 to your computer and use it in GitHub Desktop.
IF in campfire
#!/usr/bin/env ruby
require 'rubygems'
require 'tinder'
require 'open3'
require 'eventmachine'
# CHANGE THESE TO FIT
config = {
# CAMPFIRE USER DETAILS
:campfire_subdomain => 'techbelly',
:campfire_user => 'FROTZ',
:campfire_token => 'PUT YOUR TOKEN HERE, EVILDOERS',
:campfire_room_name => 'FICTIONAL',
# ZCODE DETAILS
:dfrotz => './dfrotz',
:game => './Wishbrin.z3'
}
# editing this on the server
campfire = Tinder::Campfire.new config[:campfire_subdomain], :token => config[:campfire_token]
room = campfire.find_room_by_name config[:campfire_room_name]
EventMachine::run do
frotzin, frotzout, frotzerr = Open3.popen3("#{config[:dfrotz]} -Z0 -w 3000 -p #{config[:game]}")
room.speak "FROTZ STARTED"
room.speak "Send messages to the game in ALL CAPS."
def send_message_to_game? msg
msg && msg == msg.upcase
end
Thread.new do
loop do
while output = select([frotzout,frotzerr],nil,nil,0.25)
output[0].each do |stream|
room.speak(stream.gets)
end
end
end
end
room.listen do |m|
message = m[:body]
frotzin.puts(message) if send_message_to_game?(message)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment