Class: RubyCord::Guild::Role

Inherits:
DiscordModel show all
Includes:
Comparable
Defined in:
lib/rubycord/guild/role.rb

Defined Under Namespace

Classes: Tag

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?

Instance Attribute Details

#colorRubyCord::Color (readonly)

Returns The color of the role.

Returns:



16
17
18
# File 'lib/rubycord/guild/role.rb', line 16

def color
  @color
end

#color?Boolean (readonly)

Returns Whether the role has a color.

Returns:

  • (Boolean)

    Whether the role has a color.



# File 'lib/rubycord/guild/role.rb', line 37


#custom_iconRubyCord::Asset? (readonly)

Returns The icon of the role.

Returns:



33
34
35
# File 'lib/rubycord/guild/role.rb', line 33

def custom_icon
  @custom_icon
end

#emojiRubyCord::Emoji? (readonly)

Returns The emoji of the role.

Returns:



35
36
37
# File 'lib/rubycord/guild/role.rb', line 35

def emoji
  @emoji
end

#guildRubyCord::Guild (readonly)

Returns The guild this role belongs to.

Returns:



22
23
24
# File 'lib/rubycord/guild/role.rb', line 22

def guild
  @guild
end

#hoistBoolean (readonly) Also known as: hoist?

Returns Whether the role is hoisted.

Returns:

  • (Boolean)

    Whether the role is hoisted.



24
25
26
# File 'lib/rubycord/guild/role.rb', line 24

def hoist
  @hoist
end

#iconRubyCord::Asset, RubyCord::Emoji (readonly)

Returns The icon of the role.

Returns:



# File 'lib/rubycord/guild/role.rb', line 37


#idRubyCord::Snowflake (readonly)

Returns The ID of the role.

Returns:



12
13
14
# File 'lib/rubycord/guild/role.rb', line 12

def id
  @id
end

#managedBoolean (readonly) Also known as: managed?

Returns Whether the role is managed.

Returns:

  • (Boolean)

    Whether the role is managed.



27
28
29
# File 'lib/rubycord/guild/role.rb', line 27

def managed
  @managed
end

#mentionString (readonly)

Returns The mention of the role.

Returns:

  • (String)

    The mention of the role.



# File 'lib/rubycord/guild/role.rb', line 37


#mentionableBoolean (readonly) Also known as: mentionable?

Returns Whether the role is a default role.

Returns:

  • (Boolean)

    Whether the role is a default role.



30
31
32
# File 'lib/rubycord/guild/role.rb', line 30

def mentionable
  @mentionable
end

#nameString (readonly)

Returns The name of the role.

Returns:

  • (String)

    The name of the role.



14
15
16
# File 'lib/rubycord/guild/role.rb', line 14

def name
  @name
end

#permissionsRubyCord::Permission (readonly)

Returns The permissions of the role.

Returns:



18
19
20
# File 'lib/rubycord/guild/role.rb', line 18

def permissions
  @permissions
end

#positionInteger (readonly)

Returns The position of the role.

Returns:

  • (Integer)

    The position of the role.



20
21
22
# File 'lib/rubycord/guild/role.rb', line 20

def position
  @position
end

#tagRubyCord::Role::Tag (readonly) Also known as: tags

Returns The tag of the role.

Returns:

  • (RubyCord::Role::Tag)

    The tag of the role.



# File 'lib/rubycord/guild/role.rb', line 37


Instance Method Details

#<=>(other) ⇒ Integer

Compares two roles by their position.

Parameters:

  • other (RubyCord::Role)

    The role to compare to.

Returns:

  • (Integer)

    -1 if the other role is higher, 0 if they are equal, 1 if the other role is lower.



72
73
74
75
76
# File 'lib/rubycord/guild/role.rb', line 72

def <=>(other)
  return nil unless other.is_a?(Role)

  @position <=> other.position
end

#delete(reason: nil) ⇒ Async::Task<void> Also known as: destroy

Deletes the role.

Parameters:

  • reason (String) (defaults to: nil)

    The reason for deleting the role.

Returns:

  • (Async::Task<void>)

    The task.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/rubycord/guild/role.rb', line 187

def delete(reason: nil)
  Async do
    @client
      .http
      .request(
        RubyCord::Internal::Route.new(
          "/guilds/#{@guild.id}/roles/#{@id}",
          "//guilds/:guild_id/roles/:role_id",
          :delete
        ),
        {},
        audit_log_reason: reason
      )
      .wait
  end
end

#edit(name: RubyCord::Unset, position: RubyCord::Unset, color: RubyCord::Unset, hoist: RubyCord::Unset, mentionable: RubyCord::Unset, icon: RubyCord::Unset, reason: nil) ⇒ Async::Task<void> Also known as: modify

Note:

The arguments of this method are defaultly set to RubyCord::Unset. Specify value to set the value, if not don't specify or specify RubyCord::Unset.

Edits the role.

Parameters:

  • name (String) (defaults to: RubyCord::Unset)

    The new name of the role.

  • position (Integer) (defaults to: RubyCord::Unset)

    The new position of the role.

  • color (RubyCord::Color) (defaults to: RubyCord::Unset)

    The new color of the role.

  • hoist (Boolean) (defaults to: RubyCord::Unset)

    Whether the role should be hoisted.

  • mentionable (Boolean) (defaults to: RubyCord::Unset)

    Whether the role should be mentionable.

  • icon (RubyCord::Image, RubyCord::UnicodeEmoji) (defaults to: RubyCord::Unset)

    The new icon or emoji of the role.

  • reason (String) (defaults to: nil)

    The reason for editing the role.

Returns:

  • (Async::Task<void>)

    The task.



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rubycord/guild/role.rb', line 140

def edit(
  name: RubyCord::Unset,
  position: RubyCord::Unset,
  color: RubyCord::Unset,
  hoist: RubyCord::Unset,
  mentionable: RubyCord::Unset,
  icon: RubyCord::Unset,
  reason: nil
)
  Async do
    payload = {}
    payload[:name] = name if name != RubyCord::Unset
    payload[:position] = position if position != RubyCord::Unset
    payload[:color] = color.to_i if color != RubyCord::Unset
    payload[:hoist] = hoist if hoist != RubyCord::Unset
    payload[:mentionable] = mentionable if mentionable != RubyCord::Unset
    if icon != RubyCord::Unset
      if icon.is_a?(RubyCord::Image)
        payload[:icon] = icon.to_s
      else
        payload[:unicode_emoji] = icon.to_s
      end
    end
    @client
      .http
      .request(
        RubyCord::Internal::Route.new(
          "/guilds/#{@guild.id}/roles/#{@id}",
          "//guilds/:guild_id/roles/:role_id",
          :patch
        ),
        payload,
        audit_log_reason: reason
      )
      .wait
  end
end

#inspectObject



95
96
97
# File 'lib/rubycord/guild/role.rb', line 95

def inspect
  "#<#{self.class} @#{@name} id=#{@id}>"
end

#move(position, reason: nil) ⇒ Async::Task<void>

Moves the role to a new position.

Parameters:

  • position (Integer)

    The new position.

  • reason (String) (defaults to: nil)

    The reason for moving the role.

Returns:

  • (Async::Task<void>)

    The task.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rubycord/guild/role.rb', line 108

def move(position, reason: nil)
  Async do
    @client
      .http
      .request(
        RubyCord::Internal::Route.new(
          "/guilds/#{@guild.id}/roles",
          "//guilds/:guild_id/roles",
          :patch
        ),
        { id: @id, position: },
        audit_log_reason: reason
      )
      .wait
  end
end

#to_sString

Formats the role as a string.

Returns:

  • (String)

    The formatted string.



83
84
85
# File 'lib/rubycord/guild/role.rb', line 83

def to_s
  "@#{@name}"
end