Class: Syndi::IRC::Object::Entity
- Inherits:
-
Object
- Object
- Syndi::IRC::Object::Entity
- Defined in:
- lib/syndi/irc/object/entity.rb
Overview
A superclass which represents an IRC 'entity'; i.e., a channel or user. It acts as a base for User and Channel.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#irc ⇒ Syndi::IRC::Server
readonly
The IRC server on which this entity exists.
-
#name ⇒ String
readonly
The name of the entity.
Instance Method Summary collapse
-
#channel? ⇒ true, false
Whether we're a channel.
-
#initialize(irc, type, name) ⇒ Entity
constructor
New instance.
-
#msg(message, notice = false) ⇒ Object
Send a message to this entity.
-
#to_s ⇒ Object
def msg.
-
#user? ⇒ true, false
Whether we're a user.
Constructor Details
#initialize(irc, type, name) ⇒ Entity
New instance.
31 32 33 34 35 |
# File 'lib/syndi/irc/object/entity.rb', line 31 def initialize(irc, type, name) @irc = irc @entity_type = type @name = name end |
Instance Attribute Details
#irc ⇒ Syndi::IRC::Server (readonly)
Returns The IRC server on which this entity exists.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/syndi/irc/object/entity.rb', line 22 class Entity attr_reader :irc, :name # 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). def initialize(irc, type, name) @irc = irc @entity_type = type @name = name end # @return [true, false] Whether we're a channel. def channel? @entity_type == :channel ? true : false end # @return [true, false] Whether we're a user. def user? @entity_type == :user ? true : false end # Send a message to this entity. This will additionally divide messages # which are too long into multiple messages. # # This will call irc: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. def msg(, 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 :#{}\r\n" if raw.length > 512 msgs = [] = until raw.length <= 512 msgs << .slice!(0, 512-len) raw = ":#{@irc.nick}!#{@irc.user}@#{@irc.mask} #{command} #@name :#{}\r\n" end msgs.each { |m| @irc.snd "#{command} #@name :#{m}" } else @irc.snd "#{command} #@name :#{}" end $m.events.call 'irc:onMsg', self, end # def msg def to_s; @name; end end |
#name ⇒ String (readonly)
Returns The name of the entity.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/syndi/irc/object/entity.rb', line 22 class Entity attr_reader :irc, :name # 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). def initialize(irc, type, name) @irc = irc @entity_type = type @name = name end # @return [true, false] Whether we're a channel. def channel? @entity_type == :channel ? true : false end # @return [true, false] Whether we're a user. def user? @entity_type == :user ? true : false end # Send a message to this entity. This will additionally divide messages # which are too long into multiple messages. # # This will call irc: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. def msg(, 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 :#{}\r\n" if raw.length > 512 msgs = [] = until raw.length <= 512 msgs << .slice!(0, 512-len) raw = ":#{@irc.nick}!#{@irc.user}@#{@irc.mask} #{command} #@name :#{}\r\n" end msgs.each { |m| @irc.snd "#{command} #@name :#{m}" } else @irc.snd "#{command} #@name :#{}" end $m.events.call 'irc:onMsg', self, end # def msg def to_s; @name; end end |
Instance Method Details
#channel? ⇒ true, false
Returns Whether we're a channel.
38 39 40 |
# File 'lib/syndi/irc/object/entity.rb', line 38 def channel? @entity_type == :channel ? true : false end |
#msg(message, notice = false) ⇒ Object
Send a message to this entity. This will additionally divide messages which are too long into multiple messages.
This will call irc:onMsg with +self+ and +message+.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/syndi/irc/object/entity.rb', line 55 def msg(, 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 :#{}\r\n" if raw.length > 512 msgs = [] = until raw.length <= 512 msgs << .slice!(0, 512-len) raw = ":#{@irc.nick}!#{@irc.user}@#{@irc.mask} #{command} #@name :#{}\r\n" end msgs.each { |m| @irc.snd "#{command} #@name :#{m}" } else @irc.snd "#{command} #@name :#{}" end $m.events.call 'irc:onMsg', self, end |
#user? ⇒ true, false
Returns Whether we're a user.
43 44 45 |
# File 'lib/syndi/irc/object/entity.rb', line 43 def user? @entity_type == :user ? true : false end |