Class: Cinch::UserManager

Inherits:
CacheManager show all
Defined in:
lib/cinch/user_manager.rb

Instance Method Summary collapse

Methods inherited from CacheManager

#each, #initialize

Constructor Details

This class inherits a constructor from Cinch::CacheManager

Instance Method Details

#delete(user) ⇒ Object

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.



56
57
58
# File 'lib/cinch/user_manager.rb', line 56

def delete(user)
  @cache.delete_if {|n, u| u == user }
end

#find(nick) ⇒ User?

Finds a user.

Parameters:

  • nick (String)

    nick of a user

Returns:



42
43
44
45
# File 'lib/cinch/user_manager.rb', line 42

def find(nick)
  downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
  @cache[downcased_nick]
end

#find_ensured(nick) ⇒ User #find_ensured(user, nick, host) ⇒ User

Finds or creates a user.

Overloads:

  • #find_ensured(nick) ⇒ User

    Finds or creates a user based on his nick.

    Parameters:

    • nick (String)

      The user’s nickname

    Returns:

  • #find_ensured(user, nick, host) ⇒ User

    Finds or creates a user based on his nick but already setting user and host.

    Parameters:

    • user (String)

      The username

    • nick (String)

      The nickname

    • host (String)

      The user’s hostname

    Returns:

Returns:

See Also:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cinch/user_manager.rb', line 21

def find_ensured(*args)
  case args.size
  when 1
    nick = args.first
    bargs = [nick]
  when 3
    nick = args[1]
    bargs = args
  else
    raise ArgumentError
  end
  downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
  @mutex.synchronize do
    @cache[downcased_nick] ||= User.new(*bargs, @bot)
  end
end

#update_nick(user) ⇒ Object

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.



48
49
50
51
52
53
# File 'lib/cinch/user_manager.rb', line 48

def update_nick(user)
  @mutex.synchronize do
    @cache[user.nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])] = user
    @cache.delete user.last_nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
  end
end