/
Role.java
279 lines (258 loc) · 12.8 KB
/
Role.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
* Copyright 2015-2018 Austin Keener & Michael Ritter & Florian Spieß
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dv8tion.jda.core.entities;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.managers.RoleManager;
import net.dv8tion.jda.core.managers.RoleManagerUpdatable;
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction;
import net.dv8tion.jda.core.requests.restaction.RoleAction;
import javax.annotation.CheckReturnValue;
import java.awt.Color;
/**
* Represents a {@link net.dv8tion.jda.core.entities.Guild Guild}'s Role. Used to control permissions for Members.
*/
public interface Role extends ISnowflake, IMentionable, IPermissionHolder, Comparable<Role>
{
/** Used to keep consistency between color values used in the API */
int DEFAULT_COLOR_RAW = 0x1FFFFFFF; // java.awt.Color fills the MSB with FF, we just use 1F to provide better consistency
/**
* The hierarchical position of this {@link net.dv8tion.jda.core.entities.Role Role}
* in the {@link net.dv8tion.jda.core.entities.Guild Guild} hierarchy. (higher value means higher role).
* <br>The {@link net.dv8tion.jda.core.entities.Guild#getPublicRole()}'s getPosition() always return -1.
*
* @return The position of this {@link net.dv8tion.jda.core.entities.Role Role} as integer.
*/
int getPosition();
/**
* The actual position of the {@link net.dv8tion.jda.core.entities.Role Role} as stored and given by Discord.
* <br>Role positions are actually based on a pairing of the creation time (as stored in the snowflake id)
* and the position. If 2 or more roles share the same position then they are sorted based on their creation date.
* <br>The more recent a role was created, the lower it is in the hierarchy. This is handled by {@link #getPosition()}
* and it is most likely the method you want. If, for some reason, you want the actual position of the
* Role then this method will give you that value.
*
* @return The true, Discord stored, position of the {@link net.dv8tion.jda.core.entities.Role Role}.
*/
int getPositionRaw();
/**
* The Name of this {@link net.dv8tion.jda.core.entities.Role Role}.
*
* @return Never-null String containing the name of this {@link net.dv8tion.jda.core.entities.Role Role}.
*/
String getName();
/**
* Whether this {@link net.dv8tion.jda.core.entities.Role Role} is managed by an integration
*
* @return True, if this {@link net.dv8tion.jda.core.entities.Role Role} is managed.
*/
boolean isManaged();
/**
* Whether this {@link net.dv8tion.jda.core.entities.Role Role} is hoisted
* <br>Members in a hoisted role are displayed in their own grouping on the user-list
*
* @return True, if this {@link net.dv8tion.jda.core.entities.Role Role} is hoisted.
*/
boolean isHoisted();
/**
* Whether or not this Role is mentionable
*
* @return True, if Role is mentionable.
*/
boolean isMentionable();
/**
* The {@code long} representation of the literal permissions that this {@link net.dv8tion.jda.core.entities.Role Role} has.
* <br><b>NOTE:</b> these do not necessarily represent the permissions this role will have in a {@link net.dv8tion.jda.core.entities.Channel Channel}.
*
* @return Never-negative long containing offset permissions of this role.
*/
long getPermissionsRaw();
/**
* The color this {@link net.dv8tion.jda.core.entities.Role Role} is displayed in.
*
* @return Color value of Role-color
*
* @see #getColorRaw()
*/
Color getColor();
/**
* The raw color RGB value used for this role
* <br>Defaults to {@link #DEFAULT_COLOR_RAW} if this role has no set color
*
* @return The raw RGB color value or default
*/
int getColorRaw();
/**
* Whether this role is the @everyone role for its {@link net.dv8tion.jda.core.entities.Guild Guild},
* which is assigned to everyone who joins the {@link net.dv8tion.jda.core.entities.Guild Guild}.
*
* @return True, if and only if this {@link net.dv8tion.jda.core.entities.Role Role} is the public role
* for the {@link net.dv8tion.jda.core.entities.Guild Guild} provided by {@link #getGuild()}.
*
* @see net.dv8tion.jda.core.entities.Guild#getPublicRole()
*/
boolean isPublicRole();
/**
* Whether this Role can interact with the specified Role.
* (move/manage/etc.)
*
* @param role
* The not-null role to compare to
*
* @throws IllegalArgumentException
* if the provided Role is null or not from the same {@link net.dv8tion.jda.core.entities.Guild Guild}
*
* @return True, if this role can interact with the specified role
*
* @see net.dv8tion.jda.core.utils.PermissionUtil#canInteract(Role, Role)
*/
boolean canInteract(Role role);
/**
* Returns the {@link net.dv8tion.jda.core.entities.Guild Guild} this Role exists in
*
* @return the Guild containing this Role
*/
Guild getGuild();
/**
* Creates a new {@link net.dv8tion.jda.core.entities.Role Role} in the specified {@link net.dv8tion.jda.core.entities.Guild Guild}
* with the same settings as the given {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>The position of the specified Role does not matter in this case!
*
* <p>It will be placed at the bottom (just over the Public Role) to avoid permission hierarchy conflicts.
* <br>For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES} Permission
* and all {@link net.dv8tion.jda.core.Permission Permissions} the given {@link net.dv8tion.jda.core.entities.Role Role} has.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.core.requests.RestAction RestAction} include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The role could not be created due to a permission discrepancy</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>We were removed from the Guild before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MAX_ROLES_PER_GUILD MAX_ROLES_PER_GUILD}
* <br>There are too many roles in this Guild</li>
* </ul>
*
* @param guild
* The {@link net.dv8tion.jda.core.entities.Role Role} that should be copied
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES} Permission and every Permission the provided Role has
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* If the guild is temporarily not {@link net.dv8tion.jda.core.entities.Guild#isAvailable() available}
* @throws java.lang.IllegalArgumentException
* If the specified guild is {@code null}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.RoleAction RoleAction}
* <br>RoleAction with already copied values from the specified {@link net.dv8tion.jda.core.entities.Role Role}
*/
@CheckReturnValue
RoleAction createCopy(Guild guild);
/**
* Creates a new {@link net.dv8tion.jda.core.entities.Role Role} in this {@link net.dv8tion.jda.core.entities.Guild Guild}
* with the same settings as the given {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>The position of the specified Role does not matter in this case!
*
* <p>It will be placed at the bottom (just over the Public Role) to avoid permission hierarchy conflicts.
* <br>For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES} Permission
* and all {@link net.dv8tion.jda.core.Permission Permissions} the given {@link net.dv8tion.jda.core.entities.Role Role} has.
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.core.requests.RestAction RestAction} include the following:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The role could not be created due to a permission discrepancy</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>We were removed from the Guild before finishing the task</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MAX_ROLES_PER_GUILD MAX_ROLES_PER_GUILD}
* <br>There are too many roles in this Guild</li>
* </ul>
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES} Permission and every Permission the provided Role has
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* If the guild is temporarily not {@link net.dv8tion.jda.core.entities.Guild#isAvailable() available}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.RoleAction RoleAction}
* <br>RoleAction with already copied values from the specified {@link net.dv8tion.jda.core.entities.Role Role}
*/
@CheckReturnValue
default RoleAction createCopy()
{
return createCopy(getGuild());
}
/**
* The {@link net.dv8tion.jda.core.managers.RoleManager RoleManager} for this Role.
* In the RoleManager, you can modify all its values.
* <br>You modify multiple fields in one request by chaining setters before calling {@link net.dv8tion.jda.core.requests.RestAction#queue() RestAction.queue()}.
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES Permission.MANAGE_ROLES}
* @throws net.dv8tion.jda.core.exceptions.HierarchyException
* If the currently logged in account does not have the required position to modify this role
*
* @return The RoleManager of this Role
*/
RoleManager getManager();
/**
* The {@link net.dv8tion.jda.core.managers.RoleManagerUpdatable RoleManagerUpdatable} for this Role.
* In the Manager, you can modify all its values.
*
* <p>This can be used to bulk update role properties.
* It requires to call an {@code update()} method.
*
* @return The {@link net.dv8tion.jda.core.managers.RoleManagerUpdatable RoleManagerUpdatable} for this Role
*
* @deprecated
* Use {@link #getManager()} instead
*/
@Deprecated
RoleManagerUpdatable getManagerUpdatable();
/**
* Deletes this Role.
*
* <p>Possible ErrorResponses include:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_ROLE}
* <br>If the the role was already deleted.</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The send request was attempted after the account lost
* {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES Permission.MANAGE_ROLES} in the channel.</li>
*
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>If we were removed from the Guild</li>
* </ul>
*
* @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
* If we don't have the permission to {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* @throws net.dv8tion.jda.core.exceptions.HierarchyException
* If the role is too high in the role hierarchy to be deleted
*
* @return {@link net.dv8tion.jda.core.requests.RestAction}
*/
@CheckReturnValue
AuditableRestAction<Void> delete();
/**
* Returns the {@link net.dv8tion.jda.core.JDA JDA} instance of this Role
*
* @return the corresponding JDA instance
*/
JDA getJDA();
}