Class: Flexo::Events::PrivmsgEvent

Inherits:
Flexo::Event show all
Defined in:
lib/flexo/events/privmsg.rb

Overview

Private messages, which, in fact, isn’t neccessarily private. When the target of a privmsg is a channel, it’s displayed to the entire channel. Which isn’t very private at all.

Direct Known Subclasses

NoticeEvent

Instance Attribute Summary collapse

Attributes inherited from Flexo::Event

#data, #nickname

Instance Method Summary collapse

Methods inherited from Flexo::Event

#me?

Constructor Details

#initialize(*args) ⇒ PrivmsgEvent

Returns a new instance of PrivmsgEvent.



12
13
14
15
16
17
18
# File 'lib/flexo/events/privmsg.rb', line 12

def initialize(*args)
  super
  @sender = @data.hostmask.nick if @data.hostmask
  @target = @data.params[0]
  @ctcp   = (m = @data.string.match(/^\x01(.+?)\x01$/)) ? true : false
  @text   = @ctcp ? m[1] : @data.string
end

Instance Attribute Details

#senderObject (readonly) Also known as: from

Returns the value of attribute sender.



7
8
9
# File 'lib/flexo/events/privmsg.rb', line 7

def sender
  @sender
end

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'lib/flexo/events/privmsg.rb', line 8

def target
  @target
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/flexo/events/privmsg.rb', line 9

def text
  @text
end

Instance Method Details

#ctcp?Boolean

Returns true if this was a CTCP-message, and false if not.

Returns:

  • (Boolean)


21
22
23
# File 'lib/flexo/events/privmsg.rb', line 21

def ctcp?
  return @ctcp
end

#reply(text, to_channel = true) ⇒ Object

Sends a quick reply to the message. If to_channel is false, it’s sent to the person who sent the message, whether he sent it to a channel, or private. If it was sent to you, this will send a direct reply no matter what to_channel is set to.



40
41
42
43
# File 'lib/flexo/events/privmsg.rb', line 40

def reply(text, to_channel=true)
  target = (to_channel && to_channel?) ? @target : @sender
  @manager.sender.privmsg(target, text)
end

#to_channel?Boolean

Sent to a channel, or was it actually a private message?

Returns:

  • (Boolean)


31
32
33
# File 'lib/flexo/events/privmsg.rb', line 31

def to_channel?
  return Flexo::Constants::CHANPREFIX.include?(@target[0..0])
end

#to_me?Boolean

Were you the target of the message?

Returns:

  • (Boolean)


26
27
28
# File 'lib/flexo/events/privmsg.rb', line 26

def to_me?
  return @target == @manager.nickname # FIXME: Should this be stored here?
end