1.16.7 • Published 6 months ago

cordo v1.16.7

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

Cordo

Cordo is a custom api wrapper built for interactions first. It functions as an addon on top of discord.js. Full documentation is yet to be written

Originally built for the FreeStuff Bot, this codebase could find various usecases so we decided to outsource it. Here's an Example bot written with it.

Or if you prefer real-life examples check out FreeStuff Bot or Tudebot.

Use npm i cordo or yarn add cordo to install. Types are included.

How it works (aka quick docs / tutorial)

Commands

Go in bot/commands. They export a handler function as default which gets called when the command gets run.

Components

Go in bot/components. They too export a handler function as default which gets called when the component gets interacted with (button press or dropdown selection). You can create folders to build hierarchy. Each folder prefixes the resulting component id with the foldername and a _ For instance the handler in components/foo/bar/test.ts gets triggered for a component with the custom_id of foo_bar_test

States

States are an extra layer to the Commands and Components that let you define command pages. Instead of editing or sending a response to a Command or Component Interaction, you can just ask it to take form of a state and Cordo will do the rest.

Interaction flow

User presses button -> Check if this interaction has any overrides on timeout -> Check if there are global Component handlers -> Check if there is a state with the same name to take -> Error

User runs command -> Check if command handler exists -> Check if there is a state with the command name and _main -> Error

API Coverage

✔️ Slash Commands

✔️ Command Groups

✔️ Command Autocomplete

✔️ Button Components

✔️ Dropdown Components

❌ Modals

Naming Convensions

Commands may only have one word -> no CamelCase or snake_case needed

Components and States must be prefixed with the command they originated from -> A button on the settings command must start with settings_ (=> be placed inside a folder called settings)

Components must be named by their desired state and not how to get there. Example: Settings command has a page with general settings (settings_main), which has a button for advanced settings (settings_advanced) which has a button to destroy the world. Incorrect naming: settings_advanced_destroy_world Correct naming: settings_destroy_world

States also follow this principle to not inherit the path into the name, only the destination as shown above.

Components that just change state (like "open another page") or have state changing behaviour must be named like states. Example: config_page2, config_name Components that have side effects (like changing settings or alike) must be named with a verb. Example: config_name_change, friends_request_send For those verbs preferably pick:

  • _change for Select/Dropdowns
  • _toggle for Toggle Buttons
  • _enable/_disable for Single Use Buttons

Examples

Component and State names correct and incorrect examples:

❌ back

❌ back_button

❌ state_back

❌ settings_back

❌ settings_advanced_more

❌ command_free_button_one

✔️ settings_main

✔️ settings_description

✔️ free_show_details

✔️ settings_more

Best practices

While theoretically the entire system could be built on soly using states, it is recomended to use interaction.reply and interaction.edit over states in non-interactive environments to save resources. States have a larger overhead than a simply interaction reply.

Cordo is best when it's used stateless. Try to reduce interactive responses to a minimum and always put as much information as possible in the custom ids. This allows for easy scaling as well as a great user experience. It might take some time to get used to but once you understand how to build on this, cordo naturally organizes your code.

1.15.0

10 months ago

1.15.3

10 months ago

1.15.2

10 months ago

1.15.1

10 months ago

1.16.3

8 months ago

1.16.2

8 months ago

1.16.1

8 months ago

1.16.0

8 months ago

1.16.7

6 months ago

1.16.6

6 months ago

1.16.5

6 months ago

1.16.4

8 months ago

1.14.9

11 months ago

1.14.10

11 months ago

1.14.8

1 year ago

1.14.1

1 year ago

1.14.0

1 year ago

1.14.5

1 year ago

1.14.4

1 year ago

1.14.3

1 year ago

1.14.2

1 year ago

1.14.7

1 year ago

1.14.6

1 year ago

1.13.4

1 year ago

1.13.3

2 years ago

1.13.2

2 years ago

1.13.1

2 years ago

1.12.1

2 years ago

1.10.3

2 years ago

1.10.2

2 years ago

1.9.5

2 years ago

1.9.4

2 years ago

1.13.0

2 years ago

1.10.1

2 years ago

1.10.0

2 years ago

1.9.2

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.8.4

3 years ago

1.8.3

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.7.0

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.4.1

3 years ago

1.3.2

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.3.10

3 years ago

1.3.13

3 years ago

1.3.14

3 years ago

1.3.11

3 years ago

1.3.12

3 years ago

1.3.17

3 years ago

1.3.15

3 years ago

1.3.16

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.2.10

3 years ago

1.2.11

3 years ago

1.2.8

3 years ago

1.2.9

3 years ago

1.2.0

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago