Method: Autumn::Stem#initialize
- Defined in:
- lib/autumn/stem.rb
#initialize(server, newnick, opts) ⇒ Stem
Creates an instance that connects to a given IRC server and requests a given nick. Valid options:
port-
The port that the IRC client should connect on (default 6667).
local_ip-
Set this if you want to bind to an IP other than your default (for virtual hosting).
logger-
Specifies a logger instance to use. If none is specified, a new LogFacade instance is created for the current season.
ssl-
If true, indicates that the connection will be made over SSL.
user-
The username to transmit to the IRC server (by default it’s the user’s nick).
name-
The real name to transmit to the IRC server (by default it’s the user’s nick).
server_password-
The server password (not the nick password), if necessary.
password-
The password to send to NickServ, if your leaf’s nick is registered.
channel-
The name of a channel to join.
channels-
An array of channel names to join.
sever_type-
The name of the server type. (See Daemon). If left blank, the default Daemon instance is used.
rejoin-
If true, the stem will rejoin a channel it is kicked from.
case_sensitive_channel_names-
If true, indicates to the IRC client that this IRC server uses case-sensitive channel names.
dont_ghost-
If true, does not issue a /ghost command if the stem’s nick is taken. (This is only relevant if the nick is registered and
passwordis specified.) You should use this on IRC servers that don’t use “NickServ” – otherwise someone may change their nick to NickServ and discover your password! ghost_without_password-
Set this to true if your IRC server uses hostname authentication instead of password authentication for GHOST commands.
throttle-
If enabled, the stem will throttle large amounts of simultaneous messages.
throttle_rate-
Sets the number of seconds that pass between consecutive PRIVMSG’s when the leaf’s output is throttled.
throttle_threshold-
Sets the number of simultaneous messages that must be queued before the leaf begins throttling output.
Any channel name can be a one-item hash, in which case it is taken to be a channel name-channel password association.
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/autumn/stem.rb', line 290 def initialize(server, newnick, opts) raise ArgumentError, "Please specify at least one channel" unless opts[:channel] or opts[:channels] @nick = newnick @server = server @port = opts[:port] @port ||= 6667 @local_ip = opts[:local_ip] = opts @listeners = Set.new @listeners << self @logger = [:logger] @nick_generator = Proc.new do |oldnick| if [:ghost_without_password] then "GHOST #{oldnick}", 'NickServ' nil elsif [:dont_ghost] or [:password].nil? then "#{oldnick}_" else "GHOST #{oldnick} #{options[:password]}", 'NickServ' nil end end @server_type = Daemon[opts[:server_type]] @server_type ||= Daemon.default @throttle_rate = opts[:throttle_rate] @throttle_rate ||= 1 @throttle_threshold = opts[:throttle_threshold] @throttle_threshold ||= 5 @nick_regex = (opts[:nick_regex] ? opts[:nick_regex] : NICK_REGEX) @channels = Set.new @channels.merge opts[:channels] if opts[:channels] @channels << opts[:channel] if opts[:channel] @channels.map! do |chan| if chan.kind_of? Hash then { normalized_channel_name(chan.keys.only) => chan.values.only } else normalized_channel_name chan end end # Make a hash of channels to their passwords @channel_passwords = @channels.select { |ch| ch.kind_of? Hash }.mash { |pair| pair } # Strip the passwords from @channels, making it an array of channel names only @channels.map! { |chan| chan.kind_of?(Hash) ? chan.keys.only : chan } @channel_members = Hash.new @updating_channel_members = Hash.new # stores the NAMES list as its being built if @throttle = opts[:throttle] then = Queue.new = Thread.new do throttled = false loop do args = .pop throttled = true if not throttled and .length >= @throttle_threshold throttled = false if throttled and .empty? sleep @throttle_rate if throttled privmsg *args end end end @chan_mutex = Mutex.new @join_mutex = Mutex.new @socket_mutex = Mutex.new end |