Skip to content

Instantly share code, notes, and snippets.

@techbelly
Created August 12, 2012 18:51

Revisions

  1. techbelly created this gist Aug 12, 2012.
    48 changes: 48 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    #!/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