mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
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:
@@ -321,6 +321,20 @@ export async function createInvite(
|
|||||||
throw new Error(Errors.MISSING_CREATE_INSTANT_INVITE);
|
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(
|
const result = await RequestManager.post(
|
||||||
endpoints.CHANNEL_INVITES(channelID),
|
endpoints.CHANNEL_INVITES(channelID),
|
||||||
options,
|
options,
|
||||||
|
|||||||
@@ -154,11 +154,12 @@ export interface GetMessagesAround extends GetMessages {
|
|||||||
around: string;
|
around: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: v11 change to camelcase
|
||||||
export interface CreateInviteOptions {
|
export interface CreateInviteOptions {
|
||||||
/** Duration of invite in seconds before expiry, or 0 for never. Defaults to 86400 (24 hours) */
|
/** 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_age"?: number;
|
||||||
/** Max number of uses or 0 for unlimited. Default 0 */
|
/** Max number of uses or 0 for unlimited. Between 0-100. Default 0 */
|
||||||
"max_uses": number;
|
"max_uses"?: number;
|
||||||
/** Whether this invite only grants temporary membership. */
|
/** Whether this invite only grants temporary membership. */
|
||||||
temporary: boolean;
|
temporary: boolean;
|
||||||
/** If true, don't try to reuse a similar invite (useful for creating many unique one time use invites.) */
|
/** If true, don't try to reuse a similar invite (useful for creating many unique one time use invites.) */
|
||||||
|
|||||||
Reference in New Issue
Block a user