mirror of
https://github.com/sern-handler/tools
synced 2026-06-06 01:16:59 +00:00
Merge pull request #10 from Peter-MJ-Parker/patch-1
refactor: more readable context types
This commit is contained in:
@@ -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,24 @@ 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
|
||||
| typeof PermissionFlagsBits //discord.js enum
|
||||
| Array<typeof PermissionFlagsBits>
|
||||
| bigint
|
||||
|
||||
interface PublishConfig {
|
||||
guildIds?: string[];
|
||||
guildIds?: Array<`${number}`>;
|
||||
defaultMemberPermissions?: ValidMemberPermissions;
|
||||
integrationTypes?: Array<'Guild'|'User'>
|
||||
contexts: number[]
|
||||
integrationTypes?: Array<'Guild'|'User'>;
|
||||
contexts?: Array<Contexts>;
|
||||
}
|
||||
type ValidPublishOptions =
|
||||
| PublishConfig
|
||||
@@ -96,7 +103,7 @@ export default commandModule( {
|
||||
guildIds: ["889026545715400705"]
|
||||
})
|
||||
],
|
||||
description: `hello worl`,
|
||||
description: `hello world`,
|
||||
execute: (ctx) => {
|
||||
ctx.reply('pong')
|
||||
}
|
||||
@@ -104,3 +111,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.
|
||||
|
||||
@@ -176,17 +176,39 @@ export class Publisher implements Init {
|
||||
}
|
||||
}
|
||||
|
||||
export enum IntegrationContextType {
|
||||
GUILD = 0,
|
||||
BOT_DM = 1,
|
||||
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<typeof PermissionFlagsBits>
|
||||
| string //must be a stringified number
|
||||
| bigint
|
||||
|
||||
export interface PublishConfig {
|
||||
guildIds?: string[];
|
||||
guildIds?: Array<`${number}`>;
|
||||
defaultMemberPermissions?: ValidMemberPermissions;
|
||||
integrationTypes?: Array<'Guild'|'User'>
|
||||
contexts?: number[]
|
||||
integrationTypes?: Array<'Guild'|'User'>;
|
||||
contexts?: Array<Contexts>;
|
||||
}
|
||||
|
||||
export type ValidPublishOptions =
|
||||
@@ -206,7 +228,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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user