class BeerBot::Codecs::IRC::IRCMessage
This class represents an irc message broken down into its major constituent parts.
These include the prefix, command, parameters and trailing components of an irc message.
Constants
- CMD
This regexp captures the basic pattern used for prefixed and unprefixed irc commands sent by the server to a client.
See: tools.ietf.org/html/rfc1459.html sec 2.3.1
Public Class Methods
new(raw)
click to toggle source
# File lib/beerbot/02.codecs/irc.rb, line 155 def initialize raw @valid = false @has_prefix = false @user_prefix = false # message came from nick self[:prefix] = {} self[:command] = :unknown self[:raw] = raw self[:params] = [] self[:trailing] = nil if m = CMD.match(raw) then @valid = true if m[:prefix] then @has_prefix = true nick,host = m[:prefix].split('!') if host then @user_prefix = true user,host = host.split('@') self[:prefix][:nick] = nick self[:prefix][:user] = user self[:prefix][:host] = host else # It aint a user prefix, so just bung it in host for the # moment. self[:prefix][:host] = nick end end self[:command] = m[:command].strip params = if m[:params] then m[:params].strip else "" end self[:params] = params.split(/\s+/) self[:trailing]= m[:trailing].strip end end
Public Instance Methods
check(*syms)
click to toggle source
Check that syms exist in the hash otherwise return the missing sym.
# File lib/beerbot/02.codecs/irc.rb, line 213 def check *syms result = true syms.each{|sym| case sym when :prefix,:nick,:user,:host return :prefix unless self[:prefix] case sym when :prefix else return sym unless self[:prefix][sym] end else return sym unless self[sym] end } result end
prefix?()
click to toggle source
Is a prefixed irc string sent by server.
# File lib/beerbot/02.codecs/irc.rb, line 200 def prefix? @has_prefix end
user_prefix?()
click to toggle source
Is prefixed and the prefix is nick!~user@host .
# File lib/beerbot/02.codecs/irc.rb, line 206 def user_prefix? @user_prefix end
valid?()
click to toggle source
We couldn’t parse the command if not valid.
# File lib/beerbot/02.codecs/irc.rb, line 194 def valid? @valid end