npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kaname-png/revoltx

v2.0.6

Published

RevoltX is a framework for creating Revolt bots.

Downloads

65

Readme

RevoltX Logo

@kaname-png/revoltx

Create Revolt bots in a simple, fast and fun way

GitHub codecov npm npm

Features

  • Full ESM
  • TypeScript & JavaScript support
  • Written in TypeScript
  • Completely Modular and Extendable
  • Command Handler, Arguments, Preconditions and Listeners Store
  • Powered by @sapphire/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.

// 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('<BOT_TOKEN>');
};

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:

{
	"name": "my-awesome-bot",
	"version": "1.0.0",
	"main": "src/main.js"
}

For TypeScript it should be for example:

{
	"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.

import { Client } from '@kaname-png/revoltx';
import { join } from 'path';
import { fileURLToPath } from 'url';

const start = () => {
	const client = new Client({ prefix: '!' });
	await client.login('<BOT_TOKEN>');
};

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.

// 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.

// 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.

// arguments/serverOwner.ts
import { Argument, ArgumentOptions ArgumentResult, PieceContext } from '../lib/structures/argument';
import type { ArgumentContext } from '../utils/interfaces/argument';

// <boolean> is for TypeScript users only.
export class ServerOwnerArgument extends Argument<boolean> {
	// 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<boolean> {
		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.

// 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

// 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

// 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):

This project follows the all-contributors specification. Contributions of any kind welcome!