Module: Rubycord::UserAttributes

Included in:
Light::LightProfile, User
Defined in:
lib/rubycord/data/user.rb

Overview

Mixin for the attributes users should have

Constant Summary collapse

FLAGS =

Types of user's account flags mapped to their API value.

{
  staff: 1 << 0,
  partner: 1 << 1,
  hypesquad: 1 << 2,
  bug_hunter_level_1: 1 << 3,
  hypesquad_online_house_1: 1 << 6,
  hypesquad_online_house_2: 1 << 7,
  hypesquad_online_house_3: 1 << 8,
  premium_early_supporter: 1 << 9,
  team_pseudo_user: 1 << 10,
  bug_hunter_level_2: 1 << 14,
  verified_bot: 1 << 16,
  verified_developer: 1 << 17,
  certified_moderator: 1 << 18,
  bot_http_interactions: 1 << 19,
  active_developer: 1 << 22
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#avatar_idString

Returns the ID of this user's current avatar, can be used to generate an avatar URL.

Returns:

  • (String)

    the ID of this user's current avatar, can be used to generate an avatar URL.

See Also:



47
48
49
# File 'lib/rubycord/data/user.rb', line 47

def avatar_id
  @avatar_id
end

#bot_accounttrue, false (readonly) Also known as: bot_account?

Returns whether this user is a Discord bot account.

Returns:

  • (true, false)

    whether this user is a Discord bot account



37
38
39
# File 'lib/rubycord/data/user.rb', line 37

def 
  @bot_account
end

#discriminatorString (readonly) Also known as: discrim, tag, discord_tag

Returns this user's discriminator which is used internally to identify users with identical usernames.

Returns:

  • (String)

    this user's discriminator which is used internally to identify users with identical usernames.



31
32
33
# File 'lib/rubycord/data/user.rb', line 31

def discriminator
  @discriminator
end

#global_nameString? (readonly)

Returns this user's global name.

Returns:

  • (String, nil)

    this user's global name



28
29
30
# File 'lib/rubycord/data/user.rb', line 28

def global_name
  @global_name
end

#public_flagsInteger (readonly)

Returns the public flags on a user's account.

Returns:

  • (Integer)

    the public flags on a user's account



87
88
89
# File 'lib/rubycord/data/user.rb', line 87

def public_flags
  @public_flags
end

#usernameString (readonly) Also known as: name

Returns this user's username.

Returns:

  • (String)

    this user's username



24
25
26
# File 'lib/rubycord/data/user.rb', line 24

def username
  @username
end

#webhook_accounttrue, false (readonly) Also known as: webhook_account?, webhook?

Returns whether this is fake user for a webhook message.

Returns:

  • (true, false)

    whether this is fake user for a webhook message



41
42
43
# File 'lib/rubycord/data/user.rb', line 41

def 
  @webhook_account
end

Instance Method Details

#avatar_url(format = nil) ⇒ String

Utility function to get a user's avatar URL. TODO: Maybe change this method again after discriminator removal ?

Parameters:

  • format (String, nil) (defaults to: nil)

    If nil, the URL will default to webp for static avatars, and will detect if the user has a gif avatar. You can otherwise specify one of webp, jpg, png, or gif to override this. Will always be PNG for default avatars.

Returns:

  • (String)

    the URL to the avatar image.



76
77
78
79
80
81
82
83
84
# File 'lib/rubycord/data/user.rb', line 76

def avatar_url(format = nil)
  unless @avatar_id
    return API::User.default_avatar(@discriminator, legacy: true) if @discriminator && @discriminator != "0"

    return API::User.default_avatar(@id)
  end

  API::User.avatar_url(@id, @avatar_id, format)
end

#display_nameString

Utility function to get Discord's display name of a user not in server

Returns:

  • (String)

    the name the user displays as (global_name if they have one, username otherwise)



51
52
53
# File 'lib/rubycord/data/user.rb', line 51

def display_name
  global_name || username
end

#distinctString

Utility function to get Discord's distinct representation of a user, i.e. username + discriminator TODO: Maybe change this method again after discriminator removal ?

Returns:

  • (String)

    distinct representation of user



64
65
66
67
68
69
70
# File 'lib/rubycord/data/user.rb', line 64

def distinct
  if @discriminator && @discriminator != "0"
    "#{@username}##{@discriminator}"
  else
    @username.to_s
  end
end

#mentionString

Utility function to mention users in messages

Returns:

  • (String)

    the mention code in the form of <@id>



57
58
59
# File 'lib/rubycord/data/user.rb', line 57

def mention
  "<@#{@id}>"
end