@wolfstar/shared-http-pieces 2.0.13-next-20261017100959 โ 2.1.0
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 +18 -0
- package/dist/_load-Grew5qvM.d.ts +1 -0
- package/dist/_load-OFB2jZdk.js +199 -0
- package/dist/_load-OFB2jZdk.js.map +1 -0
- package/dist/module.d.ts +14 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +26 -0
- package/dist/module.js.map +1 -0
- package/dist/pieces.d.ts +12 -0
- package/dist/pieces.d.ts.map +1 -0
- package/dist/pieces.js +14 -0
- package/dist/pieces.js.map +1 -0
- package/dist/register.d.ts +1 -1
- package/dist/register.js +3 -196
- package/dist/register.js.map +1 -1
- package/package.json +21 -3
package/README.md
CHANGED
|
@@ -29,6 +29,24 @@ The shared commands used for Star Network's HTTP-only bots.
|
|
|
29
29
|
which the Stars CLI injects on its own โ no manual wiring is required. The resolved path
|
|
30
30
|
is also exported as `localesPath`, if you need it directly.
|
|
31
31
|
|
|
32
|
+
## As a module
|
|
33
|
+
|
|
34
|
+
Instead of importing `register`, list the package in `modules` in `stars.config` (it needs `@wolfstar/kit`, an
|
|
35
|
+
optional peer dependency):
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// stars.config.ts
|
|
39
|
+
import { defineConfig } from '@wolfstar/http-framework/config';
|
|
40
|
+
|
|
41
|
+
export default defineConfig({ modules: ['@wolfstar/shared-http-pieces'] });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The module adds this package's locales with `ctx.addLocales` (the generated `stars:locales` plugin merges them into
|
|
45
|
+
the `i18n` option before `@wolfstar/plugin-i18next` builds its handler, keeping the project's own languages) and
|
|
46
|
+
registers the `@wolfstar/shared-http-pieces/pieces` plugin, which loads the shared commands and listeners and the
|
|
47
|
+
plugin's own `register` entrypoint. Importing `@wolfstar/shared-http-pieces/register` keeps working; use one or the
|
|
48
|
+
other, not both. Sentry and the information variables below are set up the same way either way.
|
|
49
|
+
|
|
32
50
|
## Usage
|
|
33
51
|
|
|
34
52
|
You can either register after setting environment parameters:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { Command, Listener } from "@wolfstar/http-framework";
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { i as getRepository, n as isSentryInitialized, r as getInvite } from "./sentry-CKHik3nm.js";
|
|
2
|
+
import { captureException } from "@sentry/node";
|
|
3
|
+
import { Command, Listener, RegisterCommand, container, isUserError } from "@wolfstar/http-framework";
|
|
4
|
+
import { applyLocalizedBuilder, getSupportedUserLanguageName, getSupportedUserLanguageT } from "@wolfstar/plugin-i18next";
|
|
5
|
+
import { EmbedBuilder, TimestampStyles, time } from "@discordjs/builders";
|
|
6
|
+
import { ButtonStyle, ComponentType, MessageFlags } from "discord-api-types/v10";
|
|
7
|
+
import { cpus, uptime } from "node:os";
|
|
8
|
+
|
|
9
|
+
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/decorate.js
|
|
10
|
+
function __decorate(decorators, target, key, desc) {
|
|
11
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/commands/info.ts
|
|
19
|
+
var _SharedCommand;
|
|
20
|
+
let SharedCommand = _SharedCommand = class SharedCommand extends Command {
|
|
21
|
+
chatInputRun(interaction) {
|
|
22
|
+
const t = getSupportedUserLanguageT(interaction);
|
|
23
|
+
const lng = getSupportedUserLanguageName(interaction);
|
|
24
|
+
const embed = new EmbedBuilder().setDescription(t("commands/shared:infoEmbedDescription")).addFields(this.getUptimeStatistics(t), this.getServerUsageStatistics(t, lng));
|
|
25
|
+
const components = this.getComponents(t);
|
|
26
|
+
return interaction.reply({
|
|
27
|
+
embeds: [embed.toJSON()],
|
|
28
|
+
components,
|
|
29
|
+
flags: MessageFlags.Ephemeral
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
getUptimeStatistics(t) {
|
|
33
|
+
const nowSeconds = Math.round(Date.now() / 1e3);
|
|
34
|
+
return {
|
|
35
|
+
name: t("commands/shared:infoFieldUptimeTitle"),
|
|
36
|
+
value: t("commands/shared:infoFieldUptimeValue", {
|
|
37
|
+
host: time(Math.round(nowSeconds - uptime()), TimestampStyles.RelativeTime),
|
|
38
|
+
client: time(Math.round(nowSeconds - process.uptime()), TimestampStyles.RelativeTime)
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
getServerUsageStatistics(t, lng) {
|
|
43
|
+
const usage = process.memoryUsage();
|
|
44
|
+
return {
|
|
45
|
+
name: t("commands/shared:infoFieldServerUsageTitle"),
|
|
46
|
+
value: t("commands/shared:infoFieldServerUsageValue", {
|
|
47
|
+
cpu: cpus().map(_SharedCommand.formatCpuInfo.bind(null)).join(" | "),
|
|
48
|
+
heapUsed: (usage.heapUsed / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 }),
|
|
49
|
+
heapTotal: (usage.heapTotal / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 })
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
getComponents(t) {
|
|
54
|
+
const url = getInvite();
|
|
55
|
+
const support = this.getSupportComponent(t);
|
|
56
|
+
const github = this.getGitHubComponent(t);
|
|
57
|
+
const donate = this.getDonateComponent(t);
|
|
58
|
+
return url ? [this.getActionRow(support, this.getInviteComponent(t, url)), this.getActionRow(github, donate)] : [this.getActionRow(support, github, donate)];
|
|
59
|
+
}
|
|
60
|
+
getActionRow(...components) {
|
|
61
|
+
return {
|
|
62
|
+
type: ComponentType.ActionRow,
|
|
63
|
+
components
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
getSupportComponent(t) {
|
|
67
|
+
return {
|
|
68
|
+
type: ComponentType.Button,
|
|
69
|
+
style: ButtonStyle.Link,
|
|
70
|
+
label: t("commands/shared:infoButtonSupport"),
|
|
71
|
+
emoji: { name: "๐" },
|
|
72
|
+
url: "https://discord.gg/6gakFR2"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
getInviteComponent(t, url) {
|
|
76
|
+
return {
|
|
77
|
+
type: ComponentType.Button,
|
|
78
|
+
style: ButtonStyle.Link,
|
|
79
|
+
label: t("commands/shared:infoButtonInvite"),
|
|
80
|
+
emoji: { name: "๐" },
|
|
81
|
+
url
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
getGitHubComponent(t) {
|
|
85
|
+
return {
|
|
86
|
+
type: ComponentType.Button,
|
|
87
|
+
style: ButtonStyle.Link,
|
|
88
|
+
label: t("commands/shared:infoButtonGitHub"),
|
|
89
|
+
emoji: {
|
|
90
|
+
id: "950888087188283422",
|
|
91
|
+
name: "github2"
|
|
92
|
+
},
|
|
93
|
+
url: getRepository()
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
getDonateComponent(t) {
|
|
97
|
+
return {
|
|
98
|
+
type: ComponentType.Button,
|
|
99
|
+
style: ButtonStyle.Link,
|
|
100
|
+
label: t("commands/shared:infoButtonDonate"),
|
|
101
|
+
emoji: { name: "๐งก" },
|
|
102
|
+
url: "https://donate.wolfstar.rocks"
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
static formatCpuInfo({ times }) {
|
|
106
|
+
return `${Math.round((times.user + times.nice + times.sys + times.irq) / times.idle * 1e4) / 100}%`;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
SharedCommand = _SharedCommand = __decorate([RegisterCommand((builder) => applyLocalizedBuilder(builder, "commands/shared:info"))], SharedCommand);
|
|
110
|
+
container.stores.loadPiece({
|
|
111
|
+
name: "info",
|
|
112
|
+
piece: SharedCommand,
|
|
113
|
+
store: "commands"
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/listeners/SharedAutocompleteError.ts
|
|
118
|
+
var SharedListener$3 = class extends Listener {
|
|
119
|
+
constructor(context, options) {
|
|
120
|
+
super(context, {
|
|
121
|
+
...options,
|
|
122
|
+
event: "autocompleteError",
|
|
123
|
+
enabled: isSentryInitialized()
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
run(error, context) {
|
|
127
|
+
captureException(error, (scope) => scope.setLevel("error").setTag("event", this.name).setExtra("command", context.command.name));
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
container.stores.loadPiece({
|
|
131
|
+
name: "SharedAutocompleteError",
|
|
132
|
+
piece: SharedListener$3,
|
|
133
|
+
store: "listeners"
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/listeners/SharedCommandError.ts
|
|
138
|
+
var SharedListener$2 = class extends Listener {
|
|
139
|
+
constructor(context, options) {
|
|
140
|
+
super(context, {
|
|
141
|
+
...options,
|
|
142
|
+
event: "commandError",
|
|
143
|
+
enabled: isSentryInitialized()
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
run(error, context) {
|
|
147
|
+
captureException(error, (scope) => scope.setLevel("error").setTag("event", this.name).setExtra("command", context.command.name));
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
container.stores.loadPiece({
|
|
151
|
+
name: "SharedCommandError",
|
|
152
|
+
piece: SharedListener$2,
|
|
153
|
+
store: "listeners"
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/listeners/SharedError.ts
|
|
158
|
+
var SharedListener$1 = class extends Listener {
|
|
159
|
+
constructor(context, options) {
|
|
160
|
+
super(context, {
|
|
161
|
+
...options,
|
|
162
|
+
event: "error",
|
|
163
|
+
enabled: isSentryInitialized()
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
run(error) {
|
|
167
|
+
if (isUserError(error)) return;
|
|
168
|
+
captureException(error, (scope) => scope.setLevel("error").setTag("event", this.name));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
container.stores.loadPiece({
|
|
172
|
+
name: "SharedError",
|
|
173
|
+
piece: SharedListener$1,
|
|
174
|
+
store: "listeners"
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/listeners/SharedInteractionHandlerError.ts
|
|
179
|
+
var SharedListener = class extends Listener {
|
|
180
|
+
constructor(context, options) {
|
|
181
|
+
super(context, {
|
|
182
|
+
...options,
|
|
183
|
+
event: "interactionHandlerError",
|
|
184
|
+
enabled: isSentryInitialized()
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
run(error, context) {
|
|
188
|
+
captureException(error, (scope) => scope.setLevel("error").setTag("event", this.name).setExtra("handler", context.handler.name));
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
container.stores.loadPiece({
|
|
192
|
+
name: "SharedInteractionHandlerError",
|
|
193
|
+
piece: SharedListener,
|
|
194
|
+
store: "listeners"
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
//#endregion
|
|
198
|
+
export { };
|
|
199
|
+
//# sourceMappingURL=_load-OFB2jZdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_load-OFB2jZdk.js","names":["SharedListener","SharedListener","SharedListener"],"sources":["../src/commands/info.ts","../src/listeners/SharedAutocompleteError.ts","../src/listeners/SharedCommandError.ts","../src/listeners/SharedError.ts","../src/listeners/SharedInteractionHandlerError.ts"],"sourcesContent":["import { EmbedBuilder, time, TimestampStyles } from '@discordjs/builders';\nimport { Command, container, RegisterCommand } from '@wolfstar/http-framework';\nimport { applyLocalizedBuilder, getSupportedUserLanguageName, getSupportedUserLanguageT, type TFunction } from '@wolfstar/plugin-i18next';\nimport {\n\tButtonStyle,\n\tComponentType,\n\tMessageFlags,\n\ttype APIActionRowComponent,\n\ttype APIComponentInMessageActionRow,\n\ttype APIEmbedField\n} from 'discord-api-types/v10';\nimport { cpus, uptime, type CpuInfo } from 'node:os';\nimport { getInvite, getRepository } from '../lib/information.js';\n\ntype TranslateFn = TFunction;\n\n@RegisterCommand((builder) => applyLocalizedBuilder(builder, 'commands/shared:info'))\nexport class SharedCommand extends Command {\n\tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n\t\tconst t = getSupportedUserLanguageT(interaction) as TranslateFn;\n\t\tconst lng = getSupportedUserLanguageName(interaction);\n\t\tconst embed = new EmbedBuilder()\n\t\t\t.setDescription(t('commands/shared:infoEmbedDescription'))\n\t\t\t.addFields(this.getUptimeStatistics(t), this.getServerUsageStatistics(t, lng));\n\t\tconst components = this.getComponents(t);\n\n\t\treturn interaction.reply({ embeds: [embed.toJSON()], components, flags: MessageFlags.Ephemeral });\n\t}\n\n\tprivate getUptimeStatistics(t: TranslateFn): APIEmbedField {\n\t\tconst now = Date.now();\n\t\tconst nowSeconds = Math.round(now / 1000);\n\n\t\treturn {\n\t\t\tname: t('commands/shared:infoFieldUptimeTitle'),\n\t\t\tvalue: t('commands/shared:infoFieldUptimeValue', {\n\t\t\t\thost: time(Math.round(nowSeconds - uptime()), TimestampStyles.RelativeTime),\n\t\t\t\tclient: time(Math.round(nowSeconds - process.uptime()), TimestampStyles.RelativeTime)\n\t\t\t})\n\t\t};\n\t}\n\n\tprivate getServerUsageStatistics(t: TranslateFn, lng: string): APIEmbedField {\n\t\tconst usage = process.memoryUsage();\n\n\t\treturn {\n\t\t\tname: t('commands/shared:infoFieldServerUsageTitle'),\n\t\t\tvalue: t('commands/shared:infoFieldServerUsageValue', {\n\t\t\t\tcpu: cpus().map(SharedCommand.formatCpuInfo.bind(null)).join(' | '),\n\t\t\t\theapUsed: (usage.heapUsed / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 }),\n\t\t\t\theapTotal: (usage.heapTotal / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 })\n\t\t\t})\n\t\t};\n\t}\n\n\tprivate getComponents(t: TranslateFn) {\n\t\tconst url = getInvite();\n\t\tconst support = this.getSupportComponent(t);\n\t\tconst github = this.getGitHubComponent(t);\n\t\tconst donate = this.getDonateComponent(t);\n\t\tconst data = url\n\t\t\t? [this.getActionRow(support, this.getInviteComponent(t, url)), this.getActionRow(github, donate)]\n\t\t\t: [this.getActionRow(support, github, donate)];\n\n\t\treturn data;\n\t}\n\n\tprivate getActionRow(...components: APIComponentInMessageActionRow[]): APIActionRowComponent<APIComponentInMessageActionRow> {\n\t\treturn { type: ComponentType.ActionRow, components };\n\t}\n\n\tprivate getSupportComponent(t: TranslateFn): APIComponentInMessageActionRow {\n\t\treturn {\n\t\t\ttype: ComponentType.Button,\n\t\t\tstyle: ButtonStyle.Link,\n\t\t\tlabel: t('commands/shared:infoButtonSupport'),\n\t\t\temoji: { name: '๐' },\n\t\t\turl: 'https://discord.gg/6gakFR2'\n\t\t};\n\t}\n\n\tprivate getInviteComponent(t: TranslateFn, url: string): APIComponentInMessageActionRow {\n\t\treturn {\n\t\t\ttype: ComponentType.Button,\n\t\t\tstyle: ButtonStyle.Link,\n\t\t\tlabel: t('commands/shared:infoButtonInvite'),\n\t\t\temoji: { name: '๐' },\n\t\t\turl\n\t\t};\n\t}\n\n\tprivate getGitHubComponent(t: TranslateFn): APIComponentInMessageActionRow {\n\t\treturn {\n\t\t\ttype: ComponentType.Button,\n\t\t\tstyle: ButtonStyle.Link,\n\t\t\tlabel: t('commands/shared:infoButtonGitHub'),\n\t\t\temoji: { id: '950888087188283422', name: 'github2' },\n\t\t\turl: getRepository()\n\t\t};\n\t}\n\n\tprivate getDonateComponent(t: TranslateFn): APIComponentInMessageActionRow {\n\t\treturn {\n\t\t\ttype: ComponentType.Button,\n\t\t\tstyle: ButtonStyle.Link,\n\t\t\tlabel: t('commands/shared:infoButtonDonate'),\n\t\t\temoji: { name: '๐งก' },\n\t\t\turl: 'https://donate.wolfstar.rocks'\n\t\t};\n\t}\n\n\tprivate static formatCpuInfo({ times }: CpuInfo) {\n\t\treturn `${Math.round(((times.user + times.nice + times.sys + times.irq) / times.idle) * 10000) / 100}%`;\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'info', piece: SharedCommand as any, store: 'commands' });\n","import { captureException } from '@sentry/node';\nimport { Listener, container, type ClientEventAutocompleteContext, type ClientEvents } from '@wolfstar/http-framework';\nimport { isSentryInitialized } from '../lib/sentry.js';\n\nexport class SharedListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext, options: Listener.Options) {\n\t\tsuper(context, { ...options, event: 'autocompleteError' satisfies keyof ClientEvents, enabled: isSentryInitialized() });\n\t}\n\n\tpublic run(error: unknown, context: ClientEventAutocompleteContext) {\n\t\tcaptureException(error, (scope) => scope.setLevel('error').setTag('event', this.name).setExtra('command', context.command.name));\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'SharedAutocompleteError', piece: SharedListener as any, store: 'listeners' });\n","import { captureException } from '@sentry/node';\nimport { Listener, container, type ClientEventCommandContext, type ClientEvents } from '@wolfstar/http-framework';\nimport { isSentryInitialized } from '../lib/sentry.js';\n\nexport class SharedListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext, options: Listener.Options) {\n\t\tsuper(context, { ...options, event: 'commandError' satisfies keyof ClientEvents, enabled: isSentryInitialized() });\n\t}\n\n\tpublic run(error: unknown, context: ClientEventCommandContext) {\n\t\tcaptureException(error, (scope) => scope.setLevel('error').setTag('event', this.name).setExtra('command', context.command.name));\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'SharedCommandError', piece: SharedListener as any, store: 'listeners' });\n","import { captureException } from '@sentry/node';\nimport { Listener, container, isUserError, type ClientEvents } from '@wolfstar/http-framework';\nimport { isSentryInitialized } from '../lib/sentry.js';\n\nexport class SharedListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext, options: Listener.Options) {\n\t\tsuper(context, { ...options, event: 'error' satisfies keyof ClientEvents, enabled: isSentryInitialized() });\n\t}\n\n\tpublic run(error: unknown) {\n\t\t// A `UserError` is an expected failure that is emitted as a `*Denied` event too, not a bug to report.\n\t\tif (isUserError(error)) return;\n\n\t\tcaptureException(error, (scope) => scope.setLevel('error').setTag('event', this.name));\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'SharedError', piece: SharedListener as any, store: 'listeners' });\n","import { captureException } from '@sentry/node';\nimport { Listener, container, type ClientEventInteractionHandlerContext, type ClientEvents } from '@wolfstar/http-framework';\nimport { isSentryInitialized } from '../lib/sentry.js';\n\nexport class SharedListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext, options: Listener.Options) {\n\t\tsuper(context, { ...options, event: 'interactionHandlerError' satisfies keyof ClientEvents, enabled: isSentryInitialized() });\n\t}\n\n\tpublic run(error: unknown, context: ClientEventInteractionHandlerContext) {\n\t\tcaptureException(error, (scope) => scope.setLevel('error').setTag('event', this.name).setExtra('handler', context.handler.name));\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'SharedInteractionHandlerError', piece: SharedListener as any, store: 'listeners' });\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiBO,IAAM,iCAAN,MAAM,sBAAsB,QAAQ;CAC1C,AAAgB,aAAa,aAA2C;EACvE,MAAM,IAAI,0BAA0B,WAAW;EAC/C,MAAM,MAAM,6BAA6B,WAAW;EACpD,MAAM,QAAQ,IAAI,aAAa,CAAC,CAC9B,eAAe,EAAE,sCAAsC,CAAC,CAAC,CACzD,UAAU,KAAK,oBAAoB,CAAC,GAAG,KAAK,yBAAyB,GAAG,GAAG,CAAC;EAC9E,MAAM,aAAa,KAAK,cAAc,CAAC;EAEvC,OAAO,YAAY,MAAM;GAAE,QAAQ,CAAC,MAAM,OAAO,CAAC;GAAG;GAAY,OAAO,aAAa;EAAU,CAAC;CACjG;CAEA,AAAQ,oBAAoB,GAA+B;E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/module.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Installs the shared commands, listeners and locales from `modules` in `stars.config`, instead of importing
|
|
4
|
+
* `@wolfstar/shared-http-pieces/register` by hand:
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* export default defineConfig({ modules: ['@wolfstar/shared-http-pieces'] });
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
declare const _default: import("@wolfstar/kit").StarsModule<import("@wolfstar/kit").ModuleOptions>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { _default as default };
|
|
14
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","names":[],"sources":["../src/module.ts"],"mappings":";;;;;;;;;;cAEA"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineModule } from "@wolfstar/kit";
|
|
2
|
+
|
|
3
|
+
//#region src/module.ts
|
|
4
|
+
/**
|
|
5
|
+
* Installs the shared commands, listeners and locales from `modules` in `stars.config`, instead of importing
|
|
6
|
+
* `@wolfstar/shared-http-pieces/register` by hand:
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* export default defineConfig({ modules: ['@wolfstar/shared-http-pieces'] });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
var module_default = defineModule({
|
|
14
|
+
meta: {
|
|
15
|
+
name: "@wolfstar/shared-http-pieces",
|
|
16
|
+
compatibility: { framework: ">=6.5.0" }
|
|
17
|
+
},
|
|
18
|
+
setup(_options, ctx) {
|
|
19
|
+
ctx.addLocales(new URL("../src/locales", import.meta.url));
|
|
20
|
+
ctx.addPlugin({ from: new URL("./pieces.js", import.meta.url) });
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { module_default as default };
|
|
26
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","names":[],"sources":["../src/module.ts"],"sourcesContent":["import { defineModule } from '@wolfstar/kit';\n\n/**\n * Installs the shared commands, listeners and locales from `modules` in `stars.config`, instead of importing\n * `@wolfstar/shared-http-pieces/register` by hand:\n *\n * @example\n * ```ts\n * export default defineConfig({ modules: ['@wolfstar/shared-http-pieces'] });\n * ```\n */\nexport default defineModule({\n\tmeta: { name: '@wolfstar/shared-http-pieces', compatibility: { framework: '>=6.5.0' } },\n\tsetup(_options, ctx) {\n\t\t// `src/locales` is published next to `dist`, as `localesPath` in `./register.ts` expects.\n\t\tctx.addLocales(new URL('../src/locales', import.meta.url));\n\t\tctx.addPlugin({ from: new URL('./pieces.js', import.meta.url) });\n\t}\n});\n"],"mappings":";;;;;;;;;;;;AAWA,qBAAe,aAAa;CAC3B,MAAM;EAAE,MAAM;EAAgC,eAAe,EAAE,WAAW,UAAU;CAAE;CACtF,MAAM,UAAU,KAAK;EAEpB,IAAI,WAAW,IAAI,IAAI,kBAAkB,YAAY,GAAG,CAAC;EACzD,IAAI,UAAU,EAAE,MAAM,IAAI,IAAI,eAAe,YAAY,GAAG,EAAE,CAAC;CAChE;AACD,CAAC"}
|
package/dist/pieces.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./_load-Grew5qvM.js";
|
|
2
|
+
//#region src/pieces.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The runtime half of {@link ./module.ts}. Importing this file registers the shared commands and listeners with the
|
|
5
|
+
* stores, the way `./register.ts` does, so the plugin itself has no hooks: it only gives the registration a name.
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { _default as default };
|
|
12
|
+
//# sourceMappingURL=pieces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pieces.d.ts","names":[],"sources":["../src/pieces.ts"],"mappings":""}
|
package/dist/pieces.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./_load-OFB2jZdk.js";
|
|
2
|
+
import { definePlugin } from "@wolfstar/http-framework";
|
|
3
|
+
|
|
4
|
+
//#region src/pieces.ts
|
|
5
|
+
await import("@wolfstar/plugin-i18next/register");
|
|
6
|
+
/**
|
|
7
|
+
* The runtime half of {@link ./module.ts}. Importing this file registers the shared commands and listeners with the
|
|
8
|
+
* stores, the way `./register.ts` does, so the plugin itself has no hooks: it only gives the registration a name.
|
|
9
|
+
*/
|
|
10
|
+
var pieces_default = definePlugin({ name: "@wolfstar/shared-http-pieces" });
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { pieces_default as default };
|
|
14
|
+
//# sourceMappingURL=pieces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pieces.js","names":[],"sources":["../src/pieces.ts"],"sourcesContent":["import { definePlugin } from '@wolfstar/http-framework';\nimport './commands/_load.js';\nimport './listeners/_load.js';\n\n// The plugin's own `register` entrypoint is imported here, in the bot, because the package that depends on it is\n// the one that knows it needs it. It is a dynamic import on purpose: the build treats external modules as free of\n// side effects (`moduleSideEffects: 'no-external'`) and would drop a static `import '...'` of it. Order does not\n// matter on this path: locales are added by `ctx.addLocales` in `./module.ts`, and the generated `stars:locales`\n// plugin runs first (`enforce: 'pre'`).\nawait import('@wolfstar/plugin-i18next/register');\n\n/**\n * The runtime half of {@link ./module.ts}. Importing this file registers the shared commands and listeners with the\n * stores, the way `./register.ts` does, so the plugin itself has no hooks: it only gives the registration a name.\n */\nexport default definePlugin({ name: '@wolfstar/shared-http-pieces' });\n"],"mappings":";;;;AASA,MAAM,OAAO;;;;;AAMb,qBAAe,aAAa,EAAE,MAAM,+BAA+B,CAAC"}
|
package/dist/register.d.ts
CHANGED
package/dist/register.js
CHANGED
|
@@ -1,203 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { captureException } from "@sentry/node";
|
|
1
|
+
import "./_load-OFB2jZdk.js";
|
|
3
2
|
import { join } from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { Client,
|
|
6
|
-
import { InternationalizationHandler
|
|
7
|
-
import { EmbedBuilder, TimestampStyles, time } from "@discordjs/builders";
|
|
8
|
-
import { ButtonStyle, ComponentType, MessageFlags } from "discord-api-types/v10";
|
|
9
|
-
import { cpus, uptime } from "node:os";
|
|
4
|
+
import { Client, container } from "@wolfstar/http-framework";
|
|
5
|
+
import { InternationalizationHandler } from "@wolfstar/plugin-i18next";
|
|
10
6
|
import { getRootData } from "@sapphire/pieces";
|
|
11
7
|
|
|
12
|
-
//#region \0@oxc-project+runtime@0.152.0/helpers/esm/decorate.js
|
|
13
|
-
function __decorate(decorators, target, key, desc) {
|
|
14
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/commands/info.ts
|
|
22
|
-
var _SharedCommand;
|
|
23
|
-
let SharedCommand = _SharedCommand = class SharedCommand extends Command {
|
|
24
|
-
chatInputRun(interaction) {
|
|
25
|
-
const t = getSupportedUserLanguageT(interaction);
|
|
26
|
-
const lng = getSupportedUserLanguageName(interaction);
|
|
27
|
-
const embed = new EmbedBuilder().setDescription(t("commands/shared:infoEmbedDescription")).addFields(this.getUptimeStatistics(t), this.getServerUsageStatistics(t, lng));
|
|
28
|
-
const components = this.getComponents(t);
|
|
29
|
-
return interaction.reply({
|
|
30
|
-
embeds: [embed.toJSON()],
|
|
31
|
-
components,
|
|
32
|
-
flags: MessageFlags.Ephemeral
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
getUptimeStatistics(t) {
|
|
36
|
-
const nowSeconds = Math.round(Date.now() / 1e3);
|
|
37
|
-
return {
|
|
38
|
-
name: t("commands/shared:infoFieldUptimeTitle"),
|
|
39
|
-
value: t("commands/shared:infoFieldUptimeValue", {
|
|
40
|
-
host: time(Math.round(nowSeconds - uptime()), TimestampStyles.RelativeTime),
|
|
41
|
-
client: time(Math.round(nowSeconds - process.uptime()), TimestampStyles.RelativeTime)
|
|
42
|
-
})
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
getServerUsageStatistics(t, lng) {
|
|
46
|
-
const usage = process.memoryUsage();
|
|
47
|
-
return {
|
|
48
|
-
name: t("commands/shared:infoFieldServerUsageTitle"),
|
|
49
|
-
value: t("commands/shared:infoFieldServerUsageValue", {
|
|
50
|
-
cpu: cpus().map(_SharedCommand.formatCpuInfo.bind(null)).join(" | "),
|
|
51
|
-
heapUsed: (usage.heapUsed / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 }),
|
|
52
|
-
heapTotal: (usage.heapTotal / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 })
|
|
53
|
-
})
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
getComponents(t) {
|
|
57
|
-
const url = getInvite();
|
|
58
|
-
const support = this.getSupportComponent(t);
|
|
59
|
-
const github = this.getGitHubComponent(t);
|
|
60
|
-
const donate = this.getDonateComponent(t);
|
|
61
|
-
return url ? [this.getActionRow(support, this.getInviteComponent(t, url)), this.getActionRow(github, donate)] : [this.getActionRow(support, github, donate)];
|
|
62
|
-
}
|
|
63
|
-
getActionRow(...components) {
|
|
64
|
-
return {
|
|
65
|
-
type: ComponentType.ActionRow,
|
|
66
|
-
components
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
getSupportComponent(t) {
|
|
70
|
-
return {
|
|
71
|
-
type: ComponentType.Button,
|
|
72
|
-
style: ButtonStyle.Link,
|
|
73
|
-
label: t("commands/shared:infoButtonSupport"),
|
|
74
|
-
emoji: { name: "๐" },
|
|
75
|
-
url: "https://discord.gg/6gakFR2"
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
getInviteComponent(t, url) {
|
|
79
|
-
return {
|
|
80
|
-
type: ComponentType.Button,
|
|
81
|
-
style: ButtonStyle.Link,
|
|
82
|
-
label: t("commands/shared:infoButtonInvite"),
|
|
83
|
-
emoji: { name: "๐" },
|
|
84
|
-
url
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
getGitHubComponent(t) {
|
|
88
|
-
return {
|
|
89
|
-
type: ComponentType.Button,
|
|
90
|
-
style: ButtonStyle.Link,
|
|
91
|
-
label: t("commands/shared:infoButtonGitHub"),
|
|
92
|
-
emoji: {
|
|
93
|
-
id: "950888087188283422",
|
|
94
|
-
name: "github2"
|
|
95
|
-
},
|
|
96
|
-
url: getRepository()
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
getDonateComponent(t) {
|
|
100
|
-
return {
|
|
101
|
-
type: ComponentType.Button,
|
|
102
|
-
style: ButtonStyle.Link,
|
|
103
|
-
label: t("commands/shared:infoButtonDonate"),
|
|
104
|
-
emoji: { name: "๐งก" },
|
|
105
|
-
url: "https://donate.wolfstar.rocks"
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
static formatCpuInfo({ times }) {
|
|
109
|
-
return `${Math.round((times.user + times.nice + times.sys + times.irq) / times.idle * 1e4) / 100}%`;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
SharedCommand = _SharedCommand = __decorate([RegisterCommand((builder) => applyLocalizedBuilder(builder, "commands/shared:info"))], SharedCommand);
|
|
113
|
-
container.stores.loadPiece({
|
|
114
|
-
name: "info",
|
|
115
|
-
piece: SharedCommand,
|
|
116
|
-
store: "commands"
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/listeners/SharedAutocompleteError.ts
|
|
121
|
-
var SharedListener$3 = class extends Listener {
|
|
122
|
-
constructor(context, options) {
|
|
123
|
-
super(context, {
|
|
124
|
-
...options,
|
|
125
|
-
event: "autocompleteError",
|
|
126
|
-
enabled: isSentryInitialized()
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
run(error, context) {
|
|
130
|
-
captureException(error, (scope) => scope.setLevel("error").setTag("event", this.name).setExtra("command", context.command.name));
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
container.stores.loadPiece({
|
|
134
|
-
name: "SharedAutocompleteError",
|
|
135
|
-
piece: SharedListener$3,
|
|
136
|
-
store: "listeners"
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/listeners/SharedCommandError.ts
|
|
141
|
-
var SharedListener$2 = class extends Listener {
|
|
142
|
-
constructor(context, options) {
|
|
143
|
-
super(context, {
|
|
144
|
-
...options,
|
|
145
|
-
event: "commandError",
|
|
146
|
-
enabled: isSentryInitialized()
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
run(error, context) {
|
|
150
|
-
captureException(error, (scope) => scope.setLevel("error").setTag("event", this.name).setExtra("command", context.command.name));
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
container.stores.loadPiece({
|
|
154
|
-
name: "SharedCommandError",
|
|
155
|
-
piece: SharedListener$2,
|
|
156
|
-
store: "listeners"
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
//#endregion
|
|
160
|
-
//#region src/listeners/SharedError.ts
|
|
161
|
-
var SharedListener$1 = class extends Listener {
|
|
162
|
-
constructor(context, options) {
|
|
163
|
-
super(context, {
|
|
164
|
-
...options,
|
|
165
|
-
event: "error",
|
|
166
|
-
enabled: isSentryInitialized()
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
run(error) {
|
|
170
|
-
if (isUserError(error)) return;
|
|
171
|
-
captureException(error, (scope) => scope.setLevel("error").setTag("event", this.name));
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
container.stores.loadPiece({
|
|
175
|
-
name: "SharedError",
|
|
176
|
-
piece: SharedListener$1,
|
|
177
|
-
store: "listeners"
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/listeners/SharedInteractionHandlerError.ts
|
|
182
|
-
var SharedListener = class extends Listener {
|
|
183
|
-
constructor(context, options) {
|
|
184
|
-
super(context, {
|
|
185
|
-
...options,
|
|
186
|
-
event: "interactionHandlerError",
|
|
187
|
-
enabled: isSentryInitialized()
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
run(error, context) {
|
|
191
|
-
captureException(error, (scope) => scope.setLevel("error").setTag("event", this.name).setExtra("handler", context.handler.name));
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
container.stores.loadPiece({
|
|
195
|
-
name: "SharedInteractionHandlerError",
|
|
196
|
-
piece: SharedListener,
|
|
197
|
-
store: "listeners"
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
//#endregion
|
|
201
8
|
//#region src/lib/register-i18n.ts
|
|
202
9
|
const sharedNamespace = "commands/shared";
|
|
203
10
|
function addSharedNamespace(options, discoveredNamespaces) {
|
package/dist/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","names":["SharedListener","SharedListener","SharedListener"],"sources":["../src/commands/info.ts","../src/listeners/SharedAutocompleteError.ts","../src/listeners/SharedCommandError.ts","../src/listeners/SharedError.ts","../src/listeners/SharedInteractionHandlerError.ts","../src/lib/register-i18n.ts","../src/register.ts"],"sourcesContent":["import { EmbedBuilder, time, TimestampStyles } from '@discordjs/builders';\nimport { Command, container, RegisterCommand } from '@wolfstar/http-framework';\nimport { applyLocalizedBuilder, getSupportedUserLanguageName, getSupportedUserLanguageT, type TFunction } from '@wolfstar/plugin-i18next';\nimport {\n\tButtonStyle,\n\tComponentType,\n\tMessageFlags,\n\ttype APIActionRowComponent,\n\ttype APIComponentInMessageActionRow,\n\ttype APIEmbedField\n} from 'discord-api-types/v10';\nimport { cpus, uptime, type CpuInfo } from 'node:os';\nimport { getInvite, getRepository } from '../lib/information.js';\n\ntype TranslateFn = TFunction;\n\n@RegisterCommand((builder) => applyLocalizedBuilder(builder, 'commands/shared:info'))\nexport class SharedCommand extends Command {\n\tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n\t\tconst t = getSupportedUserLanguageT(interaction) as TranslateFn;\n\t\tconst lng = getSupportedUserLanguageName(interaction);\n\t\tconst embed = new EmbedBuilder()\n\t\t\t.setDescription(t('commands/shared:infoEmbedDescription'))\n\t\t\t.addFields(this.getUptimeStatistics(t), this.getServerUsageStatistics(t, lng));\n\t\tconst components = this.getComponents(t);\n\n\t\treturn interaction.reply({ embeds: [embed.toJSON()], components, flags: MessageFlags.Ephemeral });\n\t}\n\n\tprivate getUptimeStatistics(t: TranslateFn): APIEmbedField {\n\t\tconst now = Date.now();\n\t\tconst nowSeconds = Math.round(now / 1000);\n\n\t\treturn {\n\t\t\tname: t('commands/shared:infoFieldUptimeTitle'),\n\t\t\tvalue: t('commands/shared:infoFieldUptimeValue', {\n\t\t\t\thost: time(Math.round(nowSeconds - uptime()), TimestampStyles.RelativeTime),\n\t\t\t\tclient: time(Math.round(nowSeconds - process.uptime()), TimestampStyles.RelativeTime)\n\t\t\t})\n\t\t};\n\t}\n\n\tprivate getServerUsageStatistics(t: TranslateFn, lng: string): APIEmbedField {\n\t\tconst usage = process.memoryUsage();\n\n\t\treturn {\n\t\t\tname: t('commands/shared:infoFieldServerUsageTitle'),\n\t\t\tvalue: t('commands/shared:infoFieldServerUsageValue', {\n\t\t\t\tcpu: cpus().map(SharedCommand.formatCpuInfo.bind(null)).join(' | '),\n\t\t\t\theapUsed: (usage.heapUsed / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 }),\n\t\t\t\theapTotal: (usage.heapTotal / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 })\n\t\t\t})\n\t\t};\n\t}\n\n\tprivate getComponents(t: TranslateFn) {\n\t\tconst url = getInvite();\n\t\tconst support = this.getSupportComponent(t);\n\t\tconst github = this.getGitHubComponent(t);\n\t\tconst donate = this.getDonateComponent(t);\n\t\tconst data = url\n\t\t\t? [this.getActionRow(support, this.getInviteComponent(t, url)), this.getActionRow(github, donate)]\n\t\t\t: [this.getActionRow(support, github, donate)];\n\n\t\treturn data;\n\t}\n\n\tprivate getActionRow(...components: APIComponentInMessageActionRow[]): APIActionRowComponent<APIComponentInMessageActionRow> {\n\t\treturn { type: ComponentType.ActionRow, components };\n\t}\n\n\tprivate getSupportComponent(t: TranslateFn): APIComponentInMessageActionRow {\n\t\treturn {\n\t\t\ttype: ComponentType.Button,\n\t\t\tstyle: ButtonStyle.Link,\n\t\t\tlabel: t('commands/shared:infoButtonSupport'),\n\t\t\temoji: { name: '๐' },\n\t\t\turl: 'https://discord.gg/6gakFR2'\n\t\t};\n\t}\n\n\tprivate getInviteComponent(t: TranslateFn, url: string): APIComponentInMessageActionRow {\n\t\treturn {\n\t\t\ttype: ComponentType.Button,\n\t\t\tstyle: ButtonStyle.Link,\n\t\t\tlabel: t('commands/shared:infoButtonInvite'),\n\t\t\temoji: { name: '๐' },\n\t\t\turl\n\t\t};\n\t}\n\n\tprivate getGitHubComponent(t: TranslateFn): APIComponentInMessageActionRow {\n\t\treturn {\n\t\t\ttype: ComponentType.Button,\n\t\t\tstyle: ButtonStyle.Link,\n\t\t\tlabel: t('commands/shared:infoButtonGitHub'),\n\t\t\temoji: { id: '950888087188283422', name: 'github2' },\n\t\t\turl: getRepository()\n\t\t};\n\t}\n\n\tprivate getDonateComponent(t: TranslateFn): APIComponentInMessageActionRow {\n\t\treturn {\n\t\t\ttype: ComponentType.Button,\n\t\t\tstyle: ButtonStyle.Link,\n\t\t\tlabel: t('commands/shared:infoButtonDonate'),\n\t\t\temoji: { name: '๐งก' },\n\t\t\turl: 'https://donate.wolfstar.rocks'\n\t\t};\n\t}\n\n\tprivate static formatCpuInfo({ times }: CpuInfo) {\n\t\treturn `${Math.round(((times.user + times.nice + times.sys + times.irq) / times.idle) * 10000) / 100}%`;\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'info', piece: SharedCommand as any, store: 'commands' });\n","import { captureException } from '@sentry/node';\nimport { Listener, container, type ClientEventAutocompleteContext, type ClientEvents } from '@wolfstar/http-framework';\nimport { isSentryInitialized } from '../lib/sentry.js';\n\nexport class SharedListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext, options: Listener.Options) {\n\t\tsuper(context, { ...options, event: 'autocompleteError' satisfies keyof ClientEvents, enabled: isSentryInitialized() });\n\t}\n\n\tpublic run(error: unknown, context: ClientEventAutocompleteContext) {\n\t\tcaptureException(error, (scope) => scope.setLevel('error').setTag('event', this.name).setExtra('command', context.command.name));\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'SharedAutocompleteError', piece: SharedListener as any, store: 'listeners' });\n","import { captureException } from '@sentry/node';\nimport { Listener, container, type ClientEventCommandContext, type ClientEvents } from '@wolfstar/http-framework';\nimport { isSentryInitialized } from '../lib/sentry.js';\n\nexport class SharedListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext, options: Listener.Options) {\n\t\tsuper(context, { ...options, event: 'commandError' satisfies keyof ClientEvents, enabled: isSentryInitialized() });\n\t}\n\n\tpublic run(error: unknown, context: ClientEventCommandContext) {\n\t\tcaptureException(error, (scope) => scope.setLevel('error').setTag('event', this.name).setExtra('command', context.command.name));\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'SharedCommandError', piece: SharedListener as any, store: 'listeners' });\n","import { captureException } from '@sentry/node';\nimport { Listener, container, isUserError, type ClientEvents } from '@wolfstar/http-framework';\nimport { isSentryInitialized } from '../lib/sentry.js';\n\nexport class SharedListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext, options: Listener.Options) {\n\t\tsuper(context, { ...options, event: 'error' satisfies keyof ClientEvents, enabled: isSentryInitialized() });\n\t}\n\n\tpublic run(error: unknown) {\n\t\t// A `UserError` is an expected failure that is emitted as a `*Denied` event too, not a bug to report.\n\t\tif (isUserError(error)) return;\n\n\t\tcaptureException(error, (scope) => scope.setLevel('error').setTag('event', this.name));\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'SharedError', piece: SharedListener as any, store: 'listeners' });\n","import { captureException } from '@sentry/node';\nimport { Listener, container, type ClientEventInteractionHandlerContext, type ClientEvents } from '@wolfstar/http-framework';\nimport { isSentryInitialized } from '../lib/sentry.js';\n\nexport class SharedListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext, options: Listener.Options) {\n\t\tsuper(context, { ...options, event: 'interactionHandlerError' satisfies keyof ClientEvents, enabled: isSentryInitialized() });\n\t}\n\n\tpublic run(error: unknown, context: ClientEventInteractionHandlerContext) {\n\t\tcaptureException(error, (scope) => scope.setLevel('error').setTag('event', this.name).setExtra('handler', context.handler.name));\n\t}\n}\n\nvoid container.stores.loadPiece({ name: 'SharedInteractionHandlerError', piece: SharedListener as any, store: 'listeners' });\n","import { getRootData } from '@sapphire/pieces';\nimport type { InternationalizationOptions } from '@wolfstar/plugin-i18next';\nimport type { InitOptions } from 'i18next';\nimport { join } from 'node:path';\n\nexport const sharedNamespace = 'commands/shared';\n\nfunction addSharedNamespace(options: InitOptions | undefined, discoveredNamespaces: string[]): InitOptions {\n\tconst configuredNamespaces = options?.ns === undefined ? [] : [options.ns].flat();\n\n\treturn {\n\t\t...options,\n\t\tns: [...new Set([...discoveredNamespaces, ...configuredNamespaces, sharedNamespace])]\n\t};\n}\n\n/**\n * Adds this package's locales without losing locales and namespaces discovered by the consumer.\n *\n * `@wolfstar/plugin-i18next@2` lets `backend.paths` replace its generated consumer path and only\n * discovers namespaces below `defaultLanguageDirectory`. Supplying both values explicitly keeps\n * the consumer resources and makes this package's namespace available to i18next.\n */\nexport function registerSharedLocales(i18n: InternationalizationOptions, localesPath: string): InternationalizationOptions {\n\tconst languagesDirectory = i18n.defaultLanguageDirectory ?? join(getRootData().root, 'languages');\n\tconst consumerLocalesPath = join(languagesDirectory, '{{lng}}', '{{ns}}.json');\n\tconst configuredI18next = i18n.i18next;\n\n\treturn {\n\t\t...i18n,\n\t\tbackend: {\n\t\t\t...i18n.backend,\n\t\t\tpaths: [...new Set([consumerLocalesPath, ...(i18n.backend?.paths ?? []), localesPath])]\n\t\t},\n\t\ti18next(namespaces, languages) {\n\t\t\tconst options = typeof configuredI18next === 'function' ? configuredI18next(namespaces, languages) : configuredI18next;\n\t\t\treturn addSharedNamespace(options, namespaces);\n\t\t}\n\t};\n}\n","import { Client, container } from '@wolfstar/http-framework';\nimport { InternationalizationHandler } from '@wolfstar/plugin-i18next';\nimport { join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport './commands/_load.js';\nimport './listeners/_load.js';\nimport { registerSharedLocales } from './lib/register-i18n.js';\n\n/**\n * Path pattern for this package's bundled locales, in the format\n * `@wolfstar/plugin-i18next` expects for `i18n.backend.paths`.\n */\nexport const localesPath = join(fileURLToPath(new URL('../src/locales', import.meta.url)), '{{lng}}', '{{ns}}.json');\n\n/**\n * `@wolfstar/plugin-i18next` reads `Client`'s `i18n` option exactly once, in its own\n * `preGenericsInitialization` hook, and has no API to register extra locale directories\n * afterwards. Hooks run in registration order, so registering this one *before* importing\n * the plugin's `register` entrypoint below guarantees it runs first and can splice this\n * package's locales into `options.i18n.backend.paths` before the plugin builds its\n * `InternationalizationHandler` โ consumers that only import this module keep working\n * without having to list `localesPath` in their own `Client` config.\n *\n * That ordering only holds when this module is evaluated first. When the plugin's `register`\n * entrypoint is imported earlier (the Stars CLI prepends it to the entry of every project that\n * depends on the plugin), its hook runs first and has already built the handler from the\n * original options. The handler is then rebuilt from the merged ones: it only reads its options\n * in the constructor and is initialized later, in the plugin's `preLoad` hook, which reads\n * `container.i18n` at call time.\n */\nClient.plugins.registerPreGenericsInitializationHook((options) => {\n\tconst { i18n } = options;\n\tif (!i18n) return;\n\toptions.i18n = registerSharedLocales(i18n, localesPath);\n\tif (container.i18n) container.i18n = new InternationalizationHandler(options.i18n);\n}, '@wolfstar/shared-http-pieces');\n\n// A dynamic import, not a static one: static imports are hoisted above the hook\n// registration above, which would let the plugin's own hook register โ and run โ first.\nawait import('@wolfstar/plugin-i18next/register');\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBO,IAAM,iCAAN,MAAM,sBAAsB,QAAQ;CAC1C,AAAgB,aAAa,aAA2C;EACvE,MAAM,IAAI,0BAA0B,WAAW;EAC/C,MAAM,MAAM,6BAA6B,WAAW;EACpD,MAAM,QAAQ,IAAI,aAAa,CAAC,CAC9B,eAAe,EAAE,sCAAsC,CAAC,CAAC,CACzD,UAAU,KAAK,oBAAoB,CAAC,GAAG,KAAK,yBAAyB,GAAG,GAAG,CAAC;EAC9E,MAAM,aAAa,KAAK,cAAc,CAAC;EAEvC,OAAO,YAAY,MAAM;GAAE,QAAQ,CAAC,MAAM,OAAO,CAAC;GAAG;GAAY,OAAO,aAAa;EAAU,CAAC;CACjG;CAEA,AAAQ,oBAAoB,GAA+B;EAE1D,MAAM,aAAa,KAAK,MADZ,KAAK,IACe,IAAI,GAAI;EAExC,OAAO;GACN,MAAM,EAAE,sCAAsC;GAC9C,OAAO,EAAE,wCAAwC;IAChD,MAAM,KAAK,KAAK,MAAM,aAAa,OAAO,CAAC,GAAG,gBAAgB,YAAY;IAC1E,QAAQ,KAAK,KAAK,MAAM,aAAa,QAAQ,OAAO,CAAC,GAAG,gBAAgB,YAAY;GACrF,CAAC;EACF;CACD;CAEA,AAAQ,yBAAyB,GAAgB,KAA4B;EAC5E,MAAM,QAAQ,QAAQ,YAAY;EAElC,OAAO;GACN,MAAM,EAAE,2CAA2C;GACnD,OAAO,EAAE,6CAA6C;IACrD,KAAK,KAAK,CAAC,CAAC,mBAAkB,cAAc,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK;IAClE,WAAW,MAAM,WAAW,Q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I;GAAW,CAAC,CAAC;EACvF;EACA,QAAQ,YAAY,WAAW;GAE9B,OAAO,mBADS,OAAO,sBAAsB,aAAa,kBAAkB,YAAY,SAAS,IAAI,mBAClE,UAAU;EAC9C;CACD;AACD;;;;;;;;AC3BA,MAAa,cAAc,KAAK,cAAc,IAAI,IAAI,kBAAkB,YAAY,GAAG,CAAC,GAAG,WAAW,aAAa;;;;;;;;;;;;;;;;;AAkBnH,OAAO,QAAQ,uCAAuC,YAAY;CACjE,MAAM,EAAE,SAAS;CACjB,IAAI,CAAC,MAAM;CACX,QAAQ,OAAO,sBAAsB,MAAM,WAAW;CACtD,IAAI,UAAU,MAAM,UAAU,OAAO,IAAI,4BAA4B,QAAQ,IAAI;AAClF,GAAG,8BAA8B;AAIjC,MAAM,OAAO"}
|
|
1
|
+
{"version":3,"file":"register.js","names":[],"sources":["../src/lib/register-i18n.ts","../src/register.ts"],"sourcesContent":["import { getRootData } from '@sapphire/pieces';\nimport type { InternationalizationOptions } from '@wolfstar/plugin-i18next';\nimport type { InitOptions } from 'i18next';\nimport { join } from 'node:path';\n\nexport const sharedNamespace = 'commands/shared';\n\nfunction addSharedNamespace(options: InitOptions | undefined, discoveredNamespaces: string[]): InitOptions {\n\tconst configuredNamespaces = options?.ns === undefined ? [] : [options.ns].flat();\n\n\treturn {\n\t\t...options,\n\t\tns: [...new Set([...discoveredNamespaces, ...configuredNamespaces, sharedNamespace])]\n\t};\n}\n\n/**\n * Adds this package's locales without losing locales and namespaces discovered by the consumer.\n *\n * `@wolfstar/plugin-i18next@2` lets `backend.paths` replace its generated consumer path and only\n * discovers namespaces below `defaultLanguageDirectory`. Supplying both values explicitly keeps\n * the consumer resources and makes this package's namespace available to i18next.\n */\nexport function registerSharedLocales(i18n: InternationalizationOptions, localesPath: string): InternationalizationOptions {\n\tconst languagesDirectory = i18n.defaultLanguageDirectory ?? join(getRootData().root, 'languages');\n\tconst consumerLocalesPath = join(languagesDirectory, '{{lng}}', '{{ns}}.json');\n\tconst configuredI18next = i18n.i18next;\n\n\treturn {\n\t\t...i18n,\n\t\tbackend: {\n\t\t\t...i18n.backend,\n\t\t\tpaths: [...new Set([consumerLocalesPath, ...(i18n.backend?.paths ?? []), localesPath])]\n\t\t},\n\t\ti18next(namespaces, languages) {\n\t\t\tconst options = typeof configuredI18next === 'function' ? configuredI18next(namespaces, languages) : configuredI18next;\n\t\t\treturn addSharedNamespace(options, namespaces);\n\t\t}\n\t};\n}\n","import { Client, container } from '@wolfstar/http-framework';\nimport { InternationalizationHandler } from '@wolfstar/plugin-i18next';\nimport { join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport './commands/_load.js';\nimport './listeners/_load.js';\nimport { registerSharedLocales } from './lib/register-i18n.js';\n\n/**\n * Path pattern for this package's bundled locales, in the format\n * `@wolfstar/plugin-i18next` expects for `i18n.backend.paths`.\n */\nexport const localesPath = join(fileURLToPath(new URL('../src/locales', import.meta.url)), '{{lng}}', '{{ns}}.json');\n\n/**\n * `@wolfstar/plugin-i18next` reads `Client`'s `i18n` option exactly once, in its own\n * `preGenericsInitialization` hook, and has no API to register extra locale directories\n * afterwards. Hooks run in registration order, so registering this one *before* importing\n * the plugin's `register` entrypoint below guarantees it runs first and can splice this\n * package's locales into `options.i18n.backend.paths` before the plugin builds its\n * `InternationalizationHandler` โ consumers that only import this module keep working\n * without having to list `localesPath` in their own `Client` config.\n *\n * That ordering only holds when this module is evaluated first. When the plugin's `register`\n * entrypoint is imported earlier (the Stars CLI prepends it to the entry of every project that\n * depends on the plugin), its hook runs first and has already built the handler from the\n * original options. The handler is then rebuilt from the merged ones: it only reads its options\n * in the constructor and is initialized later, in the plugin's `preLoad` hook, which reads\n * `container.i18n` at call time.\n */\nClient.plugins.registerPreGenericsInitializationHook((options) => {\n\tconst { i18n } = options;\n\tif (!i18n) return;\n\toptions.i18n = registerSharedLocales(i18n, localesPath);\n\tif (container.i18n) container.i18n = new InternationalizationHandler(options.i18n);\n}, '@wolfstar/shared-http-pieces');\n\n// A dynamic import, not a static one: static imports are hoisted above the hook\n// registration above, which would let the plugin's own hook register โ and run โ first.\nawait import('@wolfstar/plugin-i18next/register');\n"],"mappings":";;;;;;;;AAKA,MAAa,kBAAkB;AAE/B,SAAS,mBAAmB,SAAkC,sBAA6C;CAC1G,MAAM,uBAAuB,SAAS,OAAO,SAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK;CAEhF,OAAO;EACN,GAAG;EACH,IAAI,CAAC,mBAAG,IAAI,IAAI;GAAC,GAAG;GAAsB,GAAG;GAAsB;EAAe,CAAC,CAAC;CACrF;AACD;;;;;;;;AASA,SAAgB,sBAAsB,MAAmC,aAAkD;CAC1H,MAAM,qBAAqB,KAAK,4BAA4B,KAAK,YAAY,CAAC,CAAC,MAAM,WAAW;CAChG,MAAM,sBAAsB,KAAK,oBAAoB,WAAW,aAAa;CAC7E,MAAM,oBAAoB,KAAK;CAE/B,OAAO;EACN,GAAG;EACH,SAAS;GACR,GAAG,KAAK;GACR,OAAO,CAAC,mBAAG,IAAI,IAAI;IAAC;IAAqB,GAAI,KAAK,SAAS,SAAS,CAAC;IAAI;GAAW,CAAC,CAAC;EACvF;EACA,QAAQ,YAAY,WAAW;GAE9B,OAAO,mBADS,OAAO,sBAAsB,aAAa,kBAAkB,YAAY,SAAS,IAAI,mBAClE,UAAU;EAC9C;CACD;AACD;;;;;;;;AC3BA,MAAa,cAAc,KAAK,cAAc,IAAI,IAAI,kBAAkB,YAAY,GAAG,CAAC,GAAG,WAAW,aAAa;;;;;;;;;;;;;;;;;AAkBnH,OAAO,QAAQ,uCAAuC,YAAY;CACjE,MAAM,EAAE,SAAS;CACjB,IAAI,CAAC,MAAM;CACX,QAAQ,OAAO,sBAAsB,MAAM,WAAW;CACtD,IAAI,UAAU,MAAM,UAAU,OAAO,IAAI,4BAA4B,QAAQ,IAAI;AAClF,GAAG,8BAA8B;AAIjC,MAAM,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wolfstar/shared-http-pieces",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "The common pieces for Star Network's HTTP-only bots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
],
|
|
28
28
|
"type": "module",
|
|
29
29
|
"sideEffects": [
|
|
30
|
-
"./dist/register.js"
|
|
30
|
+
"./dist/register.js",
|
|
31
|
+
"./dist/pieces.js"
|
|
31
32
|
],
|
|
32
33
|
"main": "dist/index.js",
|
|
33
34
|
"module": "dist/index.js",
|
|
@@ -40,6 +41,14 @@
|
|
|
40
41
|
"./register": {
|
|
41
42
|
"types": "./dist/register.d.ts",
|
|
42
43
|
"import": "./dist/register.js"
|
|
44
|
+
},
|
|
45
|
+
"./module": {
|
|
46
|
+
"types": "./dist/module.d.ts",
|
|
47
|
+
"import": "./dist/module.js"
|
|
48
|
+
},
|
|
49
|
+
"./pieces": {
|
|
50
|
+
"types": "./dist/pieces.d.ts",
|
|
51
|
+
"import": "./dist/pieces.js"
|
|
43
52
|
}
|
|
44
53
|
},
|
|
45
54
|
"publishConfig": {
|
|
@@ -52,7 +61,7 @@
|
|
|
52
61
|
"@sapphire/pieces": "^4.4.1",
|
|
53
62
|
"@sentry/node": "^11.4.0",
|
|
54
63
|
"@wolfstar/env-utilities": "^2.3.1",
|
|
55
|
-
"@wolfstar/http-framework": "^6.
|
|
64
|
+
"@wolfstar/http-framework": "^6.5.1",
|
|
56
65
|
"@wolfstar/plugin-i18next": "2.1.1",
|
|
57
66
|
"discord-api-types": "^0.38.8",
|
|
58
67
|
"i18next": "^26.4.2",
|
|
@@ -61,10 +70,19 @@
|
|
|
61
70
|
"devDependencies": {
|
|
62
71
|
"@vitest/coverage-v8": "^5.0.3",
|
|
63
72
|
"@wolfstar/i18next-type-generator": "^3.1.6",
|
|
73
|
+
"@wolfstar/kit": "^0.3.1",
|
|
64
74
|
"golar": "^0.1.10",
|
|
65
75
|
"typescript": "~7.0.2",
|
|
66
76
|
"vitest": "^5.0.3"
|
|
67
77
|
},
|
|
78
|
+
"peerDependencies": {
|
|
79
|
+
"@wolfstar/kit": ">=0.3.0"
|
|
80
|
+
},
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"@wolfstar/kit": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
68
86
|
"engines": {
|
|
69
87
|
"node": ">=20"
|
|
70
88
|
},
|