-
-
Notifications
You must be signed in to change notification settings - Fork 723
/
Emote.java
269 lines (250 loc) · 9.49 KB
/
Emote.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
/*
* Copyright 2015-2020 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* 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.api.entities;
import net.dv8tion.jda.annotations.DeprecatedSince;
import net.dv8tion.jda.annotations.ReplaceWith;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.managers.EmoteManager;
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
import net.dv8tion.jda.internal.utils.PermissionUtil;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
/**
* Represents a Custom Emote. (Custom Emoji in official Discord API terminology)
*
* <p>You can retrieve the creator of an emote by using {@link Guild#retrieveEmote(Emote)} followed
* by using {@link ListedEmote#getUser()}.
*
* <p><b>This does not represent unicode emojis like they are used in the official client! (:smiley: is not a custom emoji)</b>
*
* <h2>Fake Emote</h2>
* When an emote is declared as fake it cannot be updated by JDA. That means it will not be accessible
* through cache such as {@link Guild#getEmoteCache()} and similar.
* <br>Fake emotes may or may not have an attached {@link Guild Guild} and thus might not be manageable though
* {@link #getManager()} or {@link #delete()}. They also might lack attached roles for {@link #getRoles()}.
*
*
* @since 2.2
*
* @see net.dv8tion.jda.api.entities.ListedEmote ListedEmote
*
* @see Guild#getEmoteCache()
* @see Guild#getEmoteById(long)
* @see Guild#getEmotesByName(String, boolean)
* @see Guild#getEmotes()
*
* @see JDA#getEmoteCache()
* @see JDA#getEmoteById(long)
* @see JDA#getEmotesByName(String, boolean)
* @see JDA#getEmotes()
*/
public interface Emote extends IMentionable, IFakeable
{
/** Template for {@link #getImageUrl()} */
String ICON_URL = "https://cdn.discordapp.com/emojis/%s.%s";
/**
* The {@link net.dv8tion.jda.api.entities.Guild Guild} this emote is attached to.
*
* <p><b>This is null if the emote is fake (retrieved from a Message)</b>
*
* @return Guild of this emote or null if it is a fake entity
*/
@Nullable
Guild getGuild();
/**
* Roles this emote is active for.
* <br><a href="https://discord.com/developers/docs/resources/emoji#emoji-object" target="_blank">Learn More</a>
*
* @throws IllegalStateException
* If this Emote does not have attached roles according to {@link #canProvideRoles()}
*
* @return An immutable list of the roles this emote is active for (all roles if empty)
*
* @see #canProvideRoles()
*/
@Nonnull
List<Role> getRoles();
/**
* Whether this Emote has attached roles. This might not be the case when the emote
* is retrieved through special cases like audit-logs.
*
* <p>If this is not true then {@link #getRoles()} will throw {@link IllegalStateException}.
*
* @return True, if this emote has roles attached
*
* @deprecated This will be replaced by {@link #canProvideRoles()}
*/
@Deprecated
@DeprecatedSince("3.8.0")
@ReplaceWith("canProvideRoles()")
default boolean hasRoles()
{
return canProvideRoles();
}
/**
* Whether this Emote has an attached roles list. This might not be the case when the emote
* is retrieved through special cases like audit-logs.
*
* <p>If this is not true then {@link #getRoles()} will throw {@link IllegalStateException}.
*
* @return True, if this emote has an attached roles list
*/
boolean canProvideRoles();
/**
* The name of this emote.
* <br>Does not include colons.
*
* @return String representation of this emote's name
*/
@Nonnull
String getName();
/**
* Whether this emote is managed. A managed Emote is controlled by Discord, not the Guild administrator, typical
* via a service like BTTV in conjunction with Twitch.
* <br><a href="https://discord.com/developers/docs/resources/emoji#emoji-object" target="_blank">Learn More</a>
*
* @return True, if this emote is managed
*/
boolean isManaged();
/**
* The {@link net.dv8tion.jda.api.JDA JDA} instance of this Emote
*
* @return The JDA instance of this Emote
*/
@Nonnull
JDA getJDA();
/**
* Deletes this Emote.
*
* <p>Possible ErrorResponses include:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_EMOJI UNKNOWN_EMOTE}
* <br>If this Emote was already removed</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_GUILD UNKNOWN_GUILD}
* <br>If the Guild of this Emote was deleted</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>If we were removed from the Guild</li>
* </ul>
*
* @throws IllegalStateException
* if this Emote is fake ({@link #isFake()})
* @throws java.lang.UnsupportedOperationException
* If this emote is managed by discord ({@link #isManaged()})
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* if the Permission {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES MANAGE_EMOTES} is not given
*
* @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction}
* The RestAction to delete this Emote.
*/
@Nonnull
@CheckReturnValue
AuditableRestAction<Void> delete();
/**
* The {@link EmoteManager Manager} for this emote, used to modify
* properties of the emote like name and role restrictions.
* <br>You modify multiple fields in one request by chaining setters before calling {@link net.dv8tion.jda.api.requests.RestAction#queue() RestAction.queue()}.
*
* @throws IllegalStateException
* if this emote is fake
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES Permission.MANAGE_EMOTES}
*
* @return The EmoteManager for this Emote
*/
@Nonnull
EmoteManager getManager();
/**
* Whether or not this Emote is animated.
*
* <p>Animated Emotes are available to Discord Nitro users as well as Bot accounts.
*
* @return Whether the Emote is animated or not.
*/
boolean isAnimated();
/**
* A String representation of the URL which leads to image displayed within the official Discord™ client
* when this Emote is used
*
* @return Discord CDN link to the Emote's image
*/
@Nonnull
default String getImageUrl()
{
return String.format(ICON_URL, getId(), isAnimated() ? "gif" : "png");
}
/**
* Usable representation of this Emote (used to display in the client just like mentions with a specific format)
* <br>Emotes are used with the format <code><:{@link #getName getName()}:{@link #getId getId()}></code>
*
* @return A usable String representation for this Emote
*
* @see <a href="https://discord.com/developers/docs/resources/channel#message-formatting">Message Formatting</a>
*/
@Nonnull
@Override
default String getAsMention()
{
return (isAnimated() ? "<a:" : "<:") + getName() + ":" + getId() + ">";
}
/**
* Whether the specified Member can interact with this Emote
*
* @param issuer
* The User to test
*
* @return True, if the provided Member can use this Emote
*/
default boolean canInteract(Member issuer)
{
return PermissionUtil.canInteract(issuer, this);
}
/**
* Whether the specified User can interact with this Emote within the provided MessageChannel
* <br>Same logic as {@link #canInteract(User, MessageChannel, boolean) canInteract(issuer, channel, true)}!
*
* @param issuer
* The User to test
* @param channel
* The MessageChannel to test
*
* @return True, if the provided Member can use this Emote
*/
default boolean canInteract(User issuer, MessageChannel channel)
{
return PermissionUtil.canInteract(issuer, this, channel);
}
/**
* Whether the specified User can interact with this Emote within the provided MessageChannel
* <br>Special override to exclude elevated bot permissions in case of (for instance) reacting to messages.
*
* @param issuer
* The User to test
* @param channel
* The MessageChannel to test
* @param botOverride
* Whether bots can use non-managed emotes in other guilds
*
* @return True, if the provided Member can use this Emote
*/
default boolean canInteract(User issuer, MessageChannel channel, boolean botOverride)
{
return PermissionUtil.canInteract(issuer, this, channel, botOverride);
}
}