-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Represents the onboarding data of a guild. | ||
*/ | ||
class GuildOnboarding { | ||
constructor(data) { | ||
/** | ||
* The id of the guild this onboarding data is for | ||
* @type {Snowflake} | ||
*/ | ||
this.guildId = data.guild_id; | ||
|
||
/** | ||
* The prompts shown during onboarding | ||
* @type {GuildOnboardingPrompt[]} | ||
*/ | ||
this.prompts = data.prompts.map(prompt => this._transformPrompt(prompt)); | ||
|
||
/** | ||
* The ids of the channels that new members get opted into automatically | ||
* @type {Snowflake[]} | ||
*/ | ||
this.defaultChannelIds = data.default_channel_ids; | ||
|
||
/** | ||
* Whether the onboarding is enabled | ||
* @type {boolean} | ||
*/ | ||
this.enabled = data.enabled; | ||
} | ||
|
||
/** | ||
* The data for a guild onboarding prompt | ||
* @typedef {Object} GuildOnboardingPrompt | ||
* @property {Snowflake} id The id of the prompt | ||
* @property {GuildOnboardingPromptOption[]} options The options of the prompt | ||
* @property {string} title The title of the prompt | ||
* @property {boolean} singleSelect Whether only option of the prompt can be selected at a time | ||
* @property {boolean} required Whether the prompt is required in the onboarding flow | ||
* @property {boolean} inOnboarding Whether the prompt is in the onboarding flow | ||
* @property {GuildOnboardingPromptType} type The type of the prompt | ||
*/ | ||
|
||
/** | ||
* Transforms a raw prompt object into a GuildOnboardingPrompt | ||
* @param {Object} prompt The raw prompt object | ||
* @returns {GuildOnboardingPrompt} | ||
* @private | ||
*/ | ||
_transformPrompt(prompt) { | ||
return { | ||
id: prompt.id, | ||
options: prompt.options.map(option => this._transformPromptOption(option)), | ||
title: prompt.title, | ||
singleSelect: prompt.single_select, | ||
required: prompt.required, | ||
inOnboarding: prompt.in_onboarding, | ||
type: prompt.type, | ||
}; | ||
} | ||
|
||
/** | ||
* The data for an option of a guilds onboarding prompt | ||
* @typedef {Object} GuildOnboardingPromptOption | ||
* @property {Snowflake} id The id of the option | ||
* @property {Snowflake[]} channelIds The ids of the channels opted in when this option is selected | ||
* @property {Snowflake[]} roleIds The ids of the roles assigned when this option is selected | ||
* @property {GuildOnboardingPromptOptionEmoji} emoji The emoji of the option | ||
* @property {string} title The title of the option | ||
* @property {?string} description The description of the option | ||
*/ | ||
|
||
/** | ||
* The data for an emoji of a guilds onboarding prompt option | ||
* @typedef {Object} GuildOnboardingPromptOptionEmoji | ||
* @property {?Snowflake} id The id of the emoji | ||
* @property {?string} name The name of the emoji | ||
*/ | ||
|
||
/** | ||
* Transforms a raw prompt option object into a GuildOnboardingPromptOption | ||
* @param {Object} option The raw prompt option object | ||
* @returns {GuildOnboardingPromptOption} | ||
* @private | ||
*/ | ||
_transformPromptOption(option) { | ||
return { | ||
id: option.id, | ||
channelIds: option.channel_ids, | ||
roleIds: option.role_ids, | ||
emoji: { | ||
id: option.emoji_id, | ||
name: option.emoji_name, | ||
}, | ||
title: option.title, | ||
description: option.description, | ||
}; | ||
} | ||
} | ||
|
||
exports.GuildOnboarding = GuildOnboarding; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters