Class: IRC::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/rhuidean/client.rb

Overview

A simple data-holding class.

Constant Summary collapse

ORIGIN_RE =

constants

/^(.+)\!(.+)\@(.+)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, raw, origin, target, params) ⇒ Message

Creates a new Message. We use these to represent the old style of (char *origin, char *target, char *parv[]) in C.



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/rhuidean/client.rb', line 453

def initialize(client, raw, origin, target, params)
    # The IRC::Client that processed this message
    @client = client

    # If this is a CTCP, the type of CTCP
    @ctcp = nil

    # The originator of the message. Sometimes server, sometimes n!u@h
    @origin = origin

    # A space-tokenized array of anything after a colon
    @params = params

    # The full string from the IRC server
    @raw = raw

    # Usually the intended recipient; usually a user or channel
    @target = target

    # Is the origin a user? Let's make this a little more simple...
    if m = ORIGIN_RE.match(@origin)
        @origin_nick, @origin_user, @origin_host = m[1..3]
    end

    # Reformat it a bit if it's a CTCP.
    if @params and not @params.empty? and @params[0][0] == "\1"
        @params[-1].chop!
        @ctcp = @params.shift[1 .. -1].downcase.to_sym
    end
end

Instance Attribute Details

#clientObject (readonly)

instance attributes



446
447
448
# File 'lib/rhuidean/client.rb', line 446

def client
  @client
end

#ctcpObject (readonly)

instance attributes



446
447
448
# File 'lib/rhuidean/client.rb', line 446

def ctcp
  @ctcp
end

#originObject (readonly)

instance attributes



446
447
448
# File 'lib/rhuidean/client.rb', line 446

def origin
  @origin
end

#origin_hostObject (readonly)

Returns the value of attribute origin_host.



447
448
449
# File 'lib/rhuidean/client.rb', line 447

def origin_host
  @origin_host
end

#origin_nickObject (readonly)

Returns the value of attribute origin_nick.



447
448
449
# File 'lib/rhuidean/client.rb', line 447

def origin_nick
  @origin_nick
end

#origin_userObject (readonly)

Returns the value of attribute origin_user.



447
448
449
# File 'lib/rhuidean/client.rb', line 447

def origin_user
  @origin_user
end

#paramsObject (readonly)

instance attributes



446
447
448
# File 'lib/rhuidean/client.rb', line 446

def params
  @params
end

#rawObject (readonly)

instance attributes



446
447
448
# File 'lib/rhuidean/client.rb', line 446

def raw
  @raw
end

#targetObject (readonly)

instance attributes



446
447
448
# File 'lib/rhuidean/client.rb', line 446

def target
  @target
end

Instance Method Details

#action?Boolean

Was the message formatted as a CTCP action?


returns

true or false

Returns:

  • (Boolean)


511
512
513
# File 'lib/rhuidean/client.rb', line 511

def action?
    @ctcp == :action
end

#ctcp?Boolean

Was the message formatted as a CTCP message?


returns

true or false

Returns:

  • (Boolean)


502
503
504
# File 'lib/rhuidean/client.rb', line 502

def ctcp?
    @ctcp
end

#dcc?Boolean

Was the message formatted as a DCC notice?


returns

true or false

Returns:

  • (Boolean)


520
521
522
# File 'lib/rhuidean/client.rb', line 520

def dcc?
    @ctcp == :dcc
end

#to_channel?Boolean

Was the message sent to a channel?


returns

true or false

Returns:

  • (Boolean)


493
494
495
# File 'lib/rhuidean/client.rb', line 493

def to_channel?
    %w(# & !).include?(@target[0])
end