Class: ModSpox::Messages::Incoming::Privmsg

Inherits:
Message
  • Object
show all
Defined in:
lib/mod_spox/messages/incoming/Privmsg.rb

Direct Known Subclasses

Notice

Instance Attribute Summary collapse

Attributes inherited from Message

#raw_content, #time

Instance Method Summary collapse

Constructor Details

#initialize(raw, source, target, message) ⇒ Privmsg

Returns a new instance of Privmsg.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 13

def initialize(raw, source, target, message)
    super(raw)
    @source = source
    @target = target
    if(message =~ /^\001ACTION\s(.+)\001/)
        @message = $1
        @action = true
    else
        @message = message
        @action = false
    end
    botnick = Models::Nick.filter(:botnick => true).first
    if(botnick)
        @addressed = @message =~ /^#{botnick.nick}/i
    else
        @addressed = false
    end
end

Instance Attribute Details

#messageObject (readonly)

the message sent



12
13
14
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 12

def message
  @message
end

#sourceObject (readonly)

source of the message



8
9
10
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 8

def source
  @source
end

#targetObject (readonly)

target of the message



10
11
12
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 10

def target
  @target
end

Instance Method Details

#addressed?Boolean

Is message addressing the bot

Returns:

  • (Boolean)


33
34
35
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 33

def addressed?
    return @addressed || is_private?
end

#is_action?Boolean

Is this message an action message

Returns:

  • (Boolean)


58
59
60
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 58

def is_action?
    @action
end

#is_colored?Boolean

Does the message contain colors

Returns:

  • (Boolean)


48
49
50
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 48

def is_colored?
    return @message =~ /\cC\d\d?(?:,\d\d?)?/
end

#is_private?Boolean

Is this is private message

Returns:

  • (Boolean)


38
39
40
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 38

def is_private?
    return @target.is_a?(Models::Nick)
end

#is_public?Boolean

Is this a public message

Returns:

  • (Boolean)


43
44
45
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 43

def is_public?
    return @target.is_a?(Models::Channel)
end

#message_nocolorObject

Message with coloring stripped



53
54
55
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 53

def message_nocolor
    return @message.gsub(/\cC\d\d?(?:,\d\d?)?/, '')
end

#replytoObject

Convinence method for replying to the correct place



63
64
65
66
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 63

def replyto
    return @source if is_private?
    return @target if is_public?
end