class Syndi::IRC::Object::Entity
A superclass which represents an IRC
'entity'; i.e., a channel or user. It acts as a base for {Syndi::IRC::Object::User} and {Syndi::IRC::Object::Channel}.
@api IRC
@since 4.0.0 @author noxgirl
@!attribute [r] irc
@return [Syndi::IRC::Server] The IRC server on which this entity exists.
@!attribute [r] name
@return [String] The name of the entity.
Attributes
Public Class Methods
New instance.
@param [Syndi::IRC::Server] irc The server. @param [Symbol] type Either :channel
or :user
. @param [String] name The name of this entity (nickname or channel name).
# File lib/syndi/irc/object/entity.rb, line 31 def initialize(irc, type, name) @irc = irc @entity_type = type @name = name end
Public Instance Methods
@return [true, false] Whether we're a channel.
# File lib/syndi/irc/object/entity.rb, line 38 def channel? @entity_type == :channel ? true : false end
Send a message to this entity. This will additionally divide messages which are too long into multiple messages.
This will call onMsg with self
and message
.
@param [String] message The message. @param [true, false] notice Whether this should be a /notice as opposed
to a /msg.
# File lib/syndi/irc/object/entity.rb, line 55 def msg(message, notice=false) command = (notice == false ? 'PRIVMSG' : 'NOTICE') len = ":#{@irc.nick}!#{@irc.user}@#{@irc.mask} #{command} #@name :".length raw = ":#{@irc.nick}!#{@irc.user}@#{@irc.mask} #{command} #@name :#{message}\r\n" if raw.length > 512 msgs = [] nmessage = message until raw.length <= 512 msgs << nmessage.slice!(0, 512-len) raw = ":#{@irc.nick}!#{@irc.user}@#{@irc.mask} #{command} #@name :#{nmessage}\r\n" end msgs.each { |m| @irc.snd "#{command} #@name :#{m}" } else @irc.snd "#{command} #@name :#{message}" end $m.events.call 'irc:onMsg', self, message end
# File lib/syndi/irc/object/entity.rb, line 80 def to_s; @name; end
@return [true, false] Whether we're a user.
# File lib/syndi/irc/object/entity.rb, line 43 def user? @entity_type == :user ? true : false end