Class: ShoutBot

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/shout-bot/lib/shout-bot.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, port, nick, password = nil) {|_self| ... } ⇒ ShoutBot

Returns a new instance of ShoutBot.

Yields:

  • (_self)

Yield Parameters:

  • _self (ShoutBot)

    the object that the method was called on

Raises:



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vendor/shout-bot/lib/shout-bot.rb', line 50

def initialize(server, port, nick, password=nil)
  raise ArgumentError unless block_given?

  @socket = TCPSocket.open(server, port || 6667)
  @socket.puts "PASSWORD #{password}" if password
  @socket.puts "NICK #{nick}"
  @socket.puts "USER #{nick} #{nick} #{nick} :#{nick}"
  sleep 1
  yield self
  @socket.puts "QUIT"
  @socket.gets until @socket.eof?
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



48
49
50
# File 'lib/vendor/shout-bot/lib/shout-bot.rb', line 48

def channel
  @channel
end

Class Method Details

.shout(uri, &block) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vendor/shout-bot/lib/shout-bot.rb', line 34

def self.shout(uri, &block)
  raise ArgumentError unless block_given?

  uri = Addressable::URI.parse(uri)
  irc = new(uri.host, uri.port, uri.user, uri.password) do |irc|
    if channel = uri.fragment
      irc.join(channel, &block)
    else
      irc.channel = uri.path[1..-1]
      yield irc
    end
  end
end

Instance Method Details

#join(channel) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (ShoutBot)

    the object that the method was called on

Raises:



63
64
65
66
67
68
69
70
# File 'lib/vendor/shout-bot/lib/shout-bot.rb', line 63

def join(channel)
  raise ArgumentError unless block_given?

  @channel = "##{channel}"
  @socket.puts "JOIN #{@channel}"
  yield self
  @socket.puts "PART #{@channel}"
end

#say(message) ⇒ Object



72
73
74
75
# File 'lib/vendor/shout-bot/lib/shout-bot.rb', line 72

def say(message)
  return unless @channel
  @socket.puts "PRIVMSG #{@channel} :#{message}"
end