fix(handlers/channel): handle max_age and max_uses limit in createInvite() (#597)

* fix: handle invalid invite create limits

* refactor: cleanup conditonals

* chore: clarification

Co-authored-by: ayntee <ayyantee@gmail.com>
This commit is contained in:
Skillz4Killz
2021-03-06 14:44:31 -05:00
committed by GitHub
parent e5bf5cd47c
commit d084c3f3c4
2 changed files with 19 additions and 4 deletions
+14
View File
@@ -321,6 +321,20 @@ export async function createInvite(
throw new Error(Errors.MISSING_CREATE_INSTANT_INVITE);
}
if (options.max_age && (options.max_age > 604800 || options.max_age < 0)) {
console.log(
`The max age for invite created in ${channelID} was not between 0-604800. Using default values instead.`,
);
options.max_age = undefined;
}
if (options.max_uses && (options.max_uses > 100 || options.max_uses < 0)) {
console.log(
`The max uses for invite created in ${channelID} was not between 0-100. Using default values instead.`,
);
options.max_uses = undefined;
}
const result = await RequestManager.post(
endpoints.CHANNEL_INVITES(channelID),
options,
+5 -4
View File
@@ -154,11 +154,12 @@ export interface GetMessagesAround extends GetMessages {
around: string;
}
// TODO: v11 change to camelcase
export interface CreateInviteOptions {
/** Duration of invite in seconds before expiry, or 0 for never. Defaults to 86400 (24 hours) */
"max_age": number;
/** Max number of uses or 0 for unlimited. Default 0 */
"max_uses": number;
/** Duration of invite in seconds before expiry, or 0 for never. Between 0-604800 (7 days). Defaults to 86400 (24 hours). */
"max_age"?: number;
/** Max number of uses or 0 for unlimited. Between 0-100. Default 0 */
"max_uses"?: number;
/** Whether this invite only grants temporary membership. */
temporary: boolean;
/** If true, don't try to reuse a similar invite (useful for creating many unique one time use invites.) */