Created
October 26, 2012 21:19
-
-
Save zuk/3961604 to your computer and use it in GitHub Desktop.
Someone Joined Room
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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