Class: Cinch::Plugins::TinyChat

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/tiny_chat.rb

Instance Method Summary collapse

Instance Method Details

#execute(m, room) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cinch/plugins/tiny_chat.rb', line 20

def execute(m, room)
   = "0,12TinyChat"
  query  = URI::encode(room)
  doc    = Nokogiri::XML(open("http://tinychat.apigee.com/#{query}.xml").read)

  online       = doc.css("names").collect{|j| j.inner_text}.join(', ')
  onlineCount  = doc.root["total_count"]
  roomName     = doc.root["name"]

  url = "http://tinychat.com/#{roomName}"

  onlineCount = onlineCount.to_i

  if doc.root["message"]
    begin
      eMessage = doc.root["message"]
      raise "Error: #{eMessage}"
    rescue
      m.reply "#{} || I have been given an error of: \"#{$!}\"! Please contact my master."
    end
    return
  end

  m.reply "There's #{onlineCount} user in #{roomName}. | User: #{online} | #{} URL: #{url}" if onlineCount == 1

  m.reply "There's #{onlineCount} users in #{roomName}. | Users: #{online} | #{} URL: #{url}" if onlineCount >= 2

  m.reply "There are no users in #{roomName}. | #{} URL: #{url}" if onlineCount == 0
end