Class: Cakewalk::UserList

Inherits:
CachedList show all
Defined in:
lib/cakewalk/user_list.rb

Overview

Note:

In prior versions, this class was called UserManager

Since:

  • 2.0.0

Version:

  • 1.1.0

Instance Method Summary collapse

Methods inherited from CachedList

#each, #initialize

Constructor Details

This class inherits a constructor from Cakewalk::CachedList

Instance Method Details

#delete(user)

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.

Since:

  • 2.0.0



83
84
85
# File 'lib/cakewalk/user_list.rb', line 83

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:

Since:

  • 2.0.0



61
62
63
64
65
66
67
68
69
70
# File 'lib/cakewalk/user_list.rb', line 61

def find(nick)
  if nick == @bot.nick
    return @bot
  end

  downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
  @mutex.synchronize do
    return @cache[downcased_nick]
  end
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 their nick.

    Parameters:

    • nick (String)

      The user’s nickname

    Returns:

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

    Finds or creates a user based on their 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:

Since:

  • 2.0.0



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cakewalk/user_list.rb', line 24

def find_ensured(*args)
  user, host = nil, nil
  case args.size
  when 1
    nick = args.first
    bargs = [nick]
  when 3
    nick = args[1]
    bargs = args
    user, _, host = bargs
  else
    raise ArgumentError
  end

  if nick == @bot.nick
    user_obj = @bot
  end

  downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
  @mutex.synchronize do
    if user_obj.nil?
      user_obj = @cache[downcased_nick] ||= User.new(*bargs, @bot)
    end
    if user && host
      # Explicitly set user and host whenever we request a User
      # object to update them on e.g. JOIN.
      user_obj.sync(:user, user, true)
      user_obj.sync(:host, host, true)
    end
    user_obj
  end
end

#update_nick(user)

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.

Since:

  • 2.0.0



74
75
76
77
78
79
# File 'lib/cakewalk/user_list.rb', line 74

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