2.2.1 • Published 3 months ago

@skyra/http-framework v2.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 months ago

@skyra/http-framework

Some stuff to fill in later.

TODO

  • Support for reloading and unloading commands
  • Logging integration similar to @sapphire/plugin-logger.
    • Log levels
    • Colorette powered Colours
    • Timestamps
    • Logging similar to framework (registering commands, errors, successes, etc)

Usage

This library can do both handling HTTP interactions and registering commands both globally and per guild using an integrated design.

Command

The Command is a piece that runs for all chat input and context-menu interactions, including auto-complete (since this one is sort of part of context-menu). Registering the commands happens with decorators:

import { Command, RegisterCommand } from '@skyra/http-framework';

@RegisterCommand({ name: 'ping', description: 'Runs a network connection test with me.' })
export class UserCommand extends Command {
	public chatInputRun(interaction: APIApplicationCommandInteraction): APIInteractionResponse {
		return {
			type: InteractionResponseType.ChannelMessageWithSource,
			data: { content: 'Pong!' }
		};
	}
}

You can also register subcommands via decorators:

import { type ArgumentsOf, Command, RegisterCommand, RegisterSubCommandGroup, makeSubCommandBody } from '@skyra/http-framework';
import { type APIApplicationCommandInteraction, type APIInteractionResponse, ApplicationCommandOptionType } from 'discord-api-types/v9';

@RegisterCommand({ name: 'math', description: 'Does some maths.' })
export class UserCommand extends Command {
	@RegisterSubCommandGroup(addBody);
	public add(interaction: APIApplicationCommandInteraction, { first, second }: ArgumentsOf<typeof addBody>): APIInteractionResponse {
		return {
			type: InteractionResponseType.ChannelMessageWithSource,
			data: { content: `The result is: ${first + second}` }
		};
	}
}

const addBody = makeSubCommandBody({
	type: ApplicationCommandOptionType.Subcommand,
	name: 'add',
	description: 'Adds two numbers.',
	options: [
		{ type: ApplicationCommandOptionType.Number, name: 'first', description: 'The first number.' },
		{ type: ApplicationCommandOptionType.Number, name: 'second', description: 'The second number.' }
	]
});

Client

The Client class contains the HTTP server, powered by fastify, it also registers a handler which processes whether or not the HTTP request comes from Discord, then processes the information accordingly, handling the heavy weight in the background.

import { Client } from '@skyra/http-framework';

const client = new Client({
	discordPublicKey: process.env.DISCORD_PUBLIC_KEY
});

// Load all the commands and message component handlers:
await client.load();

// Start up the HTTP server;
await client.listen({ port: 3000 });

Registry

The Registry class is a wrapper around @skyra/http-framework's internal registries and uses @discordjs/rest to register them in Discord.

import { Registry } from '@skyra/http-framework';

const registry = new Registry({
	token: process.env.DISCORD_TOKEN
});

// Load all the commands and message component handlers:
await registry.load();

// Register all global commands:
await registry.registerGlobalCommands();

// Register all the guild-restricted commands:
await registry.registerGuildRestrictedCommands();
2.2.1-next.3971d50

9 months ago

2.2.0-next.4baa8d0

10 months ago

2.2.1-next.23d9751

4 months ago

2.2.1-next.295c963

6 months ago

2.2.1-next.07a19fa

6 months ago

2.2.0-next.d38f55b

10 months ago

2.2.2-next.66e03ad

4 months ago

2.2.1-next.4ec0b23

10 months ago

2.2.1-next.a3a91cc

8 months ago

2.2.1-next.ef259a2

6 months ago

2.2.1-next.db2f8ae

8 months ago

2.2.2-next.2250521

4 months ago

2.2.0-next.c4cb7ee

10 months ago

2.2.1-next.add5d0e

4 months ago

2.2.1-next.182fd3f

4 months ago

2.2.1-next.dbe950f

5 months ago

2.2.2-next.24453e7

3 months ago

2.2.1-next.9143271

4 months ago

2.2.0-next.c3e268f

10 months ago

2.2.2-next.1f60028

4 months ago

2.2.1-next.4d7ae8c

8 months ago

2.2.1-next.6bf7063

4 months ago

2.2.1-next.c69764e

4 months ago

2.2.1-next.2fd587f

4 months ago

2.2.2-next.c11c390

3 months ago

2.2.1-next.9b52063

4 months ago

2.2.1-next.5393a0c

9 months ago

2.2.2-next.fea29a6

4 months ago

2.2.1

4 months ago

2.2.0

10 months ago

2.2.1-next.43dafe2

4 months ago

2.2.2-next.38fda83

4 months ago

2.2.2-next.f5aff3e

4 months ago

2.2.2-next.b9be90a

3 months ago

2.2.1-next.dc85943

4 months ago

2.2.1-next.2fa6457

4 months ago

2.2.2-next.ce5c7b6

4 months ago

2.2.1-next.de81fe1

9 months ago

2.2.2-next.6d0d41b

4 months ago

2.2.2-next.8bd9594

3 months ago

2.2.0-next.4d41316

10 months ago

2.2.1-next.6311944

10 months ago

2.2.1-next.b222bb6

9 months ago

2.2.1-next.51fce94

8 months ago

2.2.1-next.a6ef540

4 months ago

2.2.2-next.492fcc8

4 months ago

2.2.0-next.b1b6cde

10 months ago

2.2.0-next.2a3232b

10 months ago

2.2.0-next.160a43d

10 months ago

2.2.0-next.3ef7779

10 months ago

2.2.0-next.c043105

11 months ago

2.2.0-next.a92e0a3

11 months ago

2.2.0-next.7f53fbb

11 months ago

2.2.0-next.75a2e6d

11 months ago

2.2.0-next.b998ff0

12 months ago

2.1.0

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.15.4

2 years ago

0.15.5

2 years ago

0.15.2

3 years ago

0.15.3

3 years ago

0.15.1

3 years ago

0.13.0

3 years ago

0.15.0

3 years ago

0.12.0

3 years ago

0.14.0

3 years ago

0.11.0

3 years ago

0.11.1

3 years ago

0.10.0

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.9.0

3 years ago

0.8.1

3 years ago

0.7.2

3 years ago

0.6.3

3 years ago

0.5.4

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.6.2

3 years ago

0.5.6

3 years ago

0.6.4

3 years ago

0.5.5

3 years ago

0.7.0

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.3

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.0.10

3 years ago

0.1.0

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.3.6

3 years ago

0.0.9

3 years ago

0.3.5

3 years ago

0.0.8

3 years ago

0.3.7

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.2.2

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.1

3 years ago