@wolfstar/create-http-framework 2.1.4 → 2.2.0-next-20260831123711
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -18
- package/dist/index.js +241 -41
- package/package.json +7 -3
- package/template/{.env.hbs → base/.env.hbs} +2 -0
- package/template/base/README.md.hbs +33 -0
- package/template/base/src/commands/ping.js.hbs +18 -0
- package/template/{src → base/src}/commands/ping.ts.hbs +3 -1
- package/template/base/src/lib/setup/all.js.hbs +8 -0
- package/template/base/src/lib/setup/all.ts.hbs +8 -0
- package/template/base/src/lib/setup/logger.js.hbs +4 -0
- package/template/base/src/lib/setup/logger.ts.hbs +10 -0
- package/template/base/src/lib/types/augments.ts.hbs +13 -0
- package/template/base/src/main.js.hbs +31 -0
- package/template/base/src/main.ts.hbs +31 -0
- package/template/features/i18n/src/commands/ping.js.hbs +18 -0
- package/template/features/i18n/src/commands/ping.ts.hbs +15 -0
- package/template/features/i18n/src/locales/en-US/commands/ping.json +5 -0
- package/template/features/i18n/src/main.js.hbs +37 -0
- package/template/features/i18n/src/main.ts.hbs +37 -0
- package/template/features/subcommands/src/commands/math.js.hbs +41 -0
- package/template/features/subcommands/src/commands/math.ts.hbs +38 -0
- package/template/features/subcommands-advanced/src/commands/settings.js.hbs +53 -0
- package/template/features/subcommands-advanced/src/commands/settings.ts.hbs +70 -0
- package/template/features/subcommands-advanced-i18n/src/commands/settings.js.hbs +78 -0
- package/template/features/subcommands-advanced-i18n/src/commands/settings.ts.hbs +62 -0
- package/template/features/subcommands-advanced-i18n/src/locales/en-US/commands/settings.json +22 -0
- package/template/features/subcommands-i18n/src/commands/math.js.hbs +46 -0
- package/template/features/subcommands-i18n/src/commands/math.ts.hbs +43 -0
- package/template/features/subcommands-i18n/src/locales/en-US/commands/math.json +14 -0
- package/template/features/testing/tests/ping.test.js.hbs +33 -0
- package/template/features/testing/tests/ping.test.ts.hbs +33 -0
- package/template/features/testing/vitest.config.js.hbs +9 -0
- package/template/features/testing/vitest.config.ts.hbs +9 -0
- package/template/features/testing/vitest.setup.js.hbs +4 -0
- package/template/features/testing/vitest.setup.ts.hbs +4 -0
- package/template/features/testing-i18n/tests/ping.test.js.hbs +42 -0
- package/template/features/testing-i18n/tests/ping.test.ts.hbs +42 -0
- package/template/src/commands/ping.js.hbs +0 -12
- package/template/src/index.js.hbs +0 -8
- package/template/src/index.ts.hbs +0 -8
- /package/template/{.gitignore.hbs → base/.gitignore.hbs} +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Command, RegisterCommand, RegisterSubcommand } from '@wolfstar/http-framework';
|
|
2
|
+
import { applyLocalizedBuilder, getSupportedUserLanguageT } from '@wolfstar/plugin-i18next';
|
|
3
|
+
import { ApplicationIntegrationType, InteractionContextType } from 'discord-api-types/v10';
|
|
4
|
+
|
|
5
|
+
@RegisterCommand((builder) =>
|
|
6
|
+
applyLocalizedBuilder(builder, 'commands/math:name', 'commands/math:description') //
|
|
7
|
+
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)
|
|
8
|
+
.setContexts(InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel)
|
|
9
|
+
)
|
|
10
|
+
export class MathCommand extends Command {
|
|
11
|
+
@RegisterSubcommand((builder) =>
|
|
12
|
+
applyLocalizedBuilder(builder, 'commands/math:addName', 'commands/math:addDescription') //
|
|
13
|
+
.addIntegerOption((option) =>
|
|
14
|
+
applyLocalizedBuilder(option, 'commands/math:optionsLeftName', 'commands/math:optionsLeftDescription').setRequired(true)
|
|
15
|
+
)
|
|
16
|
+
.addIntegerOption((option) =>
|
|
17
|
+
applyLocalizedBuilder(option, 'commands/math:optionsRightName', 'commands/math:optionsRightDescription').setRequired(true)
|
|
18
|
+
)
|
|
19
|
+
)
|
|
20
|
+
public add(interaction: Command.ChatInputInteraction, { left, right }: MathOptions) {
|
|
21
|
+
const t = getSupportedUserLanguageT(interaction);
|
|
22
|
+
return interaction.reply({ content: t('commands/math:addResult', { left, right, result: left + right }) });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@RegisterSubcommand((builder) =>
|
|
26
|
+
applyLocalizedBuilder(builder, 'commands/math:subtractName', 'commands/math:subtractDescription') //
|
|
27
|
+
.addIntegerOption((option) =>
|
|
28
|
+
applyLocalizedBuilder(option, 'commands/math:optionsLeftName', 'commands/math:optionsLeftDescription').setRequired(true)
|
|
29
|
+
)
|
|
30
|
+
.addIntegerOption((option) =>
|
|
31
|
+
applyLocalizedBuilder(option, 'commands/math:optionsRightName', 'commands/math:optionsRightDescription').setRequired(true)
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
public subtract(interaction: Command.ChatInputInteraction, { left, right }: MathOptions) {
|
|
35
|
+
const t = getSupportedUserLanguageT(interaction);
|
|
36
|
+
return interaction.reply({ content: t('commands/math:subtractResult', { left, right, result: left - right }) });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface MathOptions {
|
|
41
|
+
left: number;
|
|
42
|
+
right: number;
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "math",
|
|
3
|
+
"description": "Perform basic arithmetic",
|
|
4
|
+
"addName": "add",
|
|
5
|
+
"addDescription": "Add two numbers",
|
|
6
|
+
"subtractName": "subtract",
|
|
7
|
+
"subtractDescription": "Subtract two numbers",
|
|
8
|
+
"optionsLeftName": "left",
|
|
9
|
+
"optionsLeftDescription": "The left operand",
|
|
10
|
+
"optionsRightName": "right",
|
|
11
|
+
"optionsRightDescription": "The right operand",
|
|
12
|
+
"addResult": "{{left}} + {{right}} = {{result}}",
|
|
13
|
+
"subtractResult": "{{left}} - {{right}} = {{result}}"
|
|
14
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { container } from '@wolfstar/http-framework';
|
|
2
|
+
import { ChatInputApplicationCommandInteractionData, createTestHarness } from '@wolfstar/http-framework-test-utils';
|
|
3
|
+
import { MessageFlags } from 'discord-api-types/v10';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { PingCommand } from '../src/commands/ping.js';
|
|
6
|
+
|
|
7
|
+
describe('ping command', () => {
|
|
8
|
+
it('replies with Pong', async () => {
|
|
9
|
+
const { client, runner } = createTestHarness();
|
|
10
|
+
|
|
11
|
+
await container.stores.loadPiece({ name: 'ping', piece: PingCommand, store: 'commands' });
|
|
12
|
+
await client.load({ baseUserDirectory: null });
|
|
13
|
+
|
|
14
|
+
const result = await runner.run({
|
|
15
|
+
...ChatInputApplicationCommandInteractionData,
|
|
16
|
+
data: {
|
|
17
|
+
id: '0',
|
|
18
|
+
name: 'ping',
|
|
19
|
+
type: 1,
|
|
20
|
+
options: []
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
expect(result).toHaveStatus(200);
|
|
25
|
+
expect(result.json()).toMatchObject({
|
|
26
|
+
type: 4,
|
|
27
|
+
data: {
|
|
28
|
+
content: 'Pong!',
|
|
29
|
+
flags: MessageFlags.Ephemeral
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { container } from '@wolfstar/http-framework';
|
|
2
|
+
import { ChatInputApplicationCommandInteractionData, createTestHarness } from '@wolfstar/http-framework-test-utils';
|
|
3
|
+
import { MessageFlags } from 'discord-api-types/v10';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { PingCommand } from '../src/commands/ping.js';
|
|
6
|
+
|
|
7
|
+
describe('ping command', () => {
|
|
8
|
+
it('replies with Pong', async () => {
|
|
9
|
+
const { client, runner } = createTestHarness();
|
|
10
|
+
|
|
11
|
+
await container.stores.loadPiece({ name: 'ping', piece: PingCommand, store: 'commands' });
|
|
12
|
+
await client.load({ baseUserDirectory: null });
|
|
13
|
+
|
|
14
|
+
const result = await runner.run({
|
|
15
|
+
...ChatInputApplicationCommandInteractionData,
|
|
16
|
+
data: {
|
|
17
|
+
id: '0',
|
|
18
|
+
name: 'ping',
|
|
19
|
+
type: 1,
|
|
20
|
+
options: []
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
expect(result).toHaveStatus(200);
|
|
25
|
+
expect(result.json()).toMatchObject({
|
|
26
|
+
type: 4,
|
|
27
|
+
data: {
|
|
28
|
+
content: 'Pong!',
|
|
29
|
+
flags: MessageFlags.Ephemeral
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import '@wolfstar/plugin-i18next/register';
|
|
2
|
+
import { container } from '@wolfstar/http-framework';
|
|
3
|
+
import { ChatInputApplicationCommandInteractionData, createTestHarness } from '@wolfstar/http-framework-test-utils';
|
|
4
|
+
import { MessageFlags } from 'discord-api-types/v10';
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
import { PingCommand } from '../src/commands/ping.js';
|
|
7
|
+
|
|
8
|
+
describe('ping command', () => {
|
|
9
|
+
it('replies with Pong', async () => {
|
|
10
|
+
// The i18n plugin resolves `container.i18n` from `Client`'s `i18n` option, so the harness needs
|
|
11
|
+
// the same options passed to `new Client()` in `src/main.js` — pointing at the locale files
|
|
12
|
+
// under `src/locales/`, one directory up from this test file.
|
|
13
|
+
const { client, runner } = createTestHarness({
|
|
14
|
+
i18n: {
|
|
15
|
+
defaultLanguageDirectory: new URL('../src/locales', import.meta.url).pathname,
|
|
16
|
+
defaultName: 'en-US'
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await container.stores.loadPiece({ name: 'ping', piece: PingCommand, store: 'commands' });
|
|
21
|
+
await client.load({ baseUserDirectory: null });
|
|
22
|
+
|
|
23
|
+
const result = await runner.run({
|
|
24
|
+
...ChatInputApplicationCommandInteractionData,
|
|
25
|
+
data: {
|
|
26
|
+
id: '0',
|
|
27
|
+
name: 'ping',
|
|
28
|
+
type: 1,
|
|
29
|
+
options: []
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(result).toHaveStatus(200);
|
|
34
|
+
expect(result.json()).toMatchObject({
|
|
35
|
+
type: 4,
|
|
36
|
+
data: {
|
|
37
|
+
content: 'Pong!',
|
|
38
|
+
flags: MessageFlags.Ephemeral
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import '@wolfstar/plugin-i18next/register';
|
|
2
|
+
import { container } from '@wolfstar/http-framework';
|
|
3
|
+
import { ChatInputApplicationCommandInteractionData, createTestHarness } from '@wolfstar/http-framework-test-utils';
|
|
4
|
+
import { MessageFlags } from 'discord-api-types/v10';
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
import { PingCommand } from '../src/commands/ping.js';
|
|
7
|
+
|
|
8
|
+
describe('ping command', () => {
|
|
9
|
+
it('replies with Pong', async () => {
|
|
10
|
+
// The i18n plugin resolves `container.i18n` from `Client`'s `i18n` option, so the harness needs
|
|
11
|
+
// the same options passed to `new Client()` in `src/main.ts` — pointing at the locale files
|
|
12
|
+
// under `src/locales/`, one directory up from this test file.
|
|
13
|
+
const { client, runner } = createTestHarness({
|
|
14
|
+
i18n: {
|
|
15
|
+
defaultLanguageDirectory: new URL('../src/locales', import.meta.url).pathname,
|
|
16
|
+
defaultName: 'en-US'
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await container.stores.loadPiece({ name: 'ping', piece: PingCommand, store: 'commands' });
|
|
21
|
+
await client.load({ baseUserDirectory: null });
|
|
22
|
+
|
|
23
|
+
const result = await runner.run({
|
|
24
|
+
...ChatInputApplicationCommandInteractionData,
|
|
25
|
+
data: {
|
|
26
|
+
id: '0',
|
|
27
|
+
name: 'ping',
|
|
28
|
+
type: 1,
|
|
29
|
+
options: []
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(result).toHaveStatus(200);
|
|
34
|
+
expect(result.json()).toMatchObject({
|
|
35
|
+
type: 4,
|
|
36
|
+
data: {
|
|
37
|
+
content: 'Pong!',
|
|
38
|
+
flags: MessageFlags.Ephemeral
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Command } from '@wolfstar/http-framework';
|
|
2
|
-
import { MessageFlags } from 'discord-api-types/v10';
|
|
3
|
-
|
|
4
|
-
export class PingCommand extends Command {
|
|
5
|
-
chatInputRun(interaction) {
|
|
6
|
-
return interaction.reply({ content: 'Pong!', flags: MessageFlags.Ephemeral });
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
static builder = (builder) => builder
|
|
10
|
-
.setName('ping')
|
|
11
|
-
.setDescription('Replies with pong!')
|
|
12
|
-
}
|
|
File without changes
|