This commit is contained in:
Skillz4Killz
2022-09-20 03:52:23 +00:00
committed by GitHub
18 changed files with 10 additions and 288 deletions
+2
View File
@@ -19,6 +19,8 @@ await build({
name: "WebSocket",
exportName: "default",
},
{ name: "CloseEvent", typeOnly: true },
{ name: "MessageEvent", typeOnly: true },
],
},
],
@@ -1,22 +0,0 @@
import type { Bot } from "../../bot.ts";
/**
* Adds a discovery subcategory to a guild.
*
* @param bot - The bot instance to use to make the request.
* @param guildId - The ID of the guild to add the subcategory to.
* @param categoryId - The ID of the category to add to the guild.
*
* @remarks
* Requires the `MANAGE_GUILD` permission.
*
* @privateRemarks
* This endpoint is not formally documented.
*/
export async function addDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number): Promise<void> {
return await bot.rest.runMethod<void>(
bot.rest,
"POST",
bot.constants.routes.DISCOVERY_SUBCATEGORY(guildId, categoryId),
);
}
@@ -1,22 +0,0 @@
import type { Bot } from "../../bot.ts";
/**
* Deletes a discovery subcategory from a guild.
*
* @param bot - The bot instance to use to make the request.
* @param guildId - The ID of the guild to delete the subcategory from.
* @param categoryId - The ID of the category to delete from the guild.
*
* @remarks
* Requires the `MANAGE_GUILD` permission.
*
* @privateRemarks
* This endpoint is not formally documented.
*/
export async function deleteDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number): Promise<void> {
return await bot.rest.runMethod<void>(
bot.rest,
"DELETE",
bot.constants.routes.DISCOVERY_SUBCATEGORY(guildId, categoryId),
);
}
-57
View File
@@ -1,57 +0,0 @@
import type { Bot } from "../../bot.ts";
import { DiscordDiscoveryMetadata } from "../../types/discord.ts";
import { DiscoveryMetadata } from "./getDiscovery.ts";
/**
* Edits the discovery settings of a guild.
*
* @param bot - The bot instance to use to make the request.
* @param guildId - The ID of the guild to edit the discovery settings of.
* @param options - The parameters for the edit of the discovery settings.
*
* @remarks
* Requires the `MANAGE_GUILD` permission.
*
* @privateRemarks
* This endpoint is not formally documented.
*/
export async function editDiscovery(
bot: Bot,
guildId: bigint,
options: ModifyGuildDiscoveryMetadata,
): Promise<DiscoveryMetadata> {
const result = await bot.rest.runMethod<DiscordDiscoveryMetadata>(
bot.rest,
"PATCH",
bot.constants.routes.DISCOVERY_METADATA(guildId),
{
primary_category_id: options.primaryCategoryId,
keywords: options.keywords,
emoji_discoverability_enabled: options.emojiDiscoverabilityEnabled,
},
);
return {
guildId,
primaryCategoryId: result.primary_category_id,
keywords: result.keywords ?? undefined,
emojiDiscoverabilityEnabled: result.emoji_discoverability_enabled,
partnerActionedTimestamp: result.partner_actioned_timestamp
? Date.parse(result.partner_actioned_timestamp)
: undefined,
partnerApplicationTimestamp: result.partner_application_timestamp
? Date.parse(result.partner_application_timestamp)
: undefined,
categoryIds: result.category_ids,
};
}
// TODO: add docs link
export interface ModifyGuildDiscoveryMetadata {
/** The id of the primary discovery category. Default: 0 */
primaryCategoryId?: number | null;
/** Up to 10 discovery search keywords. Default: null */
keywords?: string[] | null;
/** Whether guild info is shown when custom emojis are clicked. Default: true */
emojiDiscoverabilityEnabled?: boolean | null;
}
-43
View File
@@ -1,43 +0,0 @@
import type { Bot } from "../../bot.ts";
import { DiscordDiscoveryMetadata } from "../../types/discord.ts";
export type DiscoveryMetadata = {
guildId: bigint;
primaryCategoryId: number;
keywords?: string[];
emojiDiscoverabilityEnabled: boolean;
partnerActionedTimestamp?: number;
partnerApplicationTimestamp?: number;
categoryIds: number[];
};
/**
* Gets the discovery settings of a guild.
*
* @param bot - The bot instance to use to make the request.
* @param guildId - The ID of the guild to get the discovery settings of.
*
* @privateRemarks
* This endpoint is not formally documented.
*/
export async function getDiscovery(bot: Bot, guildId: bigint): Promise<DiscoveryMetadata> {
const result = await bot.rest.runMethod<DiscordDiscoveryMetadata>(
bot.rest,
"GET",
bot.constants.routes.DISCOVERY_METADATA(guildId),
);
return {
guildId,
primaryCategoryId: result.primary_category_id,
keywords: result.keywords ?? undefined,
emojiDiscoverabilityEnabled: result.emoji_discoverability_enabled,
partnerActionedTimestamp: result.partner_actioned_timestamp
? Date.parse(result.partner_actioned_timestamp)
: undefined,
partnerApplicationTimestamp: result.partner_application_timestamp
? Date.parse(result.partner_application_timestamp)
: undefined,
categoryIds: result.category_ids,
};
}
@@ -1,37 +0,0 @@
import type { Bot } from "../../bot.ts";
import { DiscordDiscoveryCategory } from "../../types/discord.ts";
import { Collection } from "../../util/collection.ts";
export type DiscoveryCategory = {
id: bigint;
name: DiscoveryName;
isPrimary: boolean;
};
export type DiscoveryName = {
default: string;
localizations?: Record<string, string>;
};
/**
* Gets the list of available discovery categories.
*
* @param bot - The bot instance to use to make the request.
*
* @privateRemarks
* This endpoint is not formally documented.
*/
export async function getDiscoveryCategories(bot: Bot): Promise<Collection<bigint, DiscoveryCategory>> {
const results = await bot.rest.runMethod<DiscordDiscoveryCategory[]>(
bot.rest,
"GET",
bot.constants.routes.DISCOVERY_CATEGORIES(),
);
return new Collection(
results.map((result) => {
const category = { id: BigInt(result.id), name: result.name, isPrimary: result.is_primary };
return [category.id, category];
}),
);
}
@@ -1,21 +0,0 @@
import type { Bot } from "../../bot.ts";
import { DiscordValidateDiscoverySearchTerm } from "../../types/discord.ts";
/**
* Gets the validity of a discovery term.
*
* @param bot - The bot instance to use to make the request.
* @param term - The term to validate.
*
* @privateRemarks
* This endpoint is not formally documented.
*/
export async function getIsValidDiscoveryTerm(bot: Bot, term: string): Promise<boolean> {
const result = await bot.rest.runMethod<DiscordValidateDiscoverySearchTerm>(
bot.rest,
"GET",
bot.constants.routes.DISCOVERY_VALID_TERM(term),
);
return result.valid;
}
-6
View File
@@ -1,6 +0,0 @@
export * from "./addDiscoverySubcategory.ts";
export * from "./deleteDiscoverySubcategory.ts";
export * from "./editDiscovery.ts";
export * from "./getDiscovery.ts";
export * from "./getDiscoveryCategories.ts";
export * from "./getIsValidDiscoveryTerm.ts";
-1
View File
@@ -1,5 +1,4 @@
export * from "./channels/mod.ts";
export * from "./discovery/mod.ts";
export * from "./emojis/mod.ts";
export * from "./guilds/mod.ts";
export * from "./interactions/mod.ts";
-2
View File
@@ -1,6 +1,5 @@
import { BotWithCache } from "./deps.ts";
import { channels } from "./src/channels/mod.ts";
import setupDiscoveryPermChecks from "./src/discovery.ts";
import { emojis } from "./src/emojis/mod.ts";
import { guilds } from "./src/guilds/mod.ts";
import { integrations } from "./src/integrations/mod.ts";
@@ -18,7 +17,6 @@ export function enablePermissionsPlugin<B extends BotWithCache = BotWithCache>(b
bot.enabledPlugins.add("PERMISSIONS");
// BEGIN OVERRIDING HELPER FUNCTIONS
setupDiscoveryPermChecks(bot);
channels(bot);
emojis(bot);
guilds(bot);
-49
View File
@@ -1,49 +0,0 @@
import { BotWithCache } from "../deps.ts";
import { requireBotGuildPermissions } from "./permissions.ts";
export function addDiscoverySubcategory(bot: BotWithCache) {
const addDiscoverySubcategoryOld = bot.helpers.addDiscoverySubcategory;
bot.helpers.addDiscoverySubcategory = async function (guildId, categoryId) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
return await addDiscoverySubcategoryOld(guildId, categoryId);
};
}
export function deleteDiscoverySubcategory(bot: BotWithCache) {
const deleteDiscoverySubcategoryOld = bot.helpers.deleteDiscoverySubcategory;
bot.helpers.deleteDiscoverySubcategory = async function (guildId, categoryId) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
return await deleteDiscoverySubcategoryOld(guildId, categoryId);
};
}
export function getDiscovery(bot: BotWithCache) {
const getDiscoveryOld = bot.helpers.getDiscovery;
bot.helpers.getDiscovery = async function (guildId) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
return await getDiscoveryOld(guildId);
};
}
export function editDiscovery(bot: BotWithCache) {
const editDiscoveryOld = bot.helpers.editDiscovery;
bot.helpers.editDiscovery = async function (guildId, data) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
return await editDiscoveryOld(guildId, data);
};
}
export default function setupDiscoveryPermChecks(bot: BotWithCache) {
addDiscoverySubcategory(bot);
editDiscovery(bot);
getDiscovery(bot);
deleteDiscoverySubcategory(bot);
}
@@ -5,7 +5,7 @@ export function createEmoji(bot: BotWithCache) {
const createEmoji = bot.helpers.createEmoji;
bot.helpers.createEmoji = async function (guildId, id) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS"]);
requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS_AND_STICKERS"]);
return await createEmoji(guildId, id);
};
@@ -5,7 +5,7 @@ export function deleteEmoji(bot: BotWithCache) {
const deleteEmoji = bot.helpers.deleteEmoji;
bot.helpers.deleteEmoji = async function (guildId, id) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS"]);
requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS_AND_STICKERS"]);
return await deleteEmoji(guildId, id);
};
+1 -1
View File
@@ -5,7 +5,7 @@ export function editEmoji(bot: BotWithCache) {
const editEmoji = bot.helpers.editEmoji;
bot.helpers.editEmoji = async function (guildId, id, options) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS"]);
requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS_AND_STICKERS"]);
return await editEmoji(guildId, id, options);
};
-22
View File
@@ -1,22 +0,0 @@
import { assertEquals } from "../deps.ts";
import { loadBot } from "../mod.ts";
Deno.test({
name: "[discovery] get categories from discovery",
fn: async (t) => {
const bot = loadBot();
const categories = await bot.helpers.getDiscoveryCategories();
assertEquals(categories.size > 0, true);
},
});
Deno.test({
name: "[discovery] Validate a discovery search term",
fn: async (t) => {
const bot = loadBot();
const valid = await bot.helpers.getIsValidDiscoveryTerm("Bots");
assertEquals(valid, true);
},
});
+2
View File
@@ -99,6 +99,8 @@ export interface DiscordConnection {
/** An array of partial server integrations */
integrations?: DiscordIntegration[];
/** Whether this connection has a corresponding third party OAuth2 token. */
two_way_link: boolean;
}
/** https://discord.com/developers/docs/resources/user#connection-object-services */
+2 -2
View File
@@ -630,8 +630,8 @@ export enum BitwisePermissionFlags {
MANAGE_ROLES = 0x0000000010000000,
/** Allows management and editing of webhooks */
MANAGE_WEBHOOKS = 0x0000000020000000,
/** Allows management and editing of emojis */
MANAGE_EMOJIS = 0x0000000040000000,
/** Allows management and editing of emojis and stickers */
MANAGE_EMOJIS_AND_STICKERS = 0x0000000040000000,
/** Allows members to use application commands in text channels */
USE_SLASH_COMMANDS = 0x0000000080000000,
/** Allows for requesting to speak in stage channels. */
+1 -1
View File
@@ -6,7 +6,7 @@ export const API_VERSION = 10;
// TODO: update this version
/** https://github.com/discordeno/discordeno/releases */
export const DISCORDENO_VERSION = "15.0.3";
export const DISCORDENO_VERSION = "16.0.0";
/** https://discord.com/developers/docs/reference#user-agent */
export const USER_AGENT = `DiscordBot (https://github.com/discordeno/discordeno, v${DISCORDENO_VERSION})`;