Skip to content

Instantly share code, notes, and snippets.

@zuk
Created October 26, 2012 21:19
Show Gist options
  • Select an option

  • Save zuk/3961604 to your computer and use it in GitHub Desktop.

Select an option

Save zuk/3961604 to your computer and use it in GitHub Desktop.
Someone Joined Room
def initialize
@students = {}
end
someone_joined_room do |stanza|
stu = lookup_student(Util.extract_login(stanza.from), true) unless stanza.from == agent_jid_in_room
if stu
log "#{stu} joined #{config[:room]}"
end
end
def lookup_student(username)
stu = @students[username]
if stu.nil?
log "Looking up user #{username.inspect} in Rollcall..."
begin
stu = Rollcall::User.find(username)
rescue ActiveResource::ResourceNotFound
log "#{username.inspect} not found in Rollcall..."
return nil
end
unless stu.kind == "Student"
log "#{username.inspect} is not a student; will be ignored."
return nil
end
log "#{username.inspect} loaded in state #{stu.state}"
@students[username] = stu
end
return stu
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment