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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 15

def initialize(raw, source, target, message)
    super(raw)
    @source = source
    @target = target
    @ctcp = false
    @ctcp_type = nil
    @action = false
    if(@raw_content =~ /\x01(\S+)\s(.+)\x01/)
        @ctcp = true
        @ctcp_type = $1
        @message = $2
        @action = @ctcp_type.downcase == 'action'
    else
        @message = message
    end
    botnick = Models::Nick.filter(:botnick => true).first
    if(botnick)
        @addressed = @message =~ /^#{botnick.nick}/i
    else
        @addressed = false
    end
end

Instance Attribute Details

#ctcpObject (readonly)

message is CTCP



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

def ctcp
  @ctcp
end

#ctcp_typeObject (readonly)

message CTCP type



14
15
16
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 14

def ctcp_type
  @ctcp_type
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)


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

def addressed?
    return @addressed || is_private?
end

#is_action?Boolean

Is this message an action message

Returns:

  • (Boolean)


74
75
76
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 74

def is_action?
    @action
end

#is_colored?Boolean

Does the message contain colors

Returns:

  • (Boolean)


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

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

#is_ctcp?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 78

def is_ctcp?
    @ctcp
end

#is_dcc?Boolean

Is this a DCC message

Returns:

  • (Boolean)


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

def is_dcc?
    return @target.is_a?(String)
end

#is_private?Boolean

Is this is private message

Returns:

  • (Boolean)


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

def is_private?
    return !is_public?
end

#is_public?Boolean

Is this a public message

Returns:

  • (Boolean)


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

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

#message(color = false) ⇒ Object

the message sent



69
70
71
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 69

def message(color=false)
    return color ? @message : message_nocolor
end

#message_nocolorObject

Message with coloring stripped



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

def message_nocolor
    return @message.gsub(/\cC\d\d?(?:,\d\d?)?/, '').tr("\x00-\x1f", '')
end

#replytoObject

Convinence method for replying to the correct place



83
84
85
# File 'lib/mod_spox/messages/incoming/Privmsg.rb', line 83

def replyto
    return is_public? || is_dcc? ? @target : @source
end