Class: Cinch::User
- Inherits:
-
Target
- Object
- Target
- Cinch::User
- Includes:
- Syncable
- Defined in:
- lib/cinch/user.rb
Overview
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (String) authname
readonly
The current value of authname.
-
- (String?) away
readonly
The user’s away message, or
nilif not away. -
- (Array<Channel>) channels
readonly
All channels the user is in.
- - (Hash) data readonly
-
- (String) host
readonly
The current value of host.
-
- (Integer) idle
readonly
How long this user has been idle, in seconds.
-
- (Boolean) in_whois
private
-
- (String) last_nick
readonly
-
- (Boolean) monitored
(also: #monitored?)
True if the user is being monitored.
-
- (String) nick
readonly
The user’s nickname.
-
- (Object) online
(also: #online?)
unless #monitor is being used, this information cannot be ensured to be always correct.
-
- (Object) oper
(also: #oper?)
readonly
-
- (String) realname
readonly
The current value of realname.
-
- (Boolean) secure
(also: #secure?)
readonly
True if the user is using a secure connection, i.e.
-
- (Time) signed_on_at
readonly
The current value of signed_on_at.
-
- (Boolean) synced
(also: #synced?)
readonly
-
- (Boolean) unknown
(also: #unknown?)
readonly
True if the instance references an user who cannot be found on the server.
-
- (String) user
readonly
The current value of user.
Attributes inherited from Target
Instance Method Summary (collapse)
-
- (Object) attr(attribute, data = true, unsync = false)
-
- (Boolean) authed?
(also: #authenticated?)
Checks if the user is identified.
-
- dcc_send(io, filename = File.basename(io.path))
Send data via DCC SEND to a user.
-
- end_of_whois(values, not_found = false)
private
-
- (User) initialize(*args)
constructor
A new instance of User.
-
- (String) inspect
-
- (Mask) mask(s = "%n!%u@%h")
Generates a mask for the user.
-
- (Boolean) match(other)
(also: #=~)
Check if the user matches a mask.
-
- monitor
Starts monitoring a user’s online state by either using MONITOR or periodically running WHOIS.
-
- (String) to_s
-
- unmonitor
Stops monitoring a user’s online state.
-
- unsync_all
private
-
- update_nick(new_nick)
private
Used to update the user’s nick on nickchange events.
-
- whois
(also: #refresh)
Queries the IRC server for information on the user.
Methods included from Syncable
#attribute_synced?, #mark_as_synced, #sync, #unsync, #wait_until_synced
Methods inherited from Target
#<=>, #action, #concretize, #ctcp, #eql?, #msg, #notice, #safe_action, #safe_msg, #safe_notice
Constructor Details
- (User) initialize(*args)
A new instance of User
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/cinch/user.rb', line 185 def initialize(*args) @data = { :user => nil, :host => nil, :realname => nil, :authname => nil, :idle => 0, :signed_on_at => nil, :unknown? => false, :online? => false, :channels => [], :secure? => false, :away => nil, :oper? => false, } case args.size when 2 @name, @bot = args when 4 @data[:user], @name, @data[:host], @bot = args else raise ArgumentError end @synced_attributes = Set.new @when_requesting_synced_attribute = lambda {|attr| unless attribute_synced?(attr) @data[:unknown?] = false unsync :unknown? whois end } @monitored = false end |
Instance Attribute Details
- (String) authname (readonly)
The current value of authname
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def authname @authname end |
- (String?) away (readonly)
The user’s away message, or
nil if not away.
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def away @away end |
- (Array<Channel>) channels (readonly)
All channels the user is in.
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def channels @channels end |
- (Hash) data (readonly)
171 172 173 |
# File 'lib/cinch/user.rb', line 171 def data @data end |
- (String) host (readonly)
The current value of host
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def host @host end |
- (Integer) idle (readonly)
How long this user has been idle, in seconds. This is a snapshot of the last WHOIS.
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def idle @idle end |
- (Boolean) in_whois
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/cinch/user.rb', line 44 def in_whois @in_whois end |
- (String) last_nick (readonly)
35 36 37 |
# File 'lib/cinch/user.rb', line 35 def last_nick @last_nick end |
- (Boolean) monitored Also known as: monitored?
The attribute writer is in fact part of the private API
True if the user is being monitored
177 178 179 |
# File 'lib/cinch/user.rb', line 177 def monitored @monitored end |
- (String) nick (readonly)
The user’s nickname
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def nick @nick end |
- (Object) online Also known as: online?
This attribute will be updated by various events, but
unless #monitor is being used, this information cannot be ensured to be always correct.
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def online @online end |
- (Object) oper (readonly) Also known as: oper?
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def oper @oper end |
- (String) realname (readonly)
The current value of realname
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def realname @realname end |
- (Boolean) secure (readonly) Also known as: secure?
True if the user is using a secure connection, i.e. SSL.
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def secure @secure end |
- (Time) signed_on_at (readonly)
The current value of signed_on_at
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def signed_on_at @signed_on_at end |
- (Boolean) synced (readonly) Also known as: synced?
38 39 40 |
# File 'lib/cinch/user.rb', line 38 def synced @synced end |
- (Boolean) unknown (readonly) Also known as: unknown?
True if the instance references an user who cannot be found on the server.
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def unknown @unknown end |
- (String) user (readonly)
The current value of user
26 27 28 |
# File 'lib/cinch/user.rb', line 26 def user @user end |
Instance Method Details
- (Object) attr(attribute, data = true, unsync = false)
235 236 237 |
# File 'lib/cinch/user.rb', line 235 def attr(attribute, data = true, unsync = false) super end |
- (Boolean) authed? Also known as: authenticated?
Checks if the user is identified. Currently officially supports Quakenet and Freenode.
228 229 230 |
# File 'lib/cinch/user.rb', line 228 def authed? !attr(:authname).nil? end |
- dcc_send(io, filename = File.basename(io.path))
This method blocks.
This method returns an undefined value.
Send data via DCC SEND to a user.
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/cinch/user.rb', line 408 def dcc_send(io, filename = File.basename(io.path)) own_ip = bot.config.dcc.own_ip || @bot.irc.socket.addr[2] dcc = DCC::Outgoing::Send.new(receiver: self, filename: filename, io: io, own_ip: own_ip ) dcc.start_server handler = Handler.new(@bot, :message, Pattern.new(/^/, /\001DCC RESUME #{filename} #{dcc.port} (\d+)\001/, /$/)) do |m, position| next unless m.user == self dcc.seek(position.to_i) m.user.send "\001DCC ACCEPT #{filename} #{dcc.port} #{position}\001" handler.unregister end @bot.handlers.register(handler) @bot.loggers.info "DCC: Outgoing DCC SEND: File name: %s - Size: %dB - IP: %s - Port: %d - Status: waiting" % [filename, io.size, own_ip, dcc.port] dcc.send_handshake begin dcc.listen @bot.loggers.info "DCC: Outgoing DCC SEND: File name: %s - Size: %dB - IP: %s - Port: %d - Status: done" % [filename, io.size, own_ip, dcc.port] rescue Timeout::Error @bot.loggers.info "DCC: Outgoing DCC SEND: File name: %s - Size: %dB - IP: %s - Port: %d - Status: failed (timeout)" % [filename, io.size, own_ip, dcc.port] ensure handler.unregister end end |
- end_of_whois(values, not_found = false)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/cinch/user.rb', line 266 def end_of_whois(values, not_found = false) @in_whois = false if not_found sync(:unknown?, true, true) self.online = false sync(:idle, 0, true) sync(:channels, [], true) fields = @data.keys fields.delete(:unknown?) fields.delete(:idle) fields.delete(:channels) fields.each do |field| sync(field, nil, true) end return end if values.nil? # for some reason, we did not receive user information. one # reason is freenode throttling WHOIS Thread.new do sleep 2 whois end return end { :authname => nil, :idle => 0, :secure? => false, :oper? => false, :channels => [], }.merge(values).each do |attr, value| sync(attr, value, true) end sync(:unknown?, false, true) self.online = true end |
- (String) inspect
323 324 325 |
# File 'lib/cinch/user.rb', line 323 def inspect "#<User nick=#{@name.inspect}>" end |
- (Mask) mask(s = "%n!%u@%h")
Generates a mask for the user.
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/cinch/user.rb', line 338 def mask(s = "%n!%u@%h") s = s.gsub(/%(.)/) { case $1 when "n" @name when "u" self.user when "h" self.host when "r" self.realname when "a" self.authname end } Mask.new(s) end |
- (Boolean) match(other) Also known as: =~
Check if the user matches a mask.
361 362 363 |
# File 'lib/cinch/user.rb', line 361 def match(other) Mask.from(other) =~ Mask.from(self) end |
- monitor
This method returns an undefined value.
Starts monitoring a user’s online state by either using MONITOR or periodically running WHOIS.
372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/cinch/user.rb', line 372 def monitor if @bot.irc.isupport["MONITOR"] > 0 @bot.irc.send "MONITOR + #@name" else refresh @monitored_timer = Timer.new(@bot, interval: 30) { refresh } @monitored_timer.start end @monitored = true end |
- unmonitor
This method returns an undefined value.
Stops monitoring a user’s online state.
391 392 393 394 395 396 397 398 399 |
# File 'lib/cinch/user.rb', line 391 def unmonitor if @bot.irc.isupport["MONITOR"] > 0 @bot.irc.send "MONITOR - #@name" else @monitored_timer.stop if @monitored_timer end @monitored = false end |
- unsync_all
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
313 314 315 |
# File 'lib/cinch/user.rb', line 313 def unsync_all super end |
- update_nick(new_nick)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Used to update the user’s nick on nickchange events.
464 465 466 467 |
# File 'lib/cinch/user.rb', line 464 def update_nick(new_nick) @last_nick, @name = @name, new_nick @bot.user_list.update_nick(self) end |
- whois Also known as: refresh
This method returns an undefined value.
Queries the IRC server for information on the user. This will set the User’s state to not synced. After all information are received, the object will be set back to synced.
244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/cinch/user.rb', line 244 def whois return if @in_whois @data.keys.each do |attr| unsync attr end @in_whois = true if @bot.irc.network.whois_only_one_argument? @bot.irc.send "WHOIS #@name" else @bot.irc.send "WHOIS #@name #@name" end end |