Class: YAIB::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rawmsg, bot) ⇒ Message

Returns a new instance of Message.



5
6
7
8
9
10
11
12
13
14
# File 'lib/yaib/message.rb', line 5

def initialize(rawmsg, bot)
    @message, rawchan, rawuser = parse(rawmsg)
    if rawchan == bot.config.nick then
        @channel = bot.return_user rawuser, rawuser
        @user = @channel
    else
        @channel = bot.channels[rawchan]
        @user = bot.return_user rawuser, rawchan
    end
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



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

def channel
  @channel
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

Instance Method Details

#parse(rawmsg) ⇒ Object



16
17
18
# File 'lib/yaib/message.rb', line 16

def parse(rawmsg)
    [rawmsg.scan(/.* PRIVMSG .*? \:(.*)/).join, rawmsg.scan(/.* PRIVMSG (.*?) \:.*/).join, rawmsg.split(/\!/)[0].sub(/^\:/,'')]
end

#privmsg(s) ⇒ Object



20
21
22
# File 'lib/yaib/message.rb', line 20

def privmsg(s)
    @channel.privmsg(s)
end