Ruby Omegle Gem
About
This is a pure ruby implementation of the Omegle API. It is an update of the ruby-omegle gem that works and supports all omegle features (as of Feb 2013), except for webcam support. Currently, the gem supports:
- Ordinary ’text’ mode, where you chat with a single stranger.
- Topic-based text mode, where Omegle tries to match your various interests with other people.
- Ask mode, where strangers will ask you a question, and get to see you talk about it with someone else
- Spy mode, where you get to ask two people a question, and watch them talk.
Download
To download, simply use gem install -r romegle, or you can get the source over at the git page.
Use
Using the gem is simple enough, and follows a basic system of establishing a session with Omegle, then processing events in a loop until they cease. Using the system to talk requires some knowledge of threading, since you must talk as well as listen to events.
In basic terms, the gem interacts with Omegle.com and maintains an ordered list of events. These events may then be pulled out of the session object and processed. The Omegle class is thread-safe, so can be used to send/check for events in two threads.
Options Reference
The options hash may contain:
{ :question => "What flavour is blue?" # What question to ask? Setting this puts the thing in spy mode.
:answer => true # boolean. Set to true if you wish to be ASKED a question by someone else.
:topic => ["topic1", "topic2"...] # An array of topics to chat about, using omegle's topic matching feature.
:host => "http://www.omegle.com" # the hostname (don't change this without good reason)
:headers => {"key" => "value"} # HTTP headers to send with every call (i.e. UA spoofing)
}
Example Usage
% irb
irb(main):001:0> require 'omegle'
=> true
irb(main):002:0> o = Omegle.new(:question => "How much would wood a wouldchuck chuck if a wouldchuck could use homophones?")
=> #<Omegle:0x000000025bc5a0 @mx=#<Mutex:0x000000025bc528>, @options={:host=>"omegle.com", :question=>"How much would wood a wouldchuck chuck if a wouldchuck could use homophones?", :topics=>nil, :answer=>false, :headers=>{"referer"=>"http://omegle.com"}}, @events=[]>
irb(main):003:0> o.start; o.listen{|e| puts e.to_s }; o.disconnect
["waiting"]
["connected"]
["question", "How much would wood a wouldchuck chuck if a wouldchuck could use homophones?"]
["spyStoppedTyping", "Stranger 1"]
["spyTyping", "Stranger 2"]
["spyMessage", "Stranger 2", "LOL"]
["spyTyping", "Stranger 2"]
["spyMessage", "Stranger 2", "dam some of these questions"]
["spyTyping", "Stranger 2"]
["spyMessage", "Stranger 2", "are really dam good"]
["spyTyping", "Stranger 2"]
["spyMessage", "Stranger 2", "XD"]
["spyDisconnected", "Stranger 2"]
=> nil
In the above, we construct a new omegle session and set its options. We then create a thread to consume events (and simply dump them to screen) whilst we consume STDIN to send to the stranger.
Note that, if using ‘spy mode’ (enabled using :question in the options), it’s not possible to send data to Omegle.