Skip to content

Commit ed8f2ef

Browse files
authored
Support Discovery (#1015)
1 parent 27b9704 commit ed8f2ef

File tree

4 files changed

+235
-9
lines changed

4 files changed

+235
-9
lines changed

index.d.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,31 @@ declare namespace Eris {
557557
systemChannelID: string;
558558
verificationLevel?: number;
559559
}
560+
interface DiscoveryCategory {
561+
id: number;
562+
name: {
563+
default: string;
564+
localizations?: { [lang: string]: string };
565+
};
566+
is_primary: boolean;
567+
}
568+
interface DiscoveryMetadata {
569+
guild_id: string;
570+
primary_category_id: number;
571+
keywords: string[] | null;
572+
emoji_discoverability_enabled: boolean;
573+
category_ids: number[];
574+
}
575+
interface DiscoveryOptions {
576+
primaryCategoryID?: string;
577+
keywords?: string[];
578+
emojiDiscoverabilityEnabled?: boolean;
579+
reason?: string;
580+
}
581+
interface DiscoverySubcategoryResponse {
582+
guild_id: string;
583+
category_id: number;
584+
}
560585
interface GetPruneOptions {
561586
days?: number;
562587
includeRoles?: string[];
@@ -1243,6 +1268,7 @@ declare namespace Eris {
12431268
constructor(token: string, options?: ClientOptions);
12441269
acceptInvite(inviteID: string): Promise<Invite<"withoutCount">>;
12451270
addGroupRecipient(groupID: string, userID: string): Promise<void>;
1271+
addGuildDiscoverySubcategory(guildID: string, categoryID: string, reason?: string): Promise<DiscoverySubcategoryResponse>;
12461272
addGuildMemberRole(guildID: string, memberID: string, roleID: string, reason?: string): Promise<void>;
12471273
/** @deprecated */
12481274
addMessageReaction(channelID: string, messageID: string, reaction: string, userID: string): Promise<void>;
@@ -1358,6 +1384,7 @@ declare namespace Eris {
13581384
deleteChannel(channelID: string, reason?: string): Promise<void>;
13591385
deleteChannelPermission(channelID: string, overwriteID: string, reason?: string): Promise<void>;
13601386
deleteGuild(guildID: string): Promise<void>;
1387+
deleteGuildDiscoverySubcategory(guildID: string, categoryID: string, reason?: string): Promise<void>;
13611388
deleteGuildEmoji(guildID: string, emojiID: string, reason?: string): Promise<void>;
13621389
deleteGuildIntegration(guildID: string, integrationID: string): Promise<void>;
13631390
deleteGuildTemplate(guildID: string, code: string): Promise<GuildTemplate>;
@@ -1387,6 +1414,7 @@ declare namespace Eris {
13871414
): Promise<void>;
13881415
editChannelPosition(channelID: string, position: number): Promise<void>;
13891416
editGuild(guildID: string, options: GuildOptions, reason?: string): Promise<Guild>;
1417+
editGuildDiscovery(guildID: string, options?: DiscoveryOptions): Promise<DiscoveryMetadata>;
13901418
editGuildEmoji(
13911419
guildID: string,
13921420
emojiID: string,
@@ -1429,11 +1457,13 @@ declare namespace Eris {
14291457
getChannel(channelID: string): AnyChannel;
14301458
getChannelInvites(channelID: string): Promise<Invite[]>;
14311459
getChannelWebhooks(channelID: string): Promise<Webhook[]>;
1460+
getDiscoveryCategories(): Promise<DiscoveryCategory[]>;
14321461
getDMChannel(userID: string): Promise<PrivateChannel>;
14331462
getGateway(): Promise<{ url: string }>;
14341463
getGuildAuditLogs(guildID: string, limit?: number, before?: string, actionType?: number, userID?: string): Promise<GuildAuditLog>;
14351464
getGuildBan(guildID: string, userID: string): Promise<{ reason?: string; user: User }>;
14361465
getGuildBans(guildID: string): Promise<{ reason?: string; user: User }[]>;
1466+
getGuildDiscovery(guildID: string): Promise<DiscoveryMetadata>;
14371467
/** @deprecated */
14381468
getGuildEmbed(guildID: string): Promise<Widget>;
14391469
getGuildIntegrations(guildID: string): Promise<GuildIntegration[]>;
@@ -1543,6 +1573,7 @@ declare namespace Eris {
15431573
syncGuildTemplate(guildID: string, code: string): Promise<GuildTemplate>;
15441574
unbanGuildMember(guildID: string, userID: string, reason?: string): Promise<void>;
15451575
unpinMessage(channelID: string, messageID: string): Promise<void>;
1576+
validateDiscoverySearchTerm(term: string): Promise<{ valid: boolean }>;
15461577
on: ClientEvents<this>;
15471578
toString(): string;
15481579
}
@@ -1665,11 +1696,42 @@ declare namespace Eris {
16651696
removeRecipient(userID: string): Promise<void>;
16661697
}
16671698

1699+
interface DiscoveryMetadata {
1700+
guild_id: string;
1701+
primary_category_id: number;
1702+
keywords: string[] | null;
1703+
emoji_discoverability_enabled: boolean;
1704+
category_ids: number[];
1705+
}
1706+
1707+
interface DiscoveryOptions {
1708+
primaryCategoryID?: string;
1709+
keywords?: string[];
1710+
emojiDiscoverabilityEnabled?: boolean;
1711+
reason?: string;
1712+
}
1713+
1714+
interface DiscoveryCategory {
1715+
id: number;
1716+
name: {
1717+
default: string;
1718+
localizations?: { [lang: string]: string };
1719+
};
1720+
is_primary: boolean;
1721+
}
1722+
1723+
interface DiscoverySubcategoryResponse {
1724+
guild_id: string;
1725+
category_id: number;
1726+
}
1727+
16681728
export class Guild extends Base {
16691729
afkChannelID: string | null;
16701730
afkTimeout: number;
1731+
applicationID: string | null;
16711732
approximateMemberCount?: number;
16721733
approximatePresenceCount?: number;
1734+
autoRemoved?: boolean;
16731735
banner: string | null;
16741736
bannerURL: string | null;
16751737
channels: Collection<AnyGuildChannel>;
@@ -1678,6 +1740,7 @@ declare namespace Eris {
16781740
description: string | null;
16791741
discoverySplash: string | null;
16801742
discoverySplashURL: string | null;
1743+
emojiCount?: number;
16811744
emojis: Emoji[];
16821745
explicitContentFilter: number;
16831746
features: string[];
@@ -1697,6 +1760,8 @@ declare namespace Eris {
16971760
preferredLocale: string;
16981761
premiumSubscriptionCount?: number;
16991762
premiumTier: number;
1763+
primaryCategory?: DiscoveryCategory;
1764+
primaryCategoryID?: number;
17001765
publicUpdatesChannelID: string;
17011766
region: string;
17021767
roles: Collection<Role>;
@@ -1713,6 +1778,7 @@ declare namespace Eris {
17131778
widgetChannelID?: string | null;
17141779
widgetEnabled?: boolean | null;
17151780
constructor(data: BaseData, client: Client);
1781+
addDiscoverySubcategory(categoryID: string, reason?: string): Promise<DiscoverySubcategoryResponse>;
17161782
addMemberRole(memberID: string, roleID: string, reason?: string): Promise<void>;
17171783
banMember(userID: string, deleteMessageDays?: number, reason?: string): Promise<void>;
17181784
createChannel(name: string): Promise<TextChannel>;
@@ -1738,6 +1804,7 @@ declare namespace Eris {
17381804
createRole(options: RoleOptions | Role, reason?: string): Promise<Role>;
17391805
createTemplate(name: string, description?: string | null): Promise<GuildTemplate>;
17401806
delete(): Promise<void>;
1807+
deleteDiscoverySubcategory(categoryID: string, reason?: string): Promise<void>;
17411808
deleteEmoji(emojiID: string, reason?: string): Promise<void>;
17421809
deleteIntegration(integrationID: string): Promise<void>;
17431810
deleteRole(roleID: string): Promise<void>;
@@ -1748,6 +1815,7 @@ declare namespace Eris {
17481815
dynamicSplashURL(format?: ImageFormat, size?: number): string;
17491816
dynamicDiscoverySplashURL(format?: ImageFormat, size?: number): string;
17501817
edit(options: GuildOptions, reason?: string): Promise<Guild>;
1818+
editDiscovery(options?: DiscoveryOptions): Promise<DiscoveryMetadata>;
17511819
editEmoji(emojiID: string, options: { name: string; roles?: string[] }, reason?: string): Promise<Emoji>;
17521820
editIntegration(integrationID: string, options: IntegrationOptions): Promise<void>;
17531821
editMember(memberID: string, options: MemberOptions, reason?: string): Promise<void>;
@@ -1760,6 +1828,7 @@ declare namespace Eris {
17601828
getAuditLogs(limit?: number, before?: string, actionType?: number, userID?: string): Promise<GuildAuditLog>;
17611829
getBan(userID: string): Promise<{ reason?: string; user: User }>;
17621830
getBans(): Promise<{ reason?: string; user: User }[]>;
1831+
getDiscovery(): Promise<DiscoveryMetadata>;
17631832
/** @deprecated */
17641833
getEmbed(): Promise<Widget>;
17651834
getIntegrations(): Promise<GuildIntegration>;

lib/Client.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ class Client extends EventEmitter {
236236
return this.requestHandler.request("PUT", Endpoints.CHANNEL_RECIPIENT(groupID, userID), true);
237237
}
238238

239+
/**
240+
* Add a guild discovery subcategory
241+
* @param {String} guildID The ID of the guild
242+
* @param {String} categoryID The ID of the discovery category
243+
* @param {String} [reason] The reason to be displayed in audit logs
244+
* @returns {Promise<Object>}
245+
*/
246+
addGuildDiscoverySubcategory(guildID, categoryID, reason) {
247+
return this.requestHandler.request("POST", Endpoints.GUILD_DISCOVERY_CATEGORY(guildID, categoryID), true, {reason});
248+
}
249+
239250
/**
240251
* Add a role to a guild member
241252
* @arg {String} guildID The ID of the guild
@@ -659,6 +670,17 @@ class Client extends EventEmitter {
659670
return this.requestHandler.request("DELETE", Endpoints.GUILD(guildID), true);
660671
}
661672

673+
/**
674+
* Delete a guild discovery subcategory
675+
* @param {String} guildID The ID of the guild
676+
* @param {String} categoryID The ID of the discovery category
677+
* @param {String} [reason] The reason to be displayed in audit logs
678+
* @returns {Promise}
679+
*/
680+
deleteGuildDiscoverySubcategory(guildID, categoryID, reason) {
681+
return this.requestHandler.request("DELETE", Endpoints.GUILD_DISCOVERY_CATEGORY(guildID, categoryID), true, {reason});
682+
}
683+
662684
/**
663685
* Delete a guild emoji object
664686
* @arg {String} guildID The ID of the guild to delete the emoji in
@@ -973,6 +995,25 @@ class Client extends EventEmitter {
973995
}).then((guild) => new Guild(guild, this));
974996
}
975997

998+
/**
999+
* Edit a guild's discovery data
1000+
* @param {String} guildID The ID of the guild
1001+
* @param {Object} [options] The guild discovery data
1002+
* @param {String} [options.primaryCategoryID] The primary discovery category ID
1003+
* @param {Array<String>} [options.keywords] The discovery keywords (max 10)
1004+
* @param {Boolean} [options.emojiDiscoverabilityEnabled] Whether guild info should be shown when emoji info is loaded
1005+
* @param {String} [options.reason] The reason to be displayed in audit logs
1006+
* @returns {Promise<Object>} The updated guild's discovery object
1007+
*/
1008+
editGuildDiscovery(guildID, options = {}) {
1009+
return this.requestHandler.request("PATCH", Endpoints.GUILD_DISCOVERY(guildID), true, {
1010+
primary_category_id: options.primaryCategoryID,
1011+
keywords: options.keywords,
1012+
emoji_discoverability_enabled: options.emojiDiscoverabilityEnabled,
1013+
reason: options.reason
1014+
});
1015+
}
1016+
9761017
/**
9771018
* Edit a guild emoji object
9781019
* @arg {String} guildID The ID of the guild to edit the emoji in
@@ -1416,6 +1457,14 @@ class Client extends EventEmitter {
14161457
return this.requestHandler.request("GET", Endpoints.CHANNEL_WEBHOOKS(channelID), true);
14171458
}
14181459

1460+
/**
1461+
* Get a list of discovery categories
1462+
* @returns {Promise<Array<Object>>}
1463+
*/
1464+
getDiscoveryCategories() {
1465+
return this.requestHandler.request("GET", Endpoints.DISCOVERY_CATEGORIES, true);
1466+
}
1467+
14191468
/**
14201469
* Get a DM channel with a user, or create one if it does not exist
14211470
* @arg {String} userID The ID of the user
@@ -1431,6 +1480,15 @@ class Client extends EventEmitter {
14311480
}).then((privateChannel) => new PrivateChannel(privateChannel, this));
14321481
}
14331482

1483+
/**
1484+
* Get a guild from the guild's emoji ID
1485+
* @param {String} emojiID The ID of the emoji
1486+
* @returns {Promise<Guild>}
1487+
*/
1488+
getEmojiGuild(emojiID) {
1489+
return this.requestHandler.request("GET", Endpoints.CUSTOM_EMOJI_GUILD(emojiID), true).then((result) => new Guild(result, this));
1490+
}
1491+
14341492
/**
14351493
* Get info on connecting to the Discord gateway
14361494
* @returns {Promise<Object>} Resolves with an object containing gateway connection info
@@ -1490,6 +1548,15 @@ class Client extends EventEmitter {
14901548
});
14911549
}
14921550

1551+
/**
1552+
* Get a guild's discovery object
1553+
* @param {String} guildID The ID of the guild
1554+
* @returns {Promise<Object>}
1555+
*/
1556+
getGuildDiscovery(guildID) {
1557+
return this.requestHandler.request("GET", Endpoints.GUILD_DISCOVERY(guildID), true);
1558+
}
1559+
14931560
/**
14941561
* [DEPRECATED] Get a guild's embed object
14951562
* @arg {String} guildID The ID of the guild
@@ -2323,6 +2390,15 @@ class Client extends EventEmitter {
23232390
return this.requestHandler.request("DELETE", Endpoints.CHANNEL_PIN(channelID, messageID), true);
23242391
}
23252392

2393+
/**
2394+
* Validate discovery search term
2395+
* @param {String} term The search term to check
2396+
* @returns {Promise<Object>} An object with a `valid` field which is `true` when valid and `false` when invalid
2397+
*/
2398+
validateDiscoverySearchTerm(term) {
2399+
return this.requestHandler.request("GET", Endpoints.DISCOVERY_VALIDATION + `?term=${encodeURI(term)}`, true);
2400+
}
2401+
23262402
_formatAllowedMentions(allowed) {
23272403
if(!allowed) {
23282404
return this.options.allowedMentions;
@@ -2396,6 +2472,13 @@ class Client extends EventEmitter {
23962472
"voiceConnections",
23972473
"lastReconnectDelay",
23982474
"reconnectAttempts",
2475+
"autoRemoved",
2476+
"applicationID",
2477+
"emojiCount",
2478+
"primaryCategoryID",
2479+
"primaryCategory",
2480+
"categories",
2481+
"keywords",
23992482
...props
24002483
]);
24012484
}

lib/rest/Endpoints.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ module.exports.CHANNEL_RECIPIENT = (groupID, userID)
2626
module.exports.CHANNEL_TYPING = (chanID) => `/channels/${chanID}/typing`;
2727
module.exports.CHANNEL_WEBHOOKS = (chanID) => `/channels/${chanID}/webhooks`;
2828
module.exports.CHANNELS = "/channels";
29+
module.exports.CUSTOM_EMOJI_GUILD = (emojiID) => `/emojis/${emojiID}/guild`;
30+
module.exports.DISCOVERY_CATEGORIES = "/discovery/categories";
31+
module.exports.DISCOVERY_VALIDATION = "/discovery/valid-term";
2932
module.exports.GATEWAY = "/gateway";
3033
module.exports.GATEWAY_BOT = "/gateway/bot";
3134
module.exports.GUILD = (guildID) => `/guilds/${guildID}`;
3235
module.exports.GUILD_AUDIT_LOGS = (guildID) => `/guilds/${guildID}/audit-logs`;
3336
module.exports.GUILD_BAN = (guildID, memberID) => `/guilds/${guildID}/bans/${memberID}`;
3437
module.exports.GUILD_BANS = (guildID) => `/guilds/${guildID}/bans`;
3538
module.exports.GUILD_CHANNELS = (guildID) => `/guilds/${guildID}/channels`;
39+
module.exports.GUILD_DISCOVERY = (guildID) => `/guilds/${guildID}/discovery-metadata`;
40+
module.exports.GUILD_DISCOVERY_CATEGORY = (guildID, categoryID) => `/guilds/${guildID}/discovery-categories/${categoryID}`;
3641
module.exports.GUILD_EMBED = (guildID) => `/guilds/${guildID}/embed`;
3742
module.exports.GUILD_EMOJI = (guildID, emojiID) => `/guilds/${guildID}/emojis/${emojiID}`;
3843
module.exports.GUILD_EMOJIS = (guildID) => `/guilds/${guildID}/emojis`;

0 commit comments

Comments
 (0)