From e10e6cbd2f43aac75f830c7e6c193f4eee23f84d Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 29 Jul 2023 11:09:03 -0500 Subject: [PATCH] upgrades to guide and frontpage --- docs/guide/README.md | 11 ++++-- docs/guide/walkthrough/autocomplete.md | 45 ++++++++++++++++++++++++ docs/guide/walkthrough/goal.md | 4 +-- docs/guide/walkthrough/good-to-know.md | 2 +- docs/guide/walkthrough/sern-emitter.md | 2 +- src/components/HomepageFeatures/index.js | 3 +- 6 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 docs/guide/walkthrough/autocomplete.md diff --git a/docs/guide/README.md b/docs/guide/README.md index 4a6d54a..87cfe71 100644 --- a/docs/guide/README.md +++ b/docs/guide/README.md @@ -4,6 +4,9 @@ Welcome to our official guide. This guide will go through all the core features - 💖 Thank you for choosing sern to be your framework! - Teaching the discord.js library and / or Javascript / Typescript is out of scope of this project, so the documentation assumes you already know these elements. + - [discord.js](https://discord.js.org/#/) + - [javascript](https://nodejs.dev/en/learn/) + - [typescript](https://www.typescriptlang.org/docs/) - discord.js v14 is the only supported library at the moment @@ -12,11 +15,13 @@ Welcome to our official guide. This guide will go through all the core features * How to use sern with the [CLI](walkthrough/cli.md) * [Your first command](walkthrough/first-command.md) * [The Context class](walkthrough/first-command.md#context-class) - +* [Autocomplete](walkthrough/autocomplete) +* [Services](walkthrough/services) +* [dependency injection](walkthrough/dependency-injection) ### Working with plugins * [Plugins](walkthrough/plugins.md) - - [Command Plugins](walkthrough/plugins.md#command-plugins) - - [Event Plugins](walkthrough/plugins.md#event-plugins) + - [Init Plugins](walkthrough/plugins.md#command-plugins) + - [Control Plugins](walkthrough/plugins.md#event-plugins) ### Events * [The SernEmitter class](walkthrough/sern-emitter.md) * [Your first event](walkthrough/first-event.md) diff --git a/docs/guide/walkthrough/autocomplete.md b/docs/guide/walkthrough/autocomplete.md new file mode 100644 index 0000000..60e3ce8 --- /dev/null +++ b/docs/guide/walkthrough/autocomplete.md @@ -0,0 +1,45 @@ +--- +sidebar_position: 7 +--- + +# Autocomplete + + +Autocomplete is a special interaction where it can happen on multiple options on a single command. We've handled this with a simple +tree search algorithm in a nested options tree. + +## Example + +```ts title="src/commands/cheese.ts" {11-18} +export default commandModule({ + type: CommandType.Slash, + description: "show me cheese", + options: [ + { + name: "list", + type: ApplicationCommandOptionType.String, + description: "pick a cheese to show", + required: true, + autocomplete: true, + command: { + onEvent: [], + execute: (ctx) => { + const focus = ctx.options.getFocused(); + ctx.respond(['gouda', 'parmesan', 'harvati'] + .map((cheese) => ({ name: cheese, value: cheese }))); + } + } + } + ], + execute: (ctx, [, args]) => { + const cheese = args.getString('list', true); + ctx.reply('selected cheese'); + } +}) + + +``` + +Sern will handle autocomplete interactions at arbitrary depths and subcommand levels. + + diff --git a/docs/guide/walkthrough/goal.md b/docs/guide/walkthrough/goal.md index 7e6c397..0ca832e 100644 --- a/docs/guide/walkthrough/goal.md +++ b/docs/guide/walkthrough/goal.md @@ -12,7 +12,7 @@ This walkthrough will be written in [TypeScript](https://www.typescriptlang.org/ - *Modularity*: sern is built with modularity in mind. You can swap pieces and parts easily. - *Familiar*: commands and structures are similar to classic v12 handlers and the official discord.js command handler guide, while packing many features -- *Concise*: Too much code is a liability. with sern, write more for less 🤯 +- *Concise*: Too much code is a liability. with sern, write less for more 🤯 ### Using @sapphire/framework @@ -40,7 +40,6 @@ import { commandModule, CommandType } from '@sern/handler' import { publish } from '../plugins'; export default commandModule({ - //This acts as both a slash command AND text command type: CommandType.Both, plugins: [publish()], description: 'Pong!', @@ -49,3 +48,4 @@ export default commandModule({ } }) ``` +Keep in mind the above example acts as both a slash command AND text command diff --git a/docs/guide/walkthrough/good-to-know.md b/docs/guide/walkthrough/good-to-know.md index ee28ec3..e69f722 100644 --- a/docs/guide/walkthrough/good-to-know.md +++ b/docs/guide/walkthrough/good-to-know.md @@ -1,5 +1,5 @@ --- -sidebar_position: 8 +sidebar_position: 9 --- # Good to know diff --git a/docs/guide/walkthrough/sern-emitter.md b/docs/guide/walkthrough/sern-emitter.md index f9df6cb..d25a6ae 100644 --- a/docs/guide/walkthrough/sern-emitter.md +++ b/docs/guide/walkthrough/sern-emitter.md @@ -1,5 +1,5 @@ --- -sidebar_position: 6 +sidebar_position: 8 --- # The SernEmitter class diff --git a/src/components/HomepageFeatures/index.js b/src/components/HomepageFeatures/index.js index 1cdb9ba..dc16607 100644 --- a/src/components/HomepageFeatures/index.js +++ b/src/components/HomepageFeatures/index.js @@ -28,7 +28,8 @@ const FeatureList = [ Svg: require('@site/static/img/fire-com.svg').default, description: ( <> - Code like a traditional command handler. Feels and looks like classic v12 command handlers. + Code like a traditional command handler. Although not exactly the same, the api is easy to learn + and resembles classic v12 command handlers. ), },