Skip to content

Commit

Permalink
Add tags to role model (#230)
Browse files Browse the repository at this point in the history
* Add tags to role model

* Rename tags wrapper class

* Return bot_id as integer

Co-authored-by: Dakurei <[email protected]>

---------

Co-authored-by: Kamil Walkowiak <[email protected]>
Co-authored-by: Dakurei <[email protected]>
  • Loading branch information
3 people authored Jun 28, 2023
1 parent aee6c83 commit b029e52
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/discordrb/data/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ class Role
# @return [String, nil] The icon hash for this role.
attr_reader :icon

# @return [Tags, nil] The role tags
attr_reader :tags

# Wrapper for the role tags
class Tags
# @return [Integer, nil] The ID of the bot this role belongs to
attr_reader :bot_id

# @return [Integer, nil] The ID of the integration this role belongs to
attr_reader :integration_id

# @return [true, false] Whether this is the guild's Booster role
attr_reader :premium_subscriber

# @return [Integer, nil] The id of this role's subscription sku and listing
attr_reader :subscription_listing_id

# @return [true, false] Whether this role is available for purchase
attr_reader :available_for_purchase

# @return [true, false] Whether this role is a guild's linked role
attr_reader :guild_connections

def initialize(data)
@bot_id = data['bot_id']&.resolve_id
@integration_id = data['integration_id']&.resolve_id
@premium_subscriber = data.key?('premium_subscriber')
@subscription_listing_id = data['subscription_listing_id']&.resolve_id
@available_for_purchase = data.key?('available_for_purchase')
@guild_connections = data.key?('guild_connections')
end
end

# This class is used internally as a wrapper to a Role object that allows easy writing of permission data.
class RoleWriter
# @!visibility private
Expand Down Expand Up @@ -72,6 +105,8 @@ def initialize(data, bot, server = nil)
@colour = ColourRGB.new(data['color'])

@icon = data['icon']

@tags = Tags.new(data['tags']) if data['tags']
end

# @return [String] a string that will mention this role, if it is mentionable.
Expand Down

0 comments on commit b029e52

Please sign in to comment.