Sha256: 12ca55b789a4d4c661446eb89d55a66377d99e1569c4a0fb6dc15c70a90b6c16

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

#!ruby

require "ostruct"
require "socket"
require "thread"
require "logger"
require "monitor"

module Net; end

module Net::IRC
	VERSION = "0.0.7"
	class IRCException < StandardError; end

	require "net/irc/constants"
	require "net/irc/pattern"

	autoload :Message,   "net/irc/message"
	autoload :Client,    "net/irc/client"
	autoload :Server,    "net/irc/server"

	class Prefix < String
		def nick
			extract[0]
		end

		def user
			extract[1]
		end

		def host
			extract[2]
		end

		# Extract prefix string to [nick, user, host] Array.
		def extract
			_, *ret = *self.match(/^([^\s!]+)(?:!([^\s@]+)@(\S+))?$/)
			ret
		end
	end

	# Encoding to CTCP message. Prefix and postfix \x01.
	def ctcp_encoding(str)
		str = str.gsub(/\\/, "\\\\\\\\").gsub(/\x01/, '\a')
		str = str.gsub(/\x10/, "\x10\x10").gsub(/\x00/, "\x10\x30").gsub(/\x0d/, "\x10r").gsub(/\x0a/, "\x10n")
		"\x01#{str}\x01"
	end
	module_function :ctcp_encoding

	# Decoding to CTCP message. Remove \x01.
	def ctcp_decoding(str)
		str = str.gsub(/\x01/, "")
		str = str.gsub(/\x10n/, "\x0a").gsub(/\x10r/, "\x0d").gsub(/\x10\x30/, "\x00").gsub(/\x10\x10/, "\x10")
		str = str.gsub(/\\a/, "\x01").gsub(/\\\\/, "\\")
		str
	end
	module_function :ctcp_decoding
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
net-irc-0.0.7 lib/net/irc.rb