diff --git a/docs/cli/README.md b/docs/cli/README.md new file mode 100644 index 000000000..2afcb8236 --- /dev/null +++ b/docs/cli/README.md @@ -0,0 +1,30 @@ +# CLI + +Publish commands to the API, install plugins, and use other tools provided by our cli. + +The CLI is your pocketknife for discord bot development. It'll have all features necessary for developing and shipping to production. +``` +Usage: sern [options] [command] + + + ___ ___ _ __ _ __ + / __|/ _ \ '__| '_ \ + \__ \ __/ | | | | | + |___/\___|_| |_| |_| + + Welcome! + If you're new to sern, run npm create @sern/bot for an interactive setup to your new bot project! + + If you have any ideas, suggestions, bug reports, kindly join our support server: https://sern.dev/discord + +Options: + -v, --version output the version number + -h, --help display help for command + +Commands: + init [options] Quickest way to scaffold a new project [DEPRECATED] + plugins [options] Install plugins from https://github.com/sern-handler/awesome-plugins + extra Easy way to add extra things in your sern project + commands Defacto way to manage your slash commands + help [command] display help for command +``` diff --git a/docs/cli/extra.md b/docs/cli/extra.md new file mode 100644 index 000000000..8acf89110 --- /dev/null +++ b/docs/cli/extra.md @@ -0,0 +1,11 @@ + +```sh +Usage: sern extra [options] + +Easy way to add extra things in your sern project + +Options: + -h, --help display help for command +``` + +This command is pretty straightfoward. Install utilities into your application. Assumes you have a sern.config.json. diff --git a/docs/cli/publish.md b/docs/cli/publish.md new file mode 100644 index 000000000..bbbb2f6d9 --- /dev/null +++ b/docs/cli/publish.md @@ -0,0 +1,91 @@ +```sh +Usage: sern commands publish [options] [path] + +New way to manage your slash commands + +Arguments: + path path with respect to current working directory that will locate all published files + +Options: + -i, --import [scriptPath...] Prerequire a script to load into publisher + -t, --token [token] + --appId [applicationId] + -h, --help display help for command +``` +## Implicits +- Automatically reads a .env in the working directory. For seamless integration, your .env file should look like this: +```txt title=".env" +DISCORD_TOKEN= +APPLICATION_ID= +MODE= +``` +- Calls the discord API with the [PUT route](https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands). Wherever your commands directory is located, publish will override the existing application commands at Discord. Existing commands do not count towards the command limit creation daily. + +You may pass these in as command line arguments as well. **CLI arguments take precedence.** +If you do not know how to obtain either of these credentials, + +## Usage + +![usage](../../static/img/Code_-_Insiders_2kTVzm0uIQ.gif) + + +## Features +- Automatically syncs api with your command base +- generates JSON file of output (**.sern/command-data-remote.json**) +- supports publishing direct esm typescript files +- commonjs users need to compile first and then run sern publish on the dist/ output +- prerequire scripts. +- supports a configuration that is the same as the original publish plugin. + + +Each command file can have an extra config that follows this typescript interface: +PermissionResolvable is a discord.js type, but it will accept anything that the discord API accepts + +```ts +interface ValidPublishOptions { + guildIds: string[]; + dmPermission: boolean; + defaultMemberPermissions: PermissionResolvable; +} + +``` +## Prerequiring +Is there a [service](../guide/walkthrough/services) that is required at the top level of a command? +- Create an ES6 script anywhere: + +```ts title="scripts/prerequire.mjs" +import { makeDependencies, single } from '@sern/handler' +import { Client } from 'discord.js' + +await makeDependencies({ + root => root.add({ '@sern/client': single(() => new Client(...options) })) +}) + +await Service('@sern/client').login() +``` +This will create a container for publishing. (as of 0.6.0, client is required or this will crash) + +### Example: command published in guild + +#### Script ran: +``` +sern commands publish -i ./scripts/prerequire.mjs +``` +```ts title=src/commands/ping.ts +import { commandModule, Service, CommandType } from '@sern/handler' + +const client = Service('@sern/client'); + +export const config = { + guildIds: ["889026545715400705"] +} + +export default commandModule( { + type: CommandType.Slash + description: `${client.user.username}'s ping`, + execute: (ctx) => { + ctx.reply('pong') + } +}) + +``` diff --git a/docs/guide/walkthrough/cli.md b/docs/guide/walkthrough/cli.md index 1b1fb4ec9..2e534bec7 100644 --- a/docs/guide/walkthrough/cli.md +++ b/docs/guide/walkthrough/cli.md @@ -20,6 +20,8 @@ sern plugins Make sure to have a correct [sern.config.json](./good-to-know.md#sernconfigjson) ::: +[Click here](../cli) + This will display a menu selection of all installable plugins.
**Note**: You must have a [sern.config.json](good-to-know.md) to use this command. diff --git a/static/img/Code_-_Insiders_2kTVzm0uIQ.gif b/static/img/Code_-_Insiders_2kTVzm0uIQ.gif new file mode 100644 index 000000000..8b131e2fb Binary files /dev/null and b/static/img/Code_-_Insiders_2kTVzm0uIQ.gif differ