Skip to content

Commit 1ede560

Browse files
committed
update middleware behavior
1 parent 00755d8 commit 1ede560

File tree

25 files changed

+202
-167
lines changed

25 files changed

+202
-167
lines changed

apps/test-bot/src/app/commands/(developer)/+middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Logger, MiddlewareContext } from 'commandkit';
1+
import { Logger, MiddlewareContext, stopMiddlewares } from 'commandkit';
22
import { MessageFlags } from 'discord.js';
33

44
export function beforeExecute(ctx: MiddlewareContext) {
@@ -16,7 +16,7 @@ export function beforeExecute(ctx: MiddlewareContext) {
1616
ctx.message.reply('You are not allowed to use this command.');
1717
}
1818

19-
ctx.cancel();
19+
stopMiddlewares();
2020
}
2121
}
2222

apps/test-bot/src/app/commands/(general)/+middleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Logger, MiddlewareContext } from 'commandkit';
1+
import { Logger, MiddlewareContext, stopMiddlewares } from 'commandkit';
22

33
export function beforeExecute(ctx: MiddlewareContext) {
44
Logger.info(
55
`Directory-scoped middleware: ${ctx.commandName} will be executed!`,
66
);
7+
// stopMiddlewares();
78
}
89

910
export function afterExecute(ctx: MiddlewareContext) {

apps/test-bot/src/app/commands/(general)/+ping.middleware.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { Logger, MiddlewareContext } from 'commandkit';
1+
import { Logger, type MiddlewareContext, stopMiddlewares } from 'commandkit';
22

33
export function beforeExecute(ctx: MiddlewareContext) {
4+
Logger.info(`Command-scoped middleware: ${ctx.commandName} will be stopped!`);
45
Logger.info(
5-
`Command-scoped middleware: ${ctx.commandName} will be executed!`,
6+
'None of the other beforeExecute middlewares are supposed to be executed',
67
);
8+
// stopMiddlewares();
79
}
810

911
export function afterExecute(ctx: MiddlewareContext) {

apps/test-bot/src/app/commands/(general)/ping.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
AutocompleteCommandContext,
1212
CommandMetadata,
1313
MessageCommandContext,
14+
stopMiddlewares,
1415
} from 'commandkit';
1516

1617
export const command: CommandData = {
@@ -33,8 +34,8 @@ export const command: CommandData = {
3334
};
3435

3536
export const metadata: CommandMetadata = {
36-
userPermissions: 'Administrator',
37-
botPermissions: 'KickMembers',
37+
// userPermissions: 'Administrator',
38+
// botPermissions: 'KickMembers',
3839
// guilds: ['1314834483660455938'],
3940
};
4041

@@ -98,4 +99,6 @@ export async function chatInput({
9899
button.setDisabled(true);
99100
message.edit({ components: [row] });
100101
});
102+
103+
stopMiddlewares();
101104
}

apps/test-bot/src/app/commands/(interactions)/+middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Logger, MiddlewareContext } from 'commandkit';
1+
import { Logger, MiddlewareContext, stopMiddlewares } from 'commandkit';
22
import { MessageFlags } from 'discord.js';
33

44
export function beforeExecute(ctx: MiddlewareContext) {
@@ -18,7 +18,7 @@ export function beforeExecute(ctx: MiddlewareContext) {
1818
ctx.message.reply('You are not allowed to use this command.');
1919
}
2020

21-
ctx.cancel();
21+
stopMiddlewares();
2222
}
2323
}
2424

apps/test-bot/src/app/commands/+global-middleware.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { Logger, MiddlewareContext } from 'commandkit';
1+
import { Logger, MiddlewareContext, stopMiddlewares } from 'commandkit';
22

33
export function beforeExecute(ctx: MiddlewareContext) {
44
Logger.info(`Global middleware: ${ctx.commandName} will be executed!`);
5+
// ctx.message.reply('Global middleware: This command will not be executed!');
6+
// stopMiddlewares();
57
}
68

79
export function afterExecute(ctx: MiddlewareContext) {
File renamed without changes.

apps/test-bot/src/events/ready/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type EventHandler, Logger } from 'commandkit';
22

33
export const once = true;
44

5-
const handler: EventHandler<'ready'> = (client, c, commandkit) => {
5+
const handler: EventHandler<'clientReady'> = (client, c, commandkit) => {
66
Logger.log(`Ready from legacy event handler: ${client.user.username}`);
77
};
88

apps/website/docs/guide/01-getting-started/02-setup-commandkit.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ that looks something like this:
3737
│ │ ├── commands/
3838
│ │ │ └── ping.ts
3939
│ │ └── events/
40-
│ │ └── ready/
40+
│ │ └── clientReady/
4141
│ │ └── log.ts
4242
│ └── app.ts
4343
├── .env

apps/website/docs/guide/02-commands/06-category-directory.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ plugins, or even other commands through your `commandkit` instance.
3131
│ │ │ ├── kick.ts
3232
│ │ │ └── ban.ts
3333
│ │ └── events/
34-
│ │ └── ready/
34+
│ │ └── clientReady/
3535
│ │ └── log.ts
3636
│ └── app.ts
3737
├── .env

0 commit comments

Comments
 (0)