From 52cf958b1d3a2fa0ec07c18c1a3cfc6b0c1bf8e8 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sat, 17 Sep 2022 18:00:15 +0200 Subject: [PATCH 1/6] fix(dnt): private name errors --- dnt.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dnt.ts b/dnt.ts index 41f4f5836..63faf0751 100644 --- a/dnt.ts +++ b/dnt.ts @@ -19,6 +19,8 @@ await build({ name: "WebSocket", exportName: "default", }, + { name: "CloseEvent", typeOnly: true }, + { name: "MessageEvent", typeOnly: true }, ], }, ], From a4268fae44e8c06683ab8f9a3022e6392adccdf6 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 17 Sep 2022 11:10:07 -0500 Subject: [PATCH 2/6] Update constants.ts --- util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/constants.ts b/util/constants.ts index 87d3bb542..02b7ba288 100644 --- a/util/constants.ts +++ b/util/constants.ts @@ -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 = "15.0.4"; /** https://discord.com/developers/docs/reference#user-agent */ export const USER_AGENT = `DiscordBot (https://github.com/discordeno/discordeno, v${DISCORDENO_VERSION})`; From 7198bba04936aeb7e8081a41bc3360d3793c2e4d Mon Sep 17 00:00:00 2001 From: LTS20050703 Date: Sat, 17 Sep 2022 23:11:31 +0700 Subject: [PATCH 3/6] BREAKING: Remove server discovery helpers due to lack of support (#2464) * Remove server discovery helpers due to lack of support The helpers found under `/helpers/discovery` directory are undocumented and not for public bot use. * delete discovery test and permission check * deno fmt --- helpers/discovery/addDiscoverySubcategory.ts | 22 ------- .../discovery/deleteDiscoverySubcategory.ts | 22 ------- helpers/discovery/editDiscovery.ts | 57 ------------------- helpers/discovery/getDiscovery.ts | 43 -------------- helpers/discovery/getDiscoveryCategories.ts | 37 ------------ helpers/discovery/getIsValidDiscoveryTerm.ts | 21 ------- helpers/discovery/mod.ts | 6 -- helpers/mod.ts | 1 - plugins/permissions/mod.ts | 2 - plugins/permissions/src/discovery.ts | 49 ---------------- tests/misc/discovery.test.ts | 22 ------- 11 files changed, 282 deletions(-) delete mode 100644 helpers/discovery/addDiscoverySubcategory.ts delete mode 100644 helpers/discovery/deleteDiscoverySubcategory.ts delete mode 100644 helpers/discovery/editDiscovery.ts delete mode 100644 helpers/discovery/getDiscovery.ts delete mode 100644 helpers/discovery/getDiscoveryCategories.ts delete mode 100644 helpers/discovery/getIsValidDiscoveryTerm.ts delete mode 100644 helpers/discovery/mod.ts delete mode 100644 plugins/permissions/src/discovery.ts delete mode 100644 tests/misc/discovery.test.ts diff --git a/helpers/discovery/addDiscoverySubcategory.ts b/helpers/discovery/addDiscoverySubcategory.ts deleted file mode 100644 index 8f5689fab..000000000 --- a/helpers/discovery/addDiscoverySubcategory.ts +++ /dev/null @@ -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 { - return await bot.rest.runMethod( - bot.rest, - "POST", - bot.constants.routes.DISCOVERY_SUBCATEGORY(guildId, categoryId), - ); -} diff --git a/helpers/discovery/deleteDiscoverySubcategory.ts b/helpers/discovery/deleteDiscoverySubcategory.ts deleted file mode 100644 index 5e3a96b5c..000000000 --- a/helpers/discovery/deleteDiscoverySubcategory.ts +++ /dev/null @@ -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 { - return await bot.rest.runMethod( - bot.rest, - "DELETE", - bot.constants.routes.DISCOVERY_SUBCATEGORY(guildId, categoryId), - ); -} diff --git a/helpers/discovery/editDiscovery.ts b/helpers/discovery/editDiscovery.ts deleted file mode 100644 index 42b210964..000000000 --- a/helpers/discovery/editDiscovery.ts +++ /dev/null @@ -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 { - const result = await bot.rest.runMethod( - 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; -} diff --git a/helpers/discovery/getDiscovery.ts b/helpers/discovery/getDiscovery.ts deleted file mode 100644 index cc2d60fb8..000000000 --- a/helpers/discovery/getDiscovery.ts +++ /dev/null @@ -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 { - const result = await bot.rest.runMethod( - 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, - }; -} diff --git a/helpers/discovery/getDiscoveryCategories.ts b/helpers/discovery/getDiscoveryCategories.ts deleted file mode 100644 index 99780388d..000000000 --- a/helpers/discovery/getDiscoveryCategories.ts +++ /dev/null @@ -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; -}; - -/** - * 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> { - const results = await bot.rest.runMethod( - 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]; - }), - ); -} diff --git a/helpers/discovery/getIsValidDiscoveryTerm.ts b/helpers/discovery/getIsValidDiscoveryTerm.ts deleted file mode 100644 index 3f908bf74..000000000 --- a/helpers/discovery/getIsValidDiscoveryTerm.ts +++ /dev/null @@ -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 { - const result = await bot.rest.runMethod( - bot.rest, - "GET", - bot.constants.routes.DISCOVERY_VALID_TERM(term), - ); - - return result.valid; -} diff --git a/helpers/discovery/mod.ts b/helpers/discovery/mod.ts deleted file mode 100644 index af88f4fb6..000000000 --- a/helpers/discovery/mod.ts +++ /dev/null @@ -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"; diff --git a/helpers/mod.ts b/helpers/mod.ts index 69e2dce9e..a7c92b836 100644 --- a/helpers/mod.ts +++ b/helpers/mod.ts @@ -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"; diff --git a/plugins/permissions/mod.ts b/plugins/permissions/mod.ts index 8c5f1e6d3..c373adc88 100644 --- a/plugins/permissions/mod.ts +++ b/plugins/permissions/mod.ts @@ -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 bot.enabledPlugins.add("PERMISSIONS"); // BEGIN OVERRIDING HELPER FUNCTIONS - setupDiscoveryPermChecks(bot); channels(bot); emojis(bot); guilds(bot); diff --git a/plugins/permissions/src/discovery.ts b/plugins/permissions/src/discovery.ts deleted file mode 100644 index a4f353117..000000000 --- a/plugins/permissions/src/discovery.ts +++ /dev/null @@ -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); -} diff --git a/tests/misc/discovery.test.ts b/tests/misc/discovery.test.ts deleted file mode 100644 index 9650aeda1..000000000 --- a/tests/misc/discovery.test.ts +++ /dev/null @@ -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); - }, -}); From e88a63770b561910ad5ae59062baf4369677609a Mon Sep 17 00:00:00 2001 From: LTS20050703 Date: Sat, 17 Sep 2022 23:12:42 +0700 Subject: [PATCH 4/6] BREAKING: MANAGE_EMOJIS -> MANAGE_EMOJIS_AND_STICKERS (#2473) * types: MANAGE_EMOJIS -> MANAGE_EMOJIS_AND_STICKERS * deno fmt Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Co-authored-by: ITOH --- plugins/permissions/src/emojis/createEmoji.ts | 2 +- plugins/permissions/src/emojis/deleteEmoji.ts | 2 +- plugins/permissions/src/emojis/editEmoji.ts | 2 +- types/shared.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/permissions/src/emojis/createEmoji.ts b/plugins/permissions/src/emojis/createEmoji.ts index f17e5456d..9fa8e1e03 100644 --- a/plugins/permissions/src/emojis/createEmoji.ts +++ b/plugins/permissions/src/emojis/createEmoji.ts @@ -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); }; diff --git a/plugins/permissions/src/emojis/deleteEmoji.ts b/plugins/permissions/src/emojis/deleteEmoji.ts index 8ea880efc..7a63dbfa3 100644 --- a/plugins/permissions/src/emojis/deleteEmoji.ts +++ b/plugins/permissions/src/emojis/deleteEmoji.ts @@ -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); }; diff --git a/plugins/permissions/src/emojis/editEmoji.ts b/plugins/permissions/src/emojis/editEmoji.ts index 122c87f6c..5d7f3cba5 100644 --- a/plugins/permissions/src/emojis/editEmoji.ts +++ b/plugins/permissions/src/emojis/editEmoji.ts @@ -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); }; diff --git a/types/shared.ts b/types/shared.ts index a8ca0acdf..df8f14645 100644 --- a/types/shared.ts +++ b/types/shared.ts @@ -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. */ From c8275fcadca408f414ecfa0dee749adbaf47667f Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 17 Sep 2022 11:17:13 -0500 Subject: [PATCH 5/6] Update constants.ts --- util/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/constants.ts b/util/constants.ts index 02b7ba288..57b2b485c 100644 --- a/util/constants.ts +++ b/util/constants.ts @@ -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.4"; +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})`; From 23771ea9495f7f10828789751779e25b69e43c6a Mon Sep 17 00:00:00 2001 From: ITOH Date: Sat, 17 Sep 2022 23:06:45 +0200 Subject: [PATCH 6/6] feat(types)!: add `two_way_link` to `DiscordConnection` (#2481) When the connection has a corresponding thrid party OAuth2 token `two_way_link` will be set to `true`. Reference: https://github.com/discordeno/discordeno/issues/2479 Closes: #2479 --- types/discord.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/discord.ts b/types/discord.ts index e57182d77..d92b94002 100644 --- a/types/discord.ts +++ b/types/discord.ts @@ -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 */