Class: Goblin

Inherits:
Object
  • Object
show all
Defined in:
lib/goblin.rb

Instance Method Summary collapse

Constructor Details

#initialize(messages, user, server, port) ⇒ Goblin

Returns a new instance of Goblin.



6
7
8
9
10
11
12
# File 'lib/goblin.rb', line 6

def initialize(messages, user, server, port)
  @messages = messages
  @user = user
  @socket = TCPSocket.open(server, port)
  say "Nick goblin_irc_thing"
  say "User ircbot 0 * IRCBot"
end

Instance Method Details

#quitObject



36
37
38
39
# File 'lib/goblin.rb', line 36

def quit
  say "PART ##{@channel} : Bye bye."
  say 'QUIT'
end

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/goblin.rb', line 23

def run
  until @socket.eof? do
    msg = @socket.gets
    puts msg

    if msg.match(/End\sof/)
      say_to_name
      quit
    end
  end
  @socket.close
end

#say(msg) ⇒ Object



14
15
16
17
# File 'lib/goblin.rb', line 14

def say(msg)
  puts msg
  @socket.puts msg
end

#say_to_nameObject



19
20
21
# File 'lib/goblin.rb', line 19

def say_to_name
  @messages.each {|n| say "PRIVMSG #{@user} :#{n}"}
end