From 85dc50863f0dfc61da9ac42eeab675b0a348b462 Mon Sep 17 00:00:00 2001 From: Peter-MJ-Parker <34216187+Peter-MJ-Parker@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:52:08 -0500 Subject: [PATCH 1/6] feat: more readable types Added Context Types for end-users who don't know where each number points to in the array. --- packages/publisher/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/publisher/index.ts b/packages/publisher/index.ts index a5f9785..3a4ebb9 100644 --- a/packages/publisher/index.ts +++ b/packages/publisher/index.ts @@ -176,6 +176,14 @@ export class Publisher implements Init { } } +export enum IntegrationContextType { + GUILD = 0, + BOT_DM = 1, + PRIVATE_CHANNEL = 2 +} + +type Contexts = IntegrationContextType | 0 | 1 | 2; + export type ValidMemberPermissions = | typeof PermissionFlagsBits //discord.js enum | Array @@ -185,8 +193,8 @@ export type ValidMemberPermissions = export interface PublishConfig { guildIds?: string[]; defaultMemberPermissions?: ValidMemberPermissions; - integrationTypes?: Array<'Guild'|'User'> - contexts?: number[] + integrationTypes?: Array<'Guild'|'User'>; + contexts?: Array; } export type ValidPublishOptions = From fe191d3305b99d86e0c29cae27eb5b1bd8a9e02b Mon Sep 17 00:00:00 2001 From: Peter-MJ-Parker <34216187+Peter-MJ-Parker@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:33:34 -0500 Subject: [PATCH 2/6] edit version: new minor New minor version of publisher for easier to read types. --- packages/publisher/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/publisher/package.json b/packages/publisher/package.json index e8ebb31..4f80131 100644 --- a/packages/publisher/package.json +++ b/packages/publisher/package.json @@ -1,7 +1,7 @@ { "name": "@sern/publisher", - "version": "1.1.1", - "description": "Localizer", + "version": "1.1.2", + "description": "Publish commands in sern with ease!", "main": "dist/index.js", "scripts": { "build": "tsc", From ec2b32f60832d68fa1c1f696ff1b67dc24864611 Mon Sep 17 00:00:00 2001 From: Peter-MJ-Parker <34216187+Peter-MJ-Parker@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:32:05 -0500 Subject: [PATCH 3/6] edit: typing change directly imply type of permissions string -> `${number}` remove test ts ignore - no longer needed after v4 release --- packages/publisher/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/publisher/index.ts b/packages/publisher/index.ts index a5f9785..d8983ea 100644 --- a/packages/publisher/index.ts +++ b/packages/publisher/index.ts @@ -179,7 +179,7 @@ export class Publisher implements Init { export type ValidMemberPermissions = | typeof PermissionFlagsBits //discord.js enum | Array - | string //must be a stringified number + | `${number}` //must be a stringified number | bigint export interface PublishConfig { @@ -206,7 +206,6 @@ const IntegrationType = { export const publishConfig = (config: ValidPublishOptions) => { return CommandInitPlugin(({ module, absPath }) => { if((module.type & PUBLISHABLE) === 0) { - //@ts-ignore return controller.stop("Cannot publish this module; Not of type Both,Slash,CtxUsr,CtxMsg."); } let _config=config From 7e291590117c3d9c5c50914fe821f06afee75754 Mon Sep 17 00:00:00 2001 From: Peter-MJ-Parker <34216187+Peter-MJ-Parker@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:35:29 -0500 Subject: [PATCH 4/6] edit: catch up website with package --- packages/publisher/index.mdx | 46 +++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/packages/publisher/index.mdx b/packages/publisher/index.mdx index d4bf5d7..b71d023 100644 --- a/packages/publisher/index.mdx +++ b/packages/publisher/index.mdx @@ -13,7 +13,7 @@ import { makeDependencies } from '@sern/handler'; import { Publisher } from '@sern/publisher'; await makeDependencies(({ add }) => { - add('publisher', new Publisher()); + add('publisher', (deps) => new Publisher(deps['@sern/modules'], deps['@sern/emitter'], deps['@sern/logger'])); }); ``` ## Implicits @@ -36,17 +36,23 @@ Each command file can have an extra plugin `publishConfig` that follows `ValidPu ## Config ```ts +enum IntegrationContextType { + GUILD = 0, + BOT_DM = 1, + PRIVATE_CHANNEL = 2 +} + +type Contexts = IntegrationContextType | 0 | 1 | 2; + type ValidMemberPermissions = - | typeof PermissionFlagBits //discord.js enum - | typeof PermissionFlagBits[] //array of discord.js enum - | string //must be a stringified number - | bigint + | typeof PermissionFlagsBits //discord.js enum + | Array interface PublishConfig { guildIds?: string[]; defaultMemberPermissions?: ValidMemberPermissions; - integrationTypes?: Array<'Guild'|'User'> - contexts: number[] + integrationTypes?: Array<'Guild'|'User'>; + contexts?: Array; } type ValidPublishOptions = | PublishConfig @@ -96,7 +102,7 @@ export default commandModule( { guildIds: ["889026545715400705"] }) ], - description: `hello worl`, + description: `hello world`, execute: (ctx) => { ctx.reply('pong') } @@ -104,3 +110,27 @@ export default commandModule( { ``` +### Explanation of each property in the plugin + +:::tip +Not everyone likes to look at Discords Docs, so here you go +::: + +- `guildIds`: Commands will be published to guilds specified. + - Can have more than one guild id to publish certain commands in + - These commands cannot be used in dms. + +- `defaultMemberPermissions`: Only members with specified permissions can view the command + - If you specify more than one, all perms are required! + +- `integrationTypes`: able to specify guild install or user install commands + - 'Guild': Command is only able to be used in guilds + - 'User': Command can be installed to a users profile to be used everywhere (with limitations) + - Guilds with less than 200 members, developer can specify if the command should be invisible to others (ephemeral) + - Guild with >= 200 members, commands will be forced to be invisible by the Discord API. + +- `contexts`: specify where the user installed commands can be used. + - 0: Only available to be used by the user in GUILDS. + - 1: Only available in Bot dms. + - 2: Any private channel, such as a group dm outside of bots dms. + - Also able to use IntegrationContextType enum from `@sern/publisher` if you don't want to use numbers. From af496c4efee28051b206aedaa753009e7cedc3c9 Mon Sep 17 00:00:00 2001 From: Peter-MJ-Parker <34216187+Peter-MJ-Parker@users.noreply.github.com> Date: Sat, 20 Jul 2024 21:18:30 -0500 Subject: [PATCH 5/6] edit: doc strings for new types --- packages/publisher/index.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/publisher/index.ts b/packages/publisher/index.ts index 895da26..fb9b3cd 100644 --- a/packages/publisher/index.ts +++ b/packages/publisher/index.ts @@ -182,16 +182,30 @@ export enum IntegrationContextType { PRIVATE_CHANNEL = 2 } +/** +* Valid contexts for posting commands. +* 0 - Guild +* 1 - Bot DM +* 2 - Private Channel +* keyof IntegrationContextType +*/ type Contexts = IntegrationContextType | 0 | 1 | 2; +/** +* Permission Resolvable - Not all permission resolvables that discord supports are supported here +* Valid permission types: +* a single permission from `PermissionFlagsBits` +* array of `PermissionFlagsBits` +* stringified permissions ex.: "Administrator" +* V13 djs permissions will not work! +*/ export type ValidMemberPermissions = | typeof PermissionFlagsBits //discord.js enum | Array - | `${number}` //must be a stringified number | bigint export interface PublishConfig { - guildIds?: string[]; + guildIds?: Array<`${number}`>; defaultMemberPermissions?: ValidMemberPermissions; integrationTypes?: Array<'Guild'|'User'>; contexts?: Array; From 92b961adc7427bacc1ea741ac5d1584b37b96081 Mon Sep 17 00:00:00 2001 From: Peter-MJ-Parker <34216187+Peter-MJ-Parker@users.noreply.github.com> Date: Sat, 20 Jul 2024 21:19:32 -0500 Subject: [PATCH 6/6] fix: types for publish on website --- packages/publisher/index.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/publisher/index.mdx b/packages/publisher/index.mdx index b71d023..2f569af 100644 --- a/packages/publisher/index.mdx +++ b/packages/publisher/index.mdx @@ -47,9 +47,10 @@ type Contexts = IntegrationContextType | 0 | 1 | 2; type ValidMemberPermissions = | typeof PermissionFlagsBits //discord.js enum | Array + | bigint interface PublishConfig { - guildIds?: string[]; + guildIds?: Array<`${number}`>; defaultMemberPermissions?: ValidMemberPermissions; integrationTypes?: Array<'Guild'|'User'>; contexts?: Array;