Class: DiscordRDA::Role
- 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
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compare roles by position.
-
#available_for_purchase? ⇒ Boolean
Check if role is available for purchase.
-
#color_hex ⇒ String
Get color as hex string.
-
#color_object ⇒ Color
Get color as Color object.
-
#created_at ⇒ Time
Get creation time.
-
#everyone? ⇒ Boolean
Check if this is the @everyone role.
-
#guild_connections? ⇒ Boolean
Check if role is a guild’s linked role.
-
#guild_id ⇒ Snowflake?
Get the guild ID.
-
#higher_than?(other) ⇒ Boolean
Check if this role is higher than another.
-
#hoisted? ⇒ Boolean
Check if role is hoisted (shown separately in member list).
-
#icon_url(format: 'png', size: nil) ⇒ String?
Get icon URL if role has custom icon.
-
#integrated? ⇒ Boolean
Check if role is integrated.
-
#lower_than?(other) ⇒ Boolean
Check if this role is lower than another.
-
#managed? ⇒ Boolean
Check if role is managed by an integration.
-
#mention ⇒ String
Get mention string for the role.
-
#mentionable? ⇒ Boolean
Check if role is mentionable.
-
#permission_set ⇒ Permission
Get permissions as Permission object.
-
#premium_subscriber? ⇒ Boolean
Check if role is a premium subscriber role.
-
#rgb ⇒ Array<Integer>
Get RGB values.
-
#role_tags ⇒ RoleTags
Get role tags.
-
#subscription_listing? ⇒ Boolean
Check if role has a subscription listing.
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
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
118 119 120 |
# File 'lib/discord_rda/entity/role.rb', line 118 def available_for_purchase? &.key?('available_for_purchase') end |
#color_hex ⇒ String
Get color as hex string
70 71 72 |
# File 'lib/discord_rda/entity/role.rb', line 70 def color_hex color_object.to_s end |
#color_object ⇒ Color
Get color as Color object
64 65 66 |
# File 'lib/discord_rda/entity/role.rb', line 64 def color_object Color.new(color) end |
#created_at ⇒ Time
Get creation time
153 154 155 |
# File 'lib/discord_rda/entity/role.rb', line 153 def created_at id. end |
#everyone? ⇒ Boolean
Check if this is the @everyone role
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
124 125 126 |
# File 'lib/discord_rda/entity/role.rb', line 124 def guild_connections? &.key?('guild_connections') end |
#guild_id ⇒ Snowflake?
Get the guild ID
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
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)
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
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
100 101 102 |
# File 'lib/discord_rda/entity/role.rb', line 100 def integrated? &.key?('bot_id') || &.key?('integration_id') end |
#lower_than?(other) ⇒ Boolean
Check if this role is lower than another
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
34 35 36 |
# File 'lib/discord_rda/entity/role.rb', line 34 def managed? managed end |
#mention ⇒ String
Get mention string for the role
58 59 60 |
# File 'lib/discord_rda/entity/role.rb', line 58 def mention "<@&#{id}>" end |
#mentionable? ⇒ Boolean
Check if role is mentionable
40 41 42 |
# File 'lib/discord_rda/entity/role.rb', line 40 def mentionable? mentionable end |
#permission_set ⇒ Permission
Get permissions as Permission object
28 29 30 |
# File 'lib/discord_rda/entity/role.rb', line 28 def Permission.new(.to_i) end |
#premium_subscriber? ⇒ Boolean
Check if role is a premium subscriber role
106 107 108 |
# File 'lib/discord_rda/entity/role.rb', line 106 def premium_subscriber? &.key?('premium_subscriber') end |
#rgb ⇒ Array<Integer>
Get RGB values
76 77 78 |
# File 'lib/discord_rda/entity/role.rb', line 76 def rgb color_object.rgb end |
#role_tags ⇒ RoleTags
Get role tags
94 95 96 |
# File 'lib/discord_rda/entity/role.rb', line 94 def RoleTags.new( || {}) end |
#subscription_listing? ⇒ Boolean
Check if role has a subscription listing
112 113 114 |
# File 'lib/discord_rda/entity/role.rb', line 112 def subscription_listing? &.key?('subscription_listing_id') end |