Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sawa-ko/revoltx
Revoltx is a Framework for revolt.js to create awesome bots.
https://github.com/sawa-ko/revoltx
bot framework revolt revolt-bot
Last synced: 8 days ago
JSON representation
Revoltx is a Framework for revolt.js to create awesome bots.
- Host: GitHub
- URL: https://github.com/sawa-ko/revoltx
- Owner: sawa-ko
- License: mit
- Created: 2022-03-03T23:10:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T17:41:42.000Z (17 days ago)
- Last Synced: 2024-10-29T18:59:53.807Z (17 days ago)
- Topics: bot, framework, revolt, revolt-bot
- Language: TypeScript
- Homepage:
- Size: 10.5 MB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
![RevoltX Logo](https://raw.githubusercontent.com/kaname-png/revoltx/development/.github/assets/logo-transparent.png)
# @kaname-png/revoltx
**Create Revolt bots in a simple, fast and fun way**
[![GitHub](https://img.shields.io/github/license/kaname-png/revoltx)](https://github.com/kaname-png/revoltx/blob/main/LICENSE.md)
[![codecov](https://codecov.io/gh/kaname-png/revoltx/branch/main/graph/badge.svg?token=0MSAyoZNxz)](https://codecov.io/gh/kaname-png/revoltx)
[![npm](https://img.shields.io/npm/v/@kaname-png/revoltx?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@kaname-png/revoltx)
[![npm](https://img.shields.io/npm/dt/@kaname-png/revoltx?color=crimson&logo=npm)](https://www.npmjs.com/package/@kaname-png/revoltx)## Features
- Full ESM
- TypeScript & JavaScript support
- Written in TypeScript
- Completely Modular and Extendable
- Command Handler, Arguments, Preconditions and Listeners Store
- Powered by [@sapphire/framework](https://github.com/sapphiredev/framework) preconditions and arguments system# π Introduction
With RevoltX you have at your disposal the creation of highly typed, secure and easy to make bots with a wide variety of tools and utilities available.
# β Usage
Now you can continue installing the necessary packages.
```
npm i @kaname-png/revoltx revolt.js
```Or
```
yarn add @kaname-png/revoltx revolt.js
```### π€ Client
This is how the client is created and the bot is started.
```typescript
// client.js
import { Client } from '@kaname-png/revoltx';
import { join } from 'path';
import { fileURLToPath } from 'url';const start = () => {
const client = new Client({ prefix: '!' });
await client.login('');
};void start();
```Now you can start bot as follows:
```
node --experimental-specifier-resolution=node client.js
```To set the path to the commands, listeners, etc. you need to indicate the path to your "main.js" file (the file which starts your bot) in the "main" property of your `package.json` file.
> Remember that the name of your main file `(main.js)` is up to you.
For JavaScript it should be for example:
```json
{
"name": "my-awesome-bot",
"version": "1.0.0",
"main": "src/main.js"
}
```For TypeScript it should be for example:
```json
{
"name": "my-awesome-bot",
"version": "1.0.0",
"main": "dist/main.js"
}
```### π Folder Structure
Once the client is created and instantiated, it is time to configure where all your commands, listeners, arguments, etc. are located.
```typescript
import { Client } from '@kaname-png/revoltx';
import { join } from 'path';
import { fileURLToPath } from 'url';const start = () => {
const client = new Client({ prefix: '!' });
await client.login('');
};
```Our project should have a folder structure like this.
```
ββββcommands
β ββββhelp.js
ββββmain.js
```# π Create command
Basic structure of a basic command.
Commands are actions that users can request to the bot by means of a prefix and command name, e.g.: `n!help`.
```typescript
// commands/help.ts
import { Command, CommandOptions, PieceContext } from '@kaname-png/revoltx';
import type { Message } from 'revolt.js';export class HelpCommand extends Command {
// If you need to add extra options to the command, you can do it in the constructor, it is not required if you don't need to add options.
constructor(context: PieceContext, options: CommandOptions) {
super(context, {
...options,
alias: ['helpme']
/* optional commands options */
});
}public async run(message: Message) {
return message.reply('@kaname-png/revoltx');
}
}
```# π Create listener
Basic structure of a basic listener.
The listeners have the function of listening to events that the client emits by default, but you can assign the emitter you need and listen to the events of that emitter.
```typescript
// listener/message.ts
import { Listener, ListenerOptions ClientEvents, PieceContext } from '@kaname-png/revoltx';
import type { Message } from 'revolt.js';export class MessageListener extends Listener {
// You can set the event name you need.
constructor(context: PieceContext, options: ListenerOptions) {
super(context, {
...options,
event: ClientEvents.MessageCreate
/* optional listeners options */
});
}public async run(message: Message) {
return message.reply('@kaname-png/revoltx');
}
}
```# π‘οΈ Create Argument
Basic structure of a basic argument.
Arguments are parameters that the bot receives from the message sent by the user. This argument system allows to use arguments dynamically as needed, and not only by configuring the command options.```typescript
// arguments/serverOwner.ts
import { Argument, ArgumentOptions ArgumentResult, PieceContext } from '../lib/structures/argument';
import type { ArgumentContext } from '../utils/interfaces/argument';// is for TypeScript users only.
export class ServerOwnerArgument extends Argument {
// Asign name of argument
public constructor(context: PieceContext, options: ArgumentOptions) {
super(context, {
...options,
name: 'ServerOwner'
/* optional arguments options */
});
}public run(parameter: string, context: ArgumentContext): ArgumentResult {
const resolved = message.member?.server?.owner === parameter;
if (!resolved) return this.ok(true);return this.error({
parameter,
identifier: resolved.error,
message: 'The argument did not resolve to server owner.',
context
});
}
}// For TypeScript users only.
declare module '@kaname-png/revoltx' {
interface ArgType {
// The type returned by the this.ok() method;
ServerOwner: boolean;
}
}// Command Usage
// User Input: n!server @kaname-png
import { Args, Command } from '@kaname-png/revoltx';
import type { Message } from 'revolt.js';export class ServerCommand extends Command {
public run(message: Message, args: Args) {
const owner = await args.pick('ServerOwner');
return message.channel?.sendMessage(owner ? 'You are server owner.' : 'You are not the owner of the server.');
}
}
```# π‘οΈ Create Precondition
Basic structure of a basic precondition.
```typescript
// preconditions/nsfw.ts
import type { PieceContext, Precondition, PreconditionOptions, PreconditionResult, Identifiers } from '@kaname-png/revoltx';
import type { Message } from 'revolt.js';export class NSFWPrecondition extends Precondition {
public constructor(context: PieceContext, options: PreconditionOptions) {
super(context, {
...options,
name: 'NSFW'
/* optional preconditions options */
});
}public run(message: Message): PreconditionResult {
return message.channel?.nsfw === true
? this.ok()
: this.error({ identifier: Identifiers.PreconditionsNsfw, message: 'You cannot run this command outside NSFW channels.' });
}
}// For TypeScript users only.
declare module '@kaname-png/revoltx' {
interface Preconditions {
// Name of precondition
NSFW: never;
}
}
```# π Notes
1. More examples in the comments of the corresponding classes.
2. The examples shown are written in TypeScript, but you can replicate them in JavaScript by simply removing the variable types.#### Example of converting TypeScript code to JavaScript code:
> This also applies to arguments, listeners, preconditions, etc.
TypeScript code
```typescript
// commands/help.ts
import { Command, CommandOptions, PieceContext } from '@kaname-png/revoltx';
import type { Message } from 'revolt.js';export class HelpCommand extends Command {
// If you need to add extra options to the command, you can do it in the constructor, it is not required if you don't need to add options.
constructor(context: PieceContext, options: CommandOptions) {
super(context, {
...options
/* optional commands options */
});
}public run(message: Message) {
return message.reply('@kaname-png/revoltx');
}
}
```JavaScript code
```javascript
// commands/help.js
import { Command } from '@kaname-png/revoltx';export class HelpCommand extends Command {
// If you need to add extra options to the command, you can do it in the constructor, it is not required if you don't need to add options.
constructor(context, options) {
super(context, {
...options
/* optional commands options */
});
}run(message) {
return message.reply('@kaname-png/revoltx');
}
}
```## Contributors β¨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Kaname
π π» π π€ π§ π π
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!