Class: DiscordRDA::Role

Inherits:
Entity
  • Object
show all
Includes:
Comparable
Defined in:
lib/discord_rda/entity/role.rb

Overview

Represents a Discord role. Roles are guild-specific permission sets.

Instance Attribute Summary

Attributes inherited from Entity

#id

Instance Method Summary collapse

Methods inherited from Entity

#==, attribute, from_hash, #hash, #initialize, #inspect, #to_h, #to_json

Constructor Details

This class inherits a constructor from DiscordRDA::Entity

Instance Method Details

#<=>(other) ⇒ Integer

Compare roles by position

Parameters:

  • other (Role)

    Other role

Returns:

  • (Integer)

    Comparison result



131
132
133
# File 'lib/discord_rda/entity/role.rb', line 131

def <=>(other)
  other.position <=> position
end

#available_for_purchase?Boolean

Check if role is available for purchase

Returns:

  • (Boolean)

    True if available for purchase



118
119
120
# File 'lib/discord_rda/entity/role.rb', line 118

def available_for_purchase?
  tags&.key?('available_for_purchase')
end

#color_hexString

Get color as hex string

Returns:

  • (String)

    Hex color



70
71
72
# File 'lib/discord_rda/entity/role.rb', line 70

def color_hex
  color_object.to_s
end

#color_objectColor

Get color as Color object

Returns:



64
65
66
# File 'lib/discord_rda/entity/role.rb', line 64

def color_object
  Color.new(color)
end

#created_atTime

Get creation time

Returns:

  • (Time)

    Role creation time



153
154
155
# File 'lib/discord_rda/entity/role.rb', line 153

def created_at
  id.timestamp
end

#everyone?Boolean

Check if this is the @everyone role

Returns:

  • (Boolean)

    True if @everyone



52
53
54
# File 'lib/discord_rda/entity/role.rb', line 52

def everyone?
  name == '@everyone'
end

#guild_connections?Boolean

Check if role is a guild’s linked role

Returns:

  • (Boolean)

    True if linked role



124
125
126
# File 'lib/discord_rda/entity/role.rb', line 124

def guild_connections?
  tags&.key?('guild_connections')
end

#guild_idSnowflake?

Get the guild ID

Returns:



22
23
24
# File 'lib/discord_rda/entity/role.rb', line 22

def guild_id
  @raw_data['guild_id'] ? Snowflake.new(@raw_data['guild_id']) : nil
end

#higher_than?(other) ⇒ Boolean

Check if this role is higher than another

Parameters:

  • other (Role)

    Other role

Returns:

  • (Boolean)

    True if higher position



140
141
142
# File 'lib/discord_rda/entity/role.rb', line 140

def higher_than?(other)
  position > other.position
end

#hoisted?Boolean

Check if role is hoisted (shown separately in member list)

Returns:

  • (Boolean)

    True if hoisted



46
47
48
# File 'lib/discord_rda/entity/role.rb', line 46

def hoisted?
  hoist
end

#icon_url(format: 'png', size: nil) ⇒ String?

Get icon URL if role has custom icon

Parameters:

  • format (String) (defaults to: 'png')

    Image format

  • size (Integer) (defaults to: nil)

    Image size

Returns:

  • (String, nil)

    Icon URL or nil



84
85
86
87
88
89
90
# File 'lib/discord_rda/entity/role.rb', line 84

def icon_url(format: 'png', size: nil)
  return nil unless icon

  url = "https://cdn.discordapp.com/role-icons/#{guild_id}/#{id}/#{icon}.#{format}"
  url += "?size=#{size}" if size
  url
end

#integrated?Boolean

Check if role is integrated

Returns:

  • (Boolean)

    True if bot or integration role



100
101
102
# File 'lib/discord_rda/entity/role.rb', line 100

def integrated?
  tags&.key?('bot_id') || tags&.key?('integration_id')
end

#lower_than?(other) ⇒ Boolean

Check if this role is lower than another

Parameters:

  • other (Role)

    Other role

Returns:

  • (Boolean)

    True if lower position



147
148
149
# File 'lib/discord_rda/entity/role.rb', line 147

def lower_than?(other)
  position < other.position
end

#managed?Boolean

Check if role is managed by an integration

Returns:

  • (Boolean)

    True if managed



34
35
36
# File 'lib/discord_rda/entity/role.rb', line 34

def managed?
  managed
end

#mentionString

Get mention string for the role

Returns:

  • (String)

    Role mention



58
59
60
# File 'lib/discord_rda/entity/role.rb', line 58

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

#mentionable?Boolean

Check if role is mentionable

Returns:

  • (Boolean)

    True if mentionable



40
41
42
# File 'lib/discord_rda/entity/role.rb', line 40

def mentionable?
  mentionable
end

#permission_setPermission

Get permissions as Permission object

Returns:



28
29
30
# File 'lib/discord_rda/entity/role.rb', line 28

def permission_set
  Permission.new(permissions.to_i)
end

#premium_subscriber?Boolean

Check if role is a premium subscriber role

Returns:

  • (Boolean)

    True if premium subscriber role



106
107
108
# File 'lib/discord_rda/entity/role.rb', line 106

def premium_subscriber?
  tags&.key?('premium_subscriber')
end

#rgbArray<Integer>

Get RGB values

Returns:

  • (Array<Integer>)

    RGB array



76
77
78
# File 'lib/discord_rda/entity/role.rb', line 76

def rgb
  color_object.rgb
end

#role_tagsRoleTags

Get role tags

Returns:



94
95
96
# File 'lib/discord_rda/entity/role.rb', line 94

def role_tags
  RoleTags.new(tags || {})
end

#subscription_listing?Boolean

Check if role has a subscription listing

Returns:

  • (Boolean)

    True if subscription listing



112
113
114
# File 'lib/discord_rda/entity/role.rb', line 112

def subscription_listing?
  tags&.key?('subscription_listing_id')
end