feat(handlers): add Membership Screening (#449)

* feat(handlers): support membership screening feature

* s
This commit is contained in:
Ayyan
2021-01-26 19:20:06 +04:00
committed by GitHub
parent 9e389981aa
commit 6599636dbc
3 changed files with 99 additions and 1 deletions
+68
View File
@@ -26,6 +26,8 @@ import {
ImageSize, ImageSize,
Intents, Intents,
MemberCreatePayload, MemberCreatePayload,
MembershipScreeningFieldTypes,
MembershipScreeningPayload,
Overwrite, Overwrite,
PositionSwap, PositionSwap,
PruneOptions, PruneOptions,
@@ -1021,3 +1023,69 @@ export async function editGuildTemplate(
return structures.createTemplate(template); return structures.createTemplate(template);
} }
function createMembershipObj(
{ form_fields: formFields, ...props }: MembershipScreeningPayload,
) {
return {
...props,
formFields: formFields.map(({ field_type, ...rest }) => ({
...rest,
fieldType: field_type,
})),
};
}
export type MembershipScreening = ReturnType<typeof createMembershipObj>;
/** Get the membership screening form of a guild. */
export async function getGuildMembershipScreeningForm(guildID: string) {
const membershipScreeningPayload = await RequestManager.get(
endpoints.GUILD_MEMBER_VERIFICATION(guildID),
) as MembershipScreeningPayload;
return createMembershipObj(membershipScreeningPayload);
}
/** Edit the guild's Membership Screening form. Requires the `MANAGE_GUILD` permission. */
export async function editGuildMembershipScreeningForm(
guildID: string,
options?: EditGuildMembershipScreeningForm,
) {
const membershipScreeningFormPayload = await RequestManager.patch(
endpoints.GUILD_MEMBER_VERIFICATION(guildID),
{
...options,
form_fields: JSON.stringify(
options?.formFields?.map(({ fieldType, ...props }) => ({
...props,
field_type: fieldType,
})),
),
},
) as MembershipScreeningPayload;
return createMembershipObj(
membershipScreeningFormPayload,
);
}
export interface EditGuildMembershipScreeningForm {
/** whether Membership Screening is enabled */
enabled?: boolean;
/** array of field objects */
formFields?: MembershipScreeningField[];
/** the steps in the screening form */
description?: string;
}
export interface MembershipScreeningField {
/** the type of field */
fieldType: MembershipScreeningFieldTypes;
/** the title of the field */
label: string;
/** the list of rules */
values?: string[];
/** whether the user has to fill out this field */
required: boolean;
}
+29 -1
View File
@@ -174,7 +174,11 @@ export type GuildFeatures =
| "DISCOVERABLE" | "DISCOVERABLE"
| "FEATURABLE" | "FEATURABLE"
| "ANIMATED_ICON" | "ANIMATED_ICON"
| "BANNER"; | "BANNER"
/** guild has enabled Membership Screening */
| "MEMBER_VERIFICATION_GATE_ENABLED"
/** guild can be previewed before joining via Membership Screening or the directory */
| "PREVIEW_ENABLED";
export interface VoiceRegion { export interface VoiceRegion {
/** unique ID for the region */ /** unique ID for the region */
@@ -675,3 +679,27 @@ export interface EditGuildTemplate {
/** description for the template (0-120 characters) */ /** description for the template (0-120 characters) */
description?: string | null; description?: string | null;
} }
export interface MembershipScreeningPayload {
/** when the fields were last updated */
version: string;
/** the steps in the screening form */
form_fields: MembershipScreeningFieldPayload[];
/** the server description shown in the screening form */
description: string | null;
}
export interface MembershipScreeningFieldPayload {
/** the type of field */
field_type: MembershipScreeningFieldTypes;
/** the title of the field */
label: string;
/** the list of rules */
values?: string[];
/** whether the user has to fill out this field */
required: boolean;
}
export type MembershipScreeningFieldTypes =
/** Server Rules */
"TERMS";
+2
View File
@@ -116,6 +116,8 @@ export const endpoints = {
`${baseEndpoints.BASE_URL}/guilds/templates/${code}`, `${baseEndpoints.BASE_URL}/guilds/templates/${code}`,
GUILD_TEMPLATES: (guildID: string) => `${GUILDS_BASE(guildID)}/templates`, GUILD_TEMPLATES: (guildID: string) => `${GUILDS_BASE(guildID)}/templates`,
GUILD_PREVIEW: (guildID: string) => `${GUILDS_BASE(guildID)}/preview`, GUILD_PREVIEW: (guildID: string) => `${GUILDS_BASE(guildID)}/preview`,
GUILD_MEMBER_VERIFICATION: (guildID: string) =>
`${GUILDS_BASE(guildID)}/member-verification`,
// Voice // Voice
VOICE_REGIONS: `${baseEndpoints.BASE_URL}/voice/regions`, VOICE_REGIONS: `${baseEndpoints.BASE_URL}/voice/regions`,