Class: YAIB::Bot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf) ⇒ Bot

Returns a new instance of Bot.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yaib/bot.rb', line 6

def initialize(conf)
    @config = conf
    @config.log.info("Connecting to IRC Server")
    @irc = IRC.new(config.server, config.port, config.nick, config.name, config.host, config.pass, config.log)
    @channels = {}
    @users = {}
    @listeners = []
    @commands = []
    @config.listeners.each do |responder|
        @listeners.push responder.new(config)
    end
    @config.commands.each do |responder|
        @commands.push responder.new(config)
    end
    @config.log.info("Joining Channels")
    config.channels.each do |channel|
        @channels[channel] = Channel.new(channel, self)
    end
    loop do
        recv
    end
end

Instance Attribute Details

#channelsObject

Returns the value of attribute channels.



3
4
5
# File 'lib/yaib/bot.rb', line 3

def channels
  @channels
end

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/yaib/bot.rb', line 4

def config
  @config
end

#ircObject (readonly)

Returns the value of attribute irc.



4
5
6
# File 'lib/yaib/bot.rb', line 4

def irc
  @irc
end

Instance Method Details

#recvObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/yaib/bot.rb', line 29

def recv
    msg = @irc.recv
    @config.log.info("Recieved: #{msg}")
    if msg =~ /PING/
        @irc.send("PONG #{@config.host}")
    else
        if msg.privmsg?
            msg = YAIB::Message.new(msg, self)
            @listeners.each do |listen|
                listen.listen(msg)
            end
            @commands.each do |cmd|
                if msg.message =~ /^#{config.prefix}#{cmd.matcher}/
                    cmd.execute(msg)
                end
            end
        end
    end
end

#return_user(inick, chan) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/yaib/bot.rb', line 49

def return_user(inick, chan)
    user = @users[inick]
    unless user
        user = User.new(inick, self)
        @users[inick] = user
    end
    user.channel = chan
    user
end