/
Invite.java
286 lines (262 loc) · 9.09 KB
/
Invite.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
280
281
282
283
284
285
286
/*
* Copyright 2015-2017 Austin Keener & Michael Ritter
*
* 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.entities.impl.InviteImpl;
import net.dv8tion.jda.core.requests.RestAction;
import java.time.OffsetDateTime;
/**
* Representation of a Discord Invite.
* This class is immutable.
*
* @since 3.0
* @author Aljoscha Grebe
*/
public interface Invite
{
/**
* Retrieves a new {@link net.dv8tion.jda.core.entities.Invite Invite} instance for the given invite code.
* <br><b>You cannot resolve invites if you were banned from the origin Guild!</b>
*
* <p>Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} include:
* <ul>
* <li>{@link net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_INVITE Unknown Invite}
* <br>The Invite did not exist (possibly deleted) or the account is banned in the guild.</li>
* </ul>
*
* @param api
* The JDA instance
* @param code
* A valid invite code
*
* @return {@link net.dv8tion.jda.core.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.core.entities.Invite Invite}
* <br>The Invite object
*/
static RestAction<Invite> resolve(final JDA api, final String code)
{
return InviteImpl.resolve(api, code);
}
/**
* Deletes this invite.
* <br>Requires {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} in the invite's channel.
* Will throw a {@link net.dv8tion.jda.core.exceptions.PermissionException PermissionException} otherwise.
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* if the account does not have {@link net.dv8tion.jda.core.Permission#MANAGE_SERVER MANAGE_SERVER} in the invite's channel
*
* @return {@link net.dv8tion.jda.core.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.core.entities.Invite Invite}
* <br>The deleted Invite object
*/
RestAction<Invite> delete();
/**
* Tries to retrieve a new expanded {@link net.dv8tion.jda.core.entities.Invite Invite} with more info.
* <br>Requires either {@link net.dv8tion.jda.core.Permission#MANAGE_SERVER MANAGE_SERVER} in the invite's guild or
* {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} in the invite's channel.
* Will throw a {@link net.dv8tion.jda.core.exceptions.PermissionException PermissionException} otherwise.
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* if the account neither has {@link net.dv8tion.jda.core.Permission#MANAGE_SERVER MANAGE_SERVER} in the invite's guild nor
* {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} in the invite's channel
*
* @return {@link net.dv8tion.jda.core.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.core.entities.Invite Invite}
* <br>The expanded Invite object
*
* @see #isExpanded()
*/
RestAction<Invite> expand();
/**
* An {@link net.dv8tion.jda.core.entities.Invite.Channel Invite.Channel} object
* containing information about this invite's origin channel.
*
* @return Information about this invite's origin channel
*
* @see net.dv8tion.jda.core.entities.Invite.Channel
*/
Channel getChannel();
/**
* The invite code
*
* @return the invite code
*/
String getCode();
/**
* Returns creation date of this invite.
*
* <p>This works only for expanded invites and will throw a {@link IllegalStateException} otherwise!
*
* @throws IllegalStateException
* if this invite is not expanded
*
* @return The creation date of this invite
*
* @see #expand()
* @see #isExpanded()
*/
OffsetDateTime getCreationTime();
/**
* An {@link net.dv8tion.jda.core.entities.Invite.Guild Invite.Guild} object
* containing information about this invite's origin guild.
*
* @return Information about this invite's origin guild
*
* @see net.dv8tion.jda.core.entities.Invite.Guild
*/
Guild getGuild();
/**
* The user who created this invite. This may be a fake user. For not expanded invites this may be null.
*
* @return The user who created this invite
*/
User getInviter();
/**
* The {@link net.dv8tion.jda.core.JDA JDA} instance used to create this Invite
*
* @return the corresponding JDA instance
*/
JDA getJDA();
/**
* The max age of this invite in seconds.
*
* <p>This works only for expanded invites and will throw a {@link IllegalStateException} otherwise!
*
* @throws IllegalStateException
* if this invite is not expanded
*
* @return The max age of this invite in seconds
*
* @see #expand()
* @see #isExpanded()
*/
int getMaxAge();
/**
* The max uses of this invite. If there is no limit thus will return {@code 0}.
*
* <p>This works only for expanded invites and will throw a {@link IllegalStateException} otherwise!
*
* @throws IllegalStateException
* if this invite is not expanded
*
* @return The max uses of this invite or {@code 0} if there is no limit
*
* @see #expand()
* @see #isExpanded()
*/
int getMaxUses();
/**
* How often this invite has been used.
*
* <p>This works only for expanded invites and will throw a {@link IllegalStateException} otherwise!
*
* @throws IllegalStateException
* if this invite is not expanded
*
* @return The uses of this invite
*
* @see #expand()
* @see #isExpanded()
*/
int getUses();
/**
* Whether this Invite is expanded or not. Expanded invites contain more information, but they can only be
* obtained be {@link net.dv8tion.jda.core.entities.Guild#getInvites() Guild#getInvites()} (requires
* {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL Permission.MANAGE_CHANNEL}) or
* {@link net.dv8tion.jda.core.entities.Channel#getInvites() Channel#getInvites()} (requires
* {@link net.dv8tion.jda.core.Permission#MANAGE_SERVER Permission.MANAGE_SERVER}).
*
* <p>There is a convenience method {@link #expand()} to get the expanded invite for an unexpanded one.
*
* @return Whether is invite expanded or not
*
* @see #expand()
*/
boolean isExpanded();
/**
* Whether this Invite grants only temporary access or not
*
* @throws IllegalStateException
* if this invite is not expanded
*
* @return Whether is invite expanded or not
*/
boolean isTemporary();
/**
* POJO for the channel information provided by an invite.
*
* @see #getChannel()
*/
interface Channel extends ISnowflake
{
/**
* The name of this channel.
*
* @return The channels's name
*/
String getName();
/**
* The {@link net.dv8tion.jda.core.entities.ChannelType ChannelType} of this channel.
* <br>Valid values are only {@link net.dv8tion.jda.core.entities.ChannelType#TEXT TEXT} or {@link net.dv8tion.jda.core.entities.ChannelType#VOICE VOICE}
*
* @return The channel's type
*/
ChannelType getType();
}
/**
* POJO for the guild information provided by an invite.
*
* @see #getGuild()
*/
interface Guild extends ISnowflake
{
/**
* The icon id of this guild.
*
* @return The guild's icon id
*
* @see #getIconUrl()
*/
String getIconId();
/**
* The icon url of this guild.
*
* @return The guild's icon url
*
* @see #getIconId()
*/
String getIconUrl();
/**
* The name of this guild.
*
* @return The guilds's name
*/
String getName();
/**
* The splash image id of this guild.
*
* @return The guild's splash image id or {@code null} if the guild has no splash image
*
* @see #getSplashUrl()
*/
String getSplashId();
/**
* Returns the splash image url of this guild.
*
* @return The guild's splash image url or {@code null} if the guild has no splash image
*
* @see #getSplashId()
*/
String getSplashUrl();
}
}