commandkit 0.1.11-dev.20250309035914 → 0.1.11-dev.20250327153237
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/dist/index.d.ts +160 -159
- package/dist/index.js +1086 -1273
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
package/dist/index.js
CHANGED
|
@@ -1372,9 +1372,9 @@ var init_CommandKitPluginRuntime = __esm({
|
|
|
1372
1372
|
init_Logger();
|
|
1373
1373
|
init_runtime_events();
|
|
1374
1374
|
_CommandKitPluginRuntime = class _CommandKitPluginRuntime extends EventTarget {
|
|
1375
|
-
constructor(
|
|
1375
|
+
constructor(commandkit2) {
|
|
1376
1376
|
super();
|
|
1377
|
-
this.commandkit =
|
|
1377
|
+
this.commandkit = commandkit2;
|
|
1378
1378
|
}
|
|
1379
1379
|
plugins = new import_discord7.Collection();
|
|
1380
1380
|
onClientLogin = /* @__PURE__ */ __name(() => {
|
|
@@ -1493,12 +1493,12 @@ var init_CompilerPluginRuntime = __esm({
|
|
|
1493
1493
|
return !this.plugins.length;
|
|
1494
1494
|
}
|
|
1495
1495
|
async onLoad(args) {
|
|
1496
|
-
var _a;
|
|
1496
|
+
var _a, _b;
|
|
1497
1497
|
const source = await (0, import_promises.readFile)(args.path, "utf8");
|
|
1498
|
-
let contents = source, loader = args.path.split(".").pop();
|
|
1498
|
+
let contents = source, loader = (_a = args.path) == null ? void 0 : _a.split(".").pop();
|
|
1499
1499
|
for (const plugin of this.plugins) {
|
|
1500
1500
|
try {
|
|
1501
|
-
const res = await ((
|
|
1501
|
+
const res = await ((_b = plugin.transform) == null ? void 0 : _b.call(plugin, {
|
|
1502
1502
|
contents,
|
|
1503
1503
|
path: args.path,
|
|
1504
1504
|
loader,
|
|
@@ -1695,6 +1695,7 @@ var init_UseCacheTransformer = __esm({
|
|
|
1695
1695
|
).join("");
|
|
1696
1696
|
}, "generateRandomString");
|
|
1697
1697
|
cacheDirectivePlugin = /* @__PURE__ */ __name(async (source, args) => {
|
|
1698
|
+
var _a;
|
|
1698
1699
|
const ast = parser.parse(source, {
|
|
1699
1700
|
sourceType: "module",
|
|
1700
1701
|
plugins: ["typescript", "jsx"]
|
|
@@ -1707,22 +1708,22 @@ var init_UseCacheTransformer = __esm({
|
|
|
1707
1708
|
};
|
|
1708
1709
|
traverse(ast, {
|
|
1709
1710
|
Program: {
|
|
1710
|
-
enter(
|
|
1711
|
-
const binding =
|
|
1711
|
+
enter(path2) {
|
|
1712
|
+
const binding = path2.scope.getBinding(CACHE_IDENTIFIER);
|
|
1712
1713
|
if (binding) {
|
|
1713
1714
|
state.cacheIdentifierName = `${CACHE_IDENTIFIER}_${generateRandomString()}`;
|
|
1714
1715
|
}
|
|
1715
1716
|
}
|
|
1716
1717
|
},
|
|
1717
|
-
ImportDeclaration(
|
|
1718
|
-
if (
|
|
1718
|
+
ImportDeclaration(path2) {
|
|
1719
|
+
if (path2.node.source.value === IMPORT_PATH && path2.node.specifiers.some(
|
|
1719
1720
|
(spec) => t.isImportSpecifier(spec) && // @ts-ignore
|
|
1720
1721
|
spec.imported.name === CACHE_IDENTIFIER
|
|
1721
1722
|
)) {
|
|
1722
1723
|
state.hasExistingImport = true;
|
|
1723
1724
|
if (state.cacheIdentifierName !== CACHE_IDENTIFIER) {
|
|
1724
1725
|
state.modifications.push(() => {
|
|
1725
|
-
|
|
1726
|
+
path2.node.specifiers.forEach((spec) => {
|
|
1726
1727
|
if (t.isImportSpecifier(spec) && // @ts-ignore
|
|
1727
1728
|
spec.imported.name === CACHE_IDENTIFIER) {
|
|
1728
1729
|
spec.local.name = state.cacheIdentifierName;
|
|
@@ -1732,14 +1733,14 @@ var init_UseCacheTransformer = __esm({
|
|
|
1732
1733
|
}
|
|
1733
1734
|
}
|
|
1734
1735
|
},
|
|
1735
|
-
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod"(
|
|
1736
|
-
var
|
|
1737
|
-
const body = t.isBlockStatement(
|
|
1738
|
-
const hasUseCache = (
|
|
1736
|
+
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod"(path2) {
|
|
1737
|
+
var _a2, _b, _c;
|
|
1738
|
+
const body = t.isBlockStatement(path2.node.body) ? path2.node.body : null;
|
|
1739
|
+
const hasUseCache = (_a2 = body == null ? void 0 : body.directives) == null ? void 0 : _a2.some(
|
|
1739
1740
|
(d) => d.value.value === DIRECTIVE
|
|
1740
1741
|
);
|
|
1741
|
-
if (!hasUseCache && !t.isBlockStatement(
|
|
1742
|
-
const parentFunction =
|
|
1742
|
+
if (!hasUseCache && !t.isBlockStatement(path2.node.body)) {
|
|
1743
|
+
const parentFunction = path2.findParent(
|
|
1743
1744
|
(p) => (p.isFunction() || p.isProgram()) && "directives" in p.node
|
|
1744
1745
|
);
|
|
1745
1746
|
if (!((_b = parentFunction == null ? void 0 : parentFunction.node.directives) == null ? void 0 : _b.some(
|
|
@@ -1748,35 +1749,35 @@ var init_UseCacheTransformer = __esm({
|
|
|
1748
1749
|
return;
|
|
1749
1750
|
}
|
|
1750
1751
|
}
|
|
1751
|
-
if (hasUseCache || !t.isBlockStatement(
|
|
1752
|
-
if (!
|
|
1752
|
+
if (hasUseCache || !t.isBlockStatement(path2.node.body)) {
|
|
1753
|
+
if (!path2.node.async) {
|
|
1753
1754
|
throw new Error(
|
|
1754
1755
|
`"${DIRECTIVE}" directive may only be used in async functions at ${args.path}
|
|
1755
1756
|
|
|
1756
|
-
${
|
|
1757
|
+
${path2.toString()}
|
|
1757
1758
|
^^^^${"-".repeat(6)} This function must be async`
|
|
1758
1759
|
);
|
|
1759
1760
|
}
|
|
1760
1761
|
state.needsImport = true;
|
|
1761
|
-
const isDeclaration = t.isFunctionDeclaration(
|
|
1762
|
-
const name = isDeclaration ? (_c =
|
|
1763
|
-
const newBody = t.isBlockStatement(
|
|
1764
|
-
|
|
1765
|
-
|
|
1762
|
+
const isDeclaration = t.isFunctionDeclaration(path2.node);
|
|
1763
|
+
const name = isDeclaration ? (_c = path2.node.id) == null ? void 0 : _c.name : void 0;
|
|
1764
|
+
const newBody = t.isBlockStatement(path2.node.body) ? t.blockStatement(
|
|
1765
|
+
path2.node.body.body,
|
|
1766
|
+
path2.node.body.directives.filter(
|
|
1766
1767
|
(d) => d.value.value !== DIRECTIVE
|
|
1767
1768
|
)
|
|
1768
|
-
) :
|
|
1769
|
+
) : path2.node.body;
|
|
1769
1770
|
const wrapped = t.callExpression(
|
|
1770
1771
|
t.identifier(state.cacheIdentifierName),
|
|
1771
|
-
[t.arrowFunctionExpression(
|
|
1772
|
+
[t.arrowFunctionExpression(path2.node.params, newBody, true)]
|
|
1772
1773
|
);
|
|
1773
1774
|
state.modifications.push(() => {
|
|
1774
|
-
if (t.isObjectMethod(
|
|
1775
|
-
|
|
1776
|
-
t.objectProperty(t.identifier(
|
|
1775
|
+
if (t.isObjectMethod(path2.node)) {
|
|
1776
|
+
path2.replaceWith(
|
|
1777
|
+
t.objectProperty(t.identifier(path2.node.key.name), wrapped)
|
|
1777
1778
|
);
|
|
1778
1779
|
} else if (name) {
|
|
1779
|
-
|
|
1780
|
+
path2.replaceWith(
|
|
1780
1781
|
t.variableDeclaration(
|
|
1781
1782
|
"const",
|
|
1782
1783
|
[
|
|
@@ -1784,10 +1785,10 @@ ${path3.toString()}
|
|
|
1784
1785
|
]
|
|
1785
1786
|
)
|
|
1786
1787
|
);
|
|
1787
|
-
} else if (!t.isVariableDeclarator(
|
|
1788
|
-
|
|
1788
|
+
} else if (!t.isVariableDeclarator(path2.parent)) {
|
|
1789
|
+
path2.replaceWith(wrapped);
|
|
1789
1790
|
} else {
|
|
1790
|
-
|
|
1791
|
+
path2.parent.init = wrapped;
|
|
1791
1792
|
}
|
|
1792
1793
|
});
|
|
1793
1794
|
}
|
|
@@ -1812,7 +1813,7 @@ ${path3.toString()}
|
|
|
1812
1813
|
const { code } = generate(ast);
|
|
1813
1814
|
return {
|
|
1814
1815
|
contents: code,
|
|
1815
|
-
loader: args.path.split(".").pop()
|
|
1816
|
+
loader: (_a = args.path) == null ? void 0 : _a.split(".").pop()
|
|
1816
1817
|
};
|
|
1817
1818
|
}, "cacheDirectivePlugin");
|
|
1818
1819
|
}
|
|
@@ -1888,7 +1889,10 @@ var init_default = __esm({
|
|
|
1888
1889
|
init_CachePlugin();
|
|
1889
1890
|
init_MacroPlugin();
|
|
1890
1891
|
defaultConfig = {
|
|
1891
|
-
plugins: [
|
|
1892
|
+
plugins: [
|
|
1893
|
+
new CachePlugin({ enabled: true }),
|
|
1894
|
+
new MacroPlugin({ enabled: true })
|
|
1895
|
+
],
|
|
1892
1896
|
esbuildPlugins: [],
|
|
1893
1897
|
compilerOptions: {
|
|
1894
1898
|
macro: {
|
|
@@ -1914,42 +1918,45 @@ var init_default = __esm({
|
|
|
1914
1918
|
}
|
|
1915
1919
|
});
|
|
1916
1920
|
|
|
1917
|
-
// src/config/utils.ts
|
|
1918
|
-
var mergeDeep;
|
|
1919
|
-
var init_utils = __esm({
|
|
1920
|
-
"src/config/utils.ts"() {
|
|
1921
|
-
"use strict";
|
|
1922
|
-
init_cjs_shims();
|
|
1923
|
-
mergeDeep = /* @__PURE__ */ __name((target, source) => {
|
|
1924
|
-
const isObject = /* @__PURE__ */ __name((obj) => obj && typeof obj === "object" && !Array.isArray(obj), "isObject");
|
|
1925
|
-
const output = { ...target };
|
|
1926
|
-
if (isObject(target) && isObject(source)) {
|
|
1927
|
-
Object.keys(source).forEach((key) => {
|
|
1928
|
-
if (isObject(source[key])) {
|
|
1929
|
-
if (!(key in target)) {
|
|
1930
|
-
Object.assign(output, { [key]: source[key] });
|
|
1931
|
-
} else {
|
|
1932
|
-
output[key] = mergeDeep(target[key], source[key]);
|
|
1933
|
-
}
|
|
1934
|
-
} else {
|
|
1935
|
-
Object.assign(output, { [key]: source[key] });
|
|
1936
|
-
}
|
|
1937
|
-
});
|
|
1938
|
-
}
|
|
1939
|
-
return output;
|
|
1940
|
-
}, "mergeDeep");
|
|
1941
|
-
}
|
|
1942
|
-
});
|
|
1943
|
-
|
|
1944
1921
|
// src/config/config.ts
|
|
1945
1922
|
function getConfig() {
|
|
1946
1923
|
return defined;
|
|
1947
1924
|
}
|
|
1948
1925
|
function defineConfig(config = {}) {
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1926
|
+
var _a, _b;
|
|
1927
|
+
defined = {
|
|
1928
|
+
compilerOptions: {
|
|
1929
|
+
cache: {
|
|
1930
|
+
...defaultConfig.compilerOptions.cache,
|
|
1931
|
+
...(_a = config.compilerOptions) == null ? void 0 : _a.cache
|
|
1932
|
+
},
|
|
1933
|
+
macro: {
|
|
1934
|
+
...defaultConfig.compilerOptions.macro,
|
|
1935
|
+
...(_b = config.compilerOptions) == null ? void 0 : _b.macro
|
|
1936
|
+
}
|
|
1937
|
+
},
|
|
1938
|
+
distDir: config.distDir ?? defaultConfig.distDir,
|
|
1939
|
+
env: {
|
|
1940
|
+
...defaultConfig.env,
|
|
1941
|
+
...config.env
|
|
1942
|
+
},
|
|
1943
|
+
esbuildPlugins: [
|
|
1944
|
+
...config.esbuildPlugins ?? [],
|
|
1945
|
+
...defaultConfig.esbuildPlugins ?? []
|
|
1946
|
+
],
|
|
1947
|
+
plugins: [...config.plugins ?? [], ...defaultConfig.plugins ?? []],
|
|
1948
|
+
sourceMap: {
|
|
1949
|
+
...defaultConfig.sourceMap,
|
|
1950
|
+
...config.sourceMap
|
|
1951
|
+
},
|
|
1952
|
+
static: config.static ?? defaultConfig.static,
|
|
1953
|
+
typedCommands: config.typedCommands ?? defaultConfig.typedCommands,
|
|
1954
|
+
typedLocales: config.typedLocales ?? defaultConfig.typedLocales,
|
|
1955
|
+
typescript: {
|
|
1956
|
+
...defaultConfig.typescript,
|
|
1957
|
+
...config.typescript
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1953
1960
|
return defined;
|
|
1954
1961
|
}
|
|
1955
1962
|
var defined;
|
|
@@ -1958,7 +1965,6 @@ var init_config = __esm({
|
|
|
1958
1965
|
"use strict";
|
|
1959
1966
|
init_cjs_shims();
|
|
1960
1967
|
init_default();
|
|
1961
|
-
init_utils();
|
|
1962
1968
|
defined = defaultConfig;
|
|
1963
1969
|
__name(getConfig, "getConfig");
|
|
1964
1970
|
__name(defineConfig, "defineConfig");
|
|
@@ -1976,16 +1982,16 @@ var init_DefaultLocalizationStrategy = __esm({
|
|
|
1976
1982
|
init_config();
|
|
1977
1983
|
import_node_fs = require("fs");
|
|
1978
1984
|
_DefaultLocalizationStrategy = class _DefaultLocalizationStrategy {
|
|
1979
|
-
constructor(
|
|
1980
|
-
this.commandkit =
|
|
1985
|
+
constructor(commandkit2) {
|
|
1986
|
+
this.commandkit = commandkit2;
|
|
1981
1987
|
}
|
|
1982
1988
|
translations = /* @__PURE__ */ new Map();
|
|
1983
1989
|
async locateTranslation(scope, locale) {
|
|
1984
1990
|
const localesPath = this.commandkit.getPath("locales");
|
|
1985
1991
|
if (!localesPath) return null;
|
|
1986
|
-
const
|
|
1992
|
+
const path2 = (0, import_node_path.join)(localesPath, locale, `${scope}.json`);
|
|
1987
1993
|
try {
|
|
1988
|
-
const data = await (0, import_promises2.readFile)(
|
|
1994
|
+
const data = await (0, import_promises2.readFile)(path2, "utf-8");
|
|
1989
1995
|
const localeData = JSON.parse(data);
|
|
1990
1996
|
await this.generateLocaleTypes(localeData);
|
|
1991
1997
|
return localeData;
|
|
@@ -2146,213 +2152,524 @@ var init_utilities = __esm({
|
|
|
2146
2152
|
}
|
|
2147
2153
|
});
|
|
2148
2154
|
|
|
2149
|
-
// src/
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
"
|
|
2155
|
+
// src/utils/resolve-file-url.ts
|
|
2156
|
+
function toFileURL(filePath, withTs = false) {
|
|
2157
|
+
const resolvedPath = import_path.default.resolve(filePath);
|
|
2158
|
+
return `${"file://" + resolvedPath.replace(/\\\\|\\/g, "/")}${withTs ? `?ts=${Date.now()}` : ""}`;
|
|
2159
|
+
}
|
|
2160
|
+
var import_path;
|
|
2161
|
+
var init_resolve_file_url = __esm({
|
|
2162
|
+
"src/utils/resolve-file-url.ts"() {
|
|
2153
2163
|
"use strict";
|
|
2154
2164
|
init_cjs_shims();
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
* Creates a new localization instance.
|
|
2158
|
-
* @param commandkit The command kit instance.
|
|
2159
|
-
* @param config The localization configuration.
|
|
2160
|
-
*/
|
|
2161
|
-
constructor(commandkit, config) {
|
|
2162
|
-
this.commandkit = commandkit;
|
|
2163
|
-
this.config = config;
|
|
2164
|
-
const strategy = this.commandkit.config.localizationStrategy;
|
|
2165
|
-
const { locale, target } = this.config;
|
|
2166
|
-
this.t = (translatable, args) => {
|
|
2167
|
-
return strategy.translate({
|
|
2168
|
-
args,
|
|
2169
|
-
key: translatable,
|
|
2170
|
-
locale,
|
|
2171
|
-
scope: target
|
|
2172
|
-
});
|
|
2173
|
-
};
|
|
2174
|
-
}
|
|
2175
|
-
/**
|
|
2176
|
-
* Translates the given translatable object.
|
|
2177
|
-
* @param translatable The translatable object to translate.
|
|
2178
|
-
*/
|
|
2179
|
-
t;
|
|
2180
|
-
/**
|
|
2181
|
-
* Get the localization strategy.
|
|
2182
|
-
*/
|
|
2183
|
-
getStrategy() {
|
|
2184
|
-
return this.commandkit.config.localizationStrategy;
|
|
2185
|
-
}
|
|
2186
|
-
/**
|
|
2187
|
-
* Get the default locale
|
|
2188
|
-
*/
|
|
2189
|
-
getDefaultLocale() {
|
|
2190
|
-
return this.commandkit.config.defaultLocale;
|
|
2191
|
-
}
|
|
2192
|
-
/**
|
|
2193
|
-
* Get the current locale
|
|
2194
|
-
*/
|
|
2195
|
-
getLocale() {
|
|
2196
|
-
return this.config.locale;
|
|
2197
|
-
}
|
|
2198
|
-
/**
|
|
2199
|
-
* Get the localization target
|
|
2200
|
-
*/
|
|
2201
|
-
getTarget() {
|
|
2202
|
-
return this.config.target;
|
|
2203
|
-
}
|
|
2204
|
-
};
|
|
2205
|
-
__name(_Localization, "Localization");
|
|
2206
|
-
Localization = _Localization;
|
|
2165
|
+
import_path = __toESM(require("path"));
|
|
2166
|
+
__name(toFileURL, "toFileURL");
|
|
2207
2167
|
}
|
|
2208
2168
|
});
|
|
2209
2169
|
|
|
2210
|
-
// src/
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
throw new Error("after must be called inside commandkit handler.");
|
|
2215
|
-
}
|
|
2216
|
-
return env.registerDeferredFunction(fn);
|
|
2217
|
-
}
|
|
2218
|
-
function cancelAfterCommand(id) {
|
|
2219
|
-
const env = getContext();
|
|
2220
|
-
if (!env) {
|
|
2221
|
-
throw new Error("cancelAfter must be called inside commandkit handler.");
|
|
2222
|
-
}
|
|
2223
|
-
env.clearDeferredFunction(id);
|
|
2224
|
-
}
|
|
2225
|
-
var import_node_crypto, _data, _CommandKitEnvironment, CommandKitEnvironment, CommandKitEnvironmentType;
|
|
2226
|
-
var init_environment = __esm({
|
|
2227
|
-
"src/context/environment.ts"() {
|
|
2170
|
+
// src/app/commands/MessageCommandParser.ts
|
|
2171
|
+
var import_discord8, _parsed, _options, _args, _MessageCommandParser, MessageCommandParser, _MessageCommandOptions, MessageCommandOptions;
|
|
2172
|
+
var init_MessageCommandParser = __esm({
|
|
2173
|
+
"src/app/commands/MessageCommandParser.ts"() {
|
|
2228
2174
|
"use strict";
|
|
2229
2175
|
init_cjs_shims();
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
this
|
|
2239
|
-
__privateAdd(this,
|
|
2240
|
-
executionError: null,
|
|
2241
|
-
type: null,
|
|
2242
|
-
variables: /* @__PURE__ */ new Map(),
|
|
2243
|
-
deferredFunctions: /* @__PURE__ */ new Map(),
|
|
2244
|
-
marker: "",
|
|
2245
|
-
markStart: 0,
|
|
2246
|
-
markEnd: 0
|
|
2247
|
-
});
|
|
2248
|
-
}
|
|
2249
|
-
/**
|
|
2250
|
-
* Get the execution error.
|
|
2251
|
-
* @internal
|
|
2252
|
-
*/
|
|
2253
|
-
getExecutionError() {
|
|
2254
|
-
return __privateGet(this, _data).executionError;
|
|
2176
|
+
import_discord8 = require("discord.js");
|
|
2177
|
+
init_error_codes();
|
|
2178
|
+
_MessageCommandParser = class _MessageCommandParser {
|
|
2179
|
+
constructor(message, prefix, schema) {
|
|
2180
|
+
this.message = message;
|
|
2181
|
+
this.prefix = prefix;
|
|
2182
|
+
this.schema = schema;
|
|
2183
|
+
__privateAdd(this, _parsed, null);
|
|
2184
|
+
__privateAdd(this, _options, null);
|
|
2185
|
+
__privateAdd(this, _args, []);
|
|
2255
2186
|
}
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
* @internal
|
|
2260
|
-
*/
|
|
2261
|
-
setExecutionError(error) {
|
|
2262
|
-
if (__privateGet(this, _data).executionError) {
|
|
2263
|
-
throw new Error("Execution error already set.");
|
|
2264
|
-
}
|
|
2265
|
-
__privateGet(this, _data).executionError = error;
|
|
2187
|
+
getArgs() {
|
|
2188
|
+
void this.parse();
|
|
2189
|
+
return __privateGet(this, _args);
|
|
2266
2190
|
}
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
getType() {
|
|
2271
|
-
const type = __privateGet(this, _data).type;
|
|
2272
|
-
if (!type) {
|
|
2273
|
-
throw new Error("Environment type not set.");
|
|
2191
|
+
get options() {
|
|
2192
|
+
if (!__privateGet(this, _options)) {
|
|
2193
|
+
__privateSet(this, _options, new MessageCommandOptions(this));
|
|
2274
2194
|
}
|
|
2275
|
-
return
|
|
2195
|
+
return __privateGet(this, _options);
|
|
2276
2196
|
}
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
* @internal
|
|
2281
|
-
*/
|
|
2282
|
-
setType(type) {
|
|
2283
|
-
__privateGet(this, _data).type = type;
|
|
2197
|
+
getOption(name) {
|
|
2198
|
+
var _a;
|
|
2199
|
+
return (_a = this.parse().options.find((o) => o.name === name)) == null ? void 0 : _a.value;
|
|
2284
2200
|
}
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
*/
|
|
2288
|
-
get variables() {
|
|
2289
|
-
return __privateGet(this, _data).variables;
|
|
2201
|
+
getCommand() {
|
|
2202
|
+
return this.parse().command;
|
|
2290
2203
|
}
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
* @param fn - The deferred function to register.
|
|
2294
|
-
* @returns The deferred function id.
|
|
2295
|
-
* @internal
|
|
2296
|
-
*/
|
|
2297
|
-
registerDeferredFunction(fn) {
|
|
2298
|
-
const id = (0, import_node_crypto.randomUUID)();
|
|
2299
|
-
__privateGet(this, _data).deferredFunctions.set(id, fn);
|
|
2300
|
-
return id;
|
|
2204
|
+
getSubcommand() {
|
|
2205
|
+
return this.parse().subcommand;
|
|
2301
2206
|
}
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
* @param id - The deferred function id to clear.
|
|
2305
|
-
* @internal
|
|
2306
|
-
*/
|
|
2307
|
-
clearDeferredFunction(id) {
|
|
2308
|
-
__privateGet(this, _data).deferredFunctions.delete(id);
|
|
2207
|
+
getSubcommandGroup() {
|
|
2208
|
+
return this.parse().subcommandGroup;
|
|
2309
2209
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
async runDeferredFunctions() {
|
|
2315
|
-
for (const [id, fn] of __privateGet(this, _data).deferredFunctions) {
|
|
2316
|
-
try {
|
|
2317
|
-
await fn(this);
|
|
2318
|
-
} catch (e) {
|
|
2319
|
-
this.commandkit.emit("unhandledDeferredFunctionRejection", e);
|
|
2320
|
-
} finally {
|
|
2321
|
-
this.clearDeferredFunction(id);
|
|
2210
|
+
getPrefix() {
|
|
2211
|
+
for (const p of this.prefix) {
|
|
2212
|
+
if (this.message.content.startsWith(p)) {
|
|
2213
|
+
return p;
|
|
2322
2214
|
}
|
|
2323
2215
|
}
|
|
2324
2216
|
}
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
* @internal
|
|
2328
|
-
*/
|
|
2329
|
-
clearAllDeferredFunctions() {
|
|
2330
|
-
__privateGet(this, _data).deferredFunctions.clear();
|
|
2331
|
-
}
|
|
2332
|
-
/**
|
|
2333
|
-
* Mark the start of a command execution.
|
|
2334
|
-
* @param marker - The marker to set.
|
|
2335
|
-
* @internal
|
|
2336
|
-
*/
|
|
2337
|
-
markStart(marker) {
|
|
2338
|
-
__privateGet(this, _data).marker = marker;
|
|
2339
|
-
__privateGet(this, _data).markStart = performance.now();
|
|
2340
|
-
}
|
|
2341
|
-
/**
|
|
2342
|
-
* Mark the end of a command execution.
|
|
2343
|
-
* @internal
|
|
2344
|
-
*/
|
|
2345
|
-
markEnd() {
|
|
2346
|
-
if (!__privateGet(this, _data).markEnd) __privateGet(this, _data).markEnd = performance.now();
|
|
2347
|
-
}
|
|
2348
|
-
/**
|
|
2349
|
-
* Get the marker.
|
|
2350
|
-
* @internal
|
|
2351
|
-
*/
|
|
2352
|
-
getMarker() {
|
|
2353
|
-
return __privateGet(this, _data).marker;
|
|
2217
|
+
getFullCommand() {
|
|
2218
|
+
return [this.getCommand(), this.getSubcommandGroup(), this.getSubcommand()].filter((v) => v).join(" ");
|
|
2354
2219
|
}
|
|
2355
|
-
|
|
2220
|
+
parse() {
|
|
2221
|
+
if (__privateGet(this, _parsed)) {
|
|
2222
|
+
return __privateGet(this, _parsed);
|
|
2223
|
+
}
|
|
2224
|
+
const content = this.message.content;
|
|
2225
|
+
const prefix = this.getPrefix();
|
|
2226
|
+
if (!prefix) {
|
|
2227
|
+
throw createCommandKitError(CommandKitErrorCodes.InvalidCommandPrefix);
|
|
2228
|
+
}
|
|
2229
|
+
const parts = content.slice(prefix.length).trim().split(" ");
|
|
2230
|
+
const command = parts.shift();
|
|
2231
|
+
__privateSet(this, _args, parts);
|
|
2232
|
+
let subcommandGroup;
|
|
2233
|
+
let subcommand;
|
|
2234
|
+
if (command == null ? void 0 : command.includes(":")) {
|
|
2235
|
+
const [, group, cmd] = command.split(":");
|
|
2236
|
+
if (!cmd && group) {
|
|
2237
|
+
subcommand = group;
|
|
2238
|
+
} else if (cmd && group) {
|
|
2239
|
+
subcommandGroup = group;
|
|
2240
|
+
subcommand = cmd;
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
const schema = this.schema(
|
|
2244
|
+
[command, subcommandGroup, subcommand].filter(Boolean).join(" ").trim()
|
|
2245
|
+
);
|
|
2246
|
+
const options = parts.map((part) => {
|
|
2247
|
+
try {
|
|
2248
|
+
const [name, value] = part.split(":");
|
|
2249
|
+
if (!(name in schema)) return null;
|
|
2250
|
+
switch (schema[name]) {
|
|
2251
|
+
case import_discord8.ApplicationCommandOptionType.Boolean:
|
|
2252
|
+
return { name, value: value === "true" };
|
|
2253
|
+
case import_discord8.ApplicationCommandOptionType.Integer:
|
|
2254
|
+
return { name, value: parseInt(value, 10) };
|
|
2255
|
+
case import_discord8.ApplicationCommandOptionType.Number:
|
|
2256
|
+
return { name, value: parseFloat(value) };
|
|
2257
|
+
case import_discord8.ApplicationCommandOptionType.String:
|
|
2258
|
+
return { name, value };
|
|
2259
|
+
case import_discord8.ApplicationCommandOptionType.User:
|
|
2260
|
+
return {
|
|
2261
|
+
name,
|
|
2262
|
+
value: this.message.mentions.users.find((u) => {
|
|
2263
|
+
return u.id === value.replace(/[<@!>]/g, "");
|
|
2264
|
+
})
|
|
2265
|
+
};
|
|
2266
|
+
case import_discord8.ApplicationCommandOptionType.Channel:
|
|
2267
|
+
return {
|
|
2268
|
+
name,
|
|
2269
|
+
value: this.message.mentions.channels.find((c) => {
|
|
2270
|
+
return c.id === value.replace(/[<#>]/g, "");
|
|
2271
|
+
})
|
|
2272
|
+
};
|
|
2273
|
+
case import_discord8.ApplicationCommandOptionType.Role:
|
|
2274
|
+
return {
|
|
2275
|
+
name,
|
|
2276
|
+
value: this.message.mentions.roles.find((r) => {
|
|
2277
|
+
return r.id === value.replace(/[<@&>]/g, "");
|
|
2278
|
+
})
|
|
2279
|
+
};
|
|
2280
|
+
case import_discord8.ApplicationCommandOptionType.Attachment:
|
|
2281
|
+
return {
|
|
2282
|
+
name,
|
|
2283
|
+
value: this.message.attachments.find((a) => {
|
|
2284
|
+
return a.name === value;
|
|
2285
|
+
})
|
|
2286
|
+
};
|
|
2287
|
+
default:
|
|
2288
|
+
return null;
|
|
2289
|
+
}
|
|
2290
|
+
} catch {
|
|
2291
|
+
return null;
|
|
2292
|
+
}
|
|
2293
|
+
}).filter((v) => v !== null);
|
|
2294
|
+
__privateSet(this, _parsed, {
|
|
2295
|
+
command,
|
|
2296
|
+
options,
|
|
2297
|
+
subcommand,
|
|
2298
|
+
subcommandGroup
|
|
2299
|
+
});
|
|
2300
|
+
return __privateGet(this, _parsed);
|
|
2301
|
+
}
|
|
2302
|
+
};
|
|
2303
|
+
_parsed = new WeakMap();
|
|
2304
|
+
_options = new WeakMap();
|
|
2305
|
+
_args = new WeakMap();
|
|
2306
|
+
__name(_MessageCommandParser, "MessageCommandParser");
|
|
2307
|
+
MessageCommandParser = _MessageCommandParser;
|
|
2308
|
+
_MessageCommandOptions = class _MessageCommandOptions {
|
|
2309
|
+
constructor(parser2) {
|
|
2310
|
+
this.parser = parser2;
|
|
2311
|
+
}
|
|
2312
|
+
assertOption(name, required = false) {
|
|
2313
|
+
const option = this.parser.getOption(name);
|
|
2314
|
+
if (required && option === void 0) {
|
|
2315
|
+
throw new Error(`Option "${name}" is required.`);
|
|
2316
|
+
}
|
|
2317
|
+
return option ?? null;
|
|
2318
|
+
}
|
|
2319
|
+
getMember(name, required = false) {
|
|
2320
|
+
var _a;
|
|
2321
|
+
const user = this.assertOption(name, required);
|
|
2322
|
+
const member = (_a = this.parser.message.guild) == null ? void 0 : _a.members.cache.get(user == null ? void 0 : user.id);
|
|
2323
|
+
if (required && !member) {
|
|
2324
|
+
throw new Error(`Member "${name}" is required.`);
|
|
2325
|
+
}
|
|
2326
|
+
return member ?? null;
|
|
2327
|
+
}
|
|
2328
|
+
getAttachment(name, required = false) {
|
|
2329
|
+
return this.assertOption(name, required);
|
|
2330
|
+
}
|
|
2331
|
+
getBoolean(name, required = false) {
|
|
2332
|
+
return this.assertOption(name, required);
|
|
2333
|
+
}
|
|
2334
|
+
getNumber(name, required = false) {
|
|
2335
|
+
return this.assertOption(name, required);
|
|
2336
|
+
}
|
|
2337
|
+
getString(name, required = false) {
|
|
2338
|
+
return this.assertOption(name, required);
|
|
2339
|
+
}
|
|
2340
|
+
getInteger(name, required = false) {
|
|
2341
|
+
return this.assertOption(name, required);
|
|
2342
|
+
}
|
|
2343
|
+
getUser(name, required = false) {
|
|
2344
|
+
return this.assertOption(name, required);
|
|
2345
|
+
}
|
|
2346
|
+
getChannel(name, required = false) {
|
|
2347
|
+
return this.assertOption(name, required);
|
|
2348
|
+
}
|
|
2349
|
+
getRole(name, required = false) {
|
|
2350
|
+
return this.assertOption(name, required);
|
|
2351
|
+
}
|
|
2352
|
+
getMentionable(name, required = false) {
|
|
2353
|
+
const target = this.assertOption(name, required);
|
|
2354
|
+
if (target instanceof import_discord8.GuildMember || target instanceof import_discord8.User || target instanceof import_discord8.Role) {
|
|
2355
|
+
return target;
|
|
2356
|
+
}
|
|
2357
|
+
if (required) {
|
|
2358
|
+
throw new Error(`Mentionable "${name}" is required.`);
|
|
2359
|
+
}
|
|
2360
|
+
return null;
|
|
2361
|
+
}
|
|
2362
|
+
getSubcommand(required = false) {
|
|
2363
|
+
const sub = this.parser.getSubcommand();
|
|
2364
|
+
if (required && sub === void 0) {
|
|
2365
|
+
throw new Error("Subcommand is required.");
|
|
2366
|
+
}
|
|
2367
|
+
return sub ?? null;
|
|
2368
|
+
}
|
|
2369
|
+
getSubcommandGroup(required = false) {
|
|
2370
|
+
const sub = this.parser.getSubcommandGroup();
|
|
2371
|
+
if (required && sub === void 0) {
|
|
2372
|
+
throw new Error("Subcommand group is required.");
|
|
2373
|
+
}
|
|
2374
|
+
return sub ?? null;
|
|
2375
|
+
}
|
|
2376
|
+
};
|
|
2377
|
+
__name(_MessageCommandOptions, "MessageCommandOptions");
|
|
2378
|
+
MessageCommandOptions = _MessageCommandOptions;
|
|
2379
|
+
}
|
|
2380
|
+
});
|
|
2381
|
+
|
|
2382
|
+
// src/app/register/CommandRegistrar.ts
|
|
2383
|
+
var import_discord9, _CommandRegistrar, CommandRegistrar;
|
|
2384
|
+
var init_CommandRegistrar = __esm({
|
|
2385
|
+
"src/app/register/CommandRegistrar.ts"() {
|
|
2386
|
+
"use strict";
|
|
2387
|
+
init_cjs_shims();
|
|
2388
|
+
import_discord9 = require("discord.js");
|
|
2389
|
+
init_Logger();
|
|
2390
|
+
_CommandRegistrar = class _CommandRegistrar {
|
|
2391
|
+
/**
|
|
2392
|
+
* Creates an instance of CommandRegistrar.
|
|
2393
|
+
* @param commandkit The commandkit instance.
|
|
2394
|
+
*/
|
|
2395
|
+
constructor(commandkit2) {
|
|
2396
|
+
this.commandkit = commandkit2;
|
|
2397
|
+
this.api.setToken(
|
|
2398
|
+
this.commandkit.client.token ?? process.env.DISCORD_TOKEN ?? process.env.TOKEN ?? ""
|
|
2399
|
+
);
|
|
2400
|
+
}
|
|
2401
|
+
api = new import_discord9.REST();
|
|
2402
|
+
/**
|
|
2403
|
+
* Gets the commands data.
|
|
2404
|
+
*/
|
|
2405
|
+
getCommandsData() {
|
|
2406
|
+
const handler = this.commandkit.commandHandler;
|
|
2407
|
+
const commands = handler.getCommandsArray();
|
|
2408
|
+
return commands.flatMap((cmd) => {
|
|
2409
|
+
const json = "toJSON" in cmd.data.command ? cmd.data.command.toJSON() : cmd.data.command;
|
|
2410
|
+
const collections = [json];
|
|
2411
|
+
if (cmd.data.userContextMenu && json.type !== import_discord9.ApplicationCommandType.User) {
|
|
2412
|
+
collections.push({
|
|
2413
|
+
...json,
|
|
2414
|
+
type: import_discord9.ApplicationCommandType.User,
|
|
2415
|
+
options: void 0,
|
|
2416
|
+
description_localizations: void 0,
|
|
2417
|
+
// @ts-ignore
|
|
2418
|
+
description: void 0
|
|
2419
|
+
});
|
|
2420
|
+
}
|
|
2421
|
+
if (cmd.data.messageContextMenu && json.type !== import_discord9.ApplicationCommandType.Message) {
|
|
2422
|
+
collections.push({
|
|
2423
|
+
...json,
|
|
2424
|
+
type: import_discord9.ApplicationCommandType.Message,
|
|
2425
|
+
description_localizations: void 0,
|
|
2426
|
+
// @ts-ignore
|
|
2427
|
+
description: void 0,
|
|
2428
|
+
options: void 0
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
return collections;
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
2435
|
+
* Registers loaded commands.
|
|
2436
|
+
*/
|
|
2437
|
+
async register() {
|
|
2438
|
+
if (!this.commandkit.client.isReady()) {
|
|
2439
|
+
throw new Error("Cannot register commands before the client is ready");
|
|
2440
|
+
}
|
|
2441
|
+
const commands = this.getCommandsData();
|
|
2442
|
+
const guildCommands = commands.filter((command) => {
|
|
2443
|
+
var _a;
|
|
2444
|
+
return (_a = command.guilds) == null ? void 0 : _a.filter(Boolean).length;
|
|
2445
|
+
}).map((c) => {
|
|
2446
|
+
var _a;
|
|
2447
|
+
return {
|
|
2448
|
+
...c,
|
|
2449
|
+
guilds: Array.from(new Set((_a = c.guilds) == null ? void 0 : _a.filter(Boolean)))
|
|
2450
|
+
};
|
|
2451
|
+
});
|
|
2452
|
+
const globalCommands = commands.filter(
|
|
2453
|
+
(command) => {
|
|
2454
|
+
var _a;
|
|
2455
|
+
return !((_a = command.guilds) == null ? void 0 : _a.filter(Boolean).length);
|
|
2456
|
+
}
|
|
2457
|
+
);
|
|
2458
|
+
await this.updateGlobalCommands(globalCommands);
|
|
2459
|
+
await this.updateGuildCommands(guildCommands);
|
|
2460
|
+
}
|
|
2461
|
+
/**
|
|
2462
|
+
* Updates the global commands.
|
|
2463
|
+
*/
|
|
2464
|
+
async updateGlobalCommands(commands) {
|
|
2465
|
+
if (!commands.length) return;
|
|
2466
|
+
try {
|
|
2467
|
+
const data = await this.api.put(
|
|
2468
|
+
import_discord9.Routes.applicationCommands(this.commandkit.client.user.id),
|
|
2469
|
+
{
|
|
2470
|
+
body: commands.map((c) => ({
|
|
2471
|
+
...c,
|
|
2472
|
+
guilds: void 0
|
|
2473
|
+
}))
|
|
2474
|
+
}
|
|
2475
|
+
);
|
|
2476
|
+
Logger.info(
|
|
2477
|
+
`\u2728 Refreshed ${data.length} global application (/) commands`
|
|
2478
|
+
);
|
|
2479
|
+
} catch (e) {
|
|
2480
|
+
Logger.error("Failed to update global application (/) commands", e);
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
/**
|
|
2484
|
+
* Updates the guild commands.
|
|
2485
|
+
*/
|
|
2486
|
+
async updateGuildCommands(commands) {
|
|
2487
|
+
try {
|
|
2488
|
+
const guildCommandsMap = /* @__PURE__ */ new Map();
|
|
2489
|
+
commands.forEach((command) => {
|
|
2490
|
+
var _a;
|
|
2491
|
+
if (!((_a = command.guilds) == null ? void 0 : _a.length)) return;
|
|
2492
|
+
command.guilds.forEach((guild) => {
|
|
2493
|
+
if (!guildCommandsMap.has(guild)) {
|
|
2494
|
+
guildCommandsMap.set(guild, []);
|
|
2495
|
+
}
|
|
2496
|
+
guildCommandsMap.get(guild).push(command);
|
|
2497
|
+
});
|
|
2498
|
+
});
|
|
2499
|
+
if (!guildCommandsMap.size) return;
|
|
2500
|
+
let count = 0;
|
|
2501
|
+
for (const [guild, guildCommands] of guildCommandsMap) {
|
|
2502
|
+
const data = await this.api.put(
|
|
2503
|
+
import_discord9.Routes.applicationGuildCommands(
|
|
2504
|
+
this.commandkit.client.user.id,
|
|
2505
|
+
guild
|
|
2506
|
+
),
|
|
2507
|
+
{
|
|
2508
|
+
body: guildCommands.map((b) => ({
|
|
2509
|
+
...b,
|
|
2510
|
+
guilds: void 0
|
|
2511
|
+
}))
|
|
2512
|
+
}
|
|
2513
|
+
);
|
|
2514
|
+
count += data.length;
|
|
2515
|
+
}
|
|
2516
|
+
Logger.info(`\u2728 Refreshed ${count} guild application (/) commands`);
|
|
2517
|
+
} catch (e) {
|
|
2518
|
+
Logger.error("Failed to update guild application (/) commands", e);
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
};
|
|
2522
|
+
__name(_CommandRegistrar, "CommandRegistrar");
|
|
2523
|
+
CommandRegistrar = _CommandRegistrar;
|
|
2524
|
+
}
|
|
2525
|
+
});
|
|
2526
|
+
|
|
2527
|
+
// src/context/environment.ts
|
|
2528
|
+
function afterCommand(fn) {
|
|
2529
|
+
const env = getContext();
|
|
2530
|
+
if (!env) {
|
|
2531
|
+
throw new Error("after must be called inside commandkit handler.");
|
|
2532
|
+
}
|
|
2533
|
+
return env.registerDeferredFunction(fn);
|
|
2534
|
+
}
|
|
2535
|
+
function cancelAfterCommand(id) {
|
|
2536
|
+
const env = getContext();
|
|
2537
|
+
if (!env) {
|
|
2538
|
+
throw new Error("cancelAfter must be called inside commandkit handler.");
|
|
2539
|
+
}
|
|
2540
|
+
env.clearDeferredFunction(id);
|
|
2541
|
+
}
|
|
2542
|
+
var import_node_crypto, _data, _CommandKitEnvironment, CommandKitEnvironment, CommandKitEnvironmentType;
|
|
2543
|
+
var init_environment = __esm({
|
|
2544
|
+
"src/context/environment.ts"() {
|
|
2545
|
+
"use strict";
|
|
2546
|
+
init_cjs_shims();
|
|
2547
|
+
import_node_crypto = require("crypto");
|
|
2548
|
+
init_async_context();
|
|
2549
|
+
_CommandKitEnvironment = class _CommandKitEnvironment {
|
|
2550
|
+
/**
|
|
2551
|
+
* Creates the commandkit execution environment.
|
|
2552
|
+
* @param commandkit - The commandkit instance.
|
|
2553
|
+
*/
|
|
2554
|
+
constructor(commandkit2) {
|
|
2555
|
+
this.commandkit = commandkit2;
|
|
2556
|
+
__privateAdd(this, _data, {
|
|
2557
|
+
executionError: null,
|
|
2558
|
+
type: null,
|
|
2559
|
+
variables: /* @__PURE__ */ new Map(),
|
|
2560
|
+
deferredFunctions: /* @__PURE__ */ new Map(),
|
|
2561
|
+
marker: "",
|
|
2562
|
+
markStart: 0,
|
|
2563
|
+
markEnd: 0
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
/**
|
|
2567
|
+
* Get the execution error.
|
|
2568
|
+
* @internal
|
|
2569
|
+
*/
|
|
2570
|
+
getExecutionError() {
|
|
2571
|
+
return __privateGet(this, _data).executionError;
|
|
2572
|
+
}
|
|
2573
|
+
/**
|
|
2574
|
+
* Set the execution error.
|
|
2575
|
+
* @param error - The error to set.
|
|
2576
|
+
* @internal
|
|
2577
|
+
*/
|
|
2578
|
+
setExecutionError(error) {
|
|
2579
|
+
if (__privateGet(this, _data).executionError) {
|
|
2580
|
+
throw new Error("Execution error already set.");
|
|
2581
|
+
}
|
|
2582
|
+
__privateGet(this, _data).executionError = error;
|
|
2583
|
+
}
|
|
2584
|
+
/**
|
|
2585
|
+
* Get the environment type.
|
|
2586
|
+
*/
|
|
2587
|
+
getType() {
|
|
2588
|
+
const type = __privateGet(this, _data).type;
|
|
2589
|
+
if (!type) {
|
|
2590
|
+
throw new Error("Environment type not set.");
|
|
2591
|
+
}
|
|
2592
|
+
return type;
|
|
2593
|
+
}
|
|
2594
|
+
/**
|
|
2595
|
+
* Set the environment type.
|
|
2596
|
+
* @param type - The environment type to set.
|
|
2597
|
+
* @internal
|
|
2598
|
+
*/
|
|
2599
|
+
setType(type) {
|
|
2600
|
+
__privateGet(this, _data).type = type;
|
|
2601
|
+
}
|
|
2602
|
+
/**
|
|
2603
|
+
* The variables store for this environment.
|
|
2604
|
+
*/
|
|
2605
|
+
get variables() {
|
|
2606
|
+
return __privateGet(this, _data).variables;
|
|
2607
|
+
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Register a deferred function.
|
|
2610
|
+
* @param fn - The deferred function to register.
|
|
2611
|
+
* @returns The deferred function id.
|
|
2612
|
+
* @internal
|
|
2613
|
+
*/
|
|
2614
|
+
registerDeferredFunction(fn) {
|
|
2615
|
+
const id = (0, import_node_crypto.randomUUID)();
|
|
2616
|
+
__privateGet(this, _data).deferredFunctions.set(id, fn);
|
|
2617
|
+
return id;
|
|
2618
|
+
}
|
|
2619
|
+
/**
|
|
2620
|
+
* Clear a deferred function by id.
|
|
2621
|
+
* @param id - The deferred function id to clear.
|
|
2622
|
+
* @internal
|
|
2623
|
+
*/
|
|
2624
|
+
clearDeferredFunction(id) {
|
|
2625
|
+
__privateGet(this, _data).deferredFunctions.delete(id);
|
|
2626
|
+
}
|
|
2627
|
+
/**
|
|
2628
|
+
* Run all deferred functions sequentially.
|
|
2629
|
+
* @internal
|
|
2630
|
+
*/
|
|
2631
|
+
async runDeferredFunctions() {
|
|
2632
|
+
for (const [id, fn] of __privateGet(this, _data).deferredFunctions) {
|
|
2633
|
+
try {
|
|
2634
|
+
await fn(this);
|
|
2635
|
+
} catch (e) {
|
|
2636
|
+
this.commandkit.emit("unhandledDeferredFunctionRejection", e);
|
|
2637
|
+
} finally {
|
|
2638
|
+
this.clearDeferredFunction(id);
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
/**
|
|
2643
|
+
* Clear all deferred functions.
|
|
2644
|
+
* @internal
|
|
2645
|
+
*/
|
|
2646
|
+
clearAllDeferredFunctions() {
|
|
2647
|
+
__privateGet(this, _data).deferredFunctions.clear();
|
|
2648
|
+
}
|
|
2649
|
+
/**
|
|
2650
|
+
* Mark the start of a command execution.
|
|
2651
|
+
* @param marker - The marker to set.
|
|
2652
|
+
* @internal
|
|
2653
|
+
*/
|
|
2654
|
+
markStart(marker) {
|
|
2655
|
+
__privateGet(this, _data).marker = marker;
|
|
2656
|
+
__privateGet(this, _data).markStart = performance.now();
|
|
2657
|
+
}
|
|
2658
|
+
/**
|
|
2659
|
+
* Mark the end of a command execution.
|
|
2660
|
+
* @internal
|
|
2661
|
+
*/
|
|
2662
|
+
markEnd() {
|
|
2663
|
+
if (!__privateGet(this, _data).markEnd) __privateGet(this, _data).markEnd = performance.now();
|
|
2664
|
+
}
|
|
2665
|
+
/**
|
|
2666
|
+
* Get the marker.
|
|
2667
|
+
* @internal
|
|
2668
|
+
*/
|
|
2669
|
+
getMarker() {
|
|
2670
|
+
return __privateGet(this, _data).marker;
|
|
2671
|
+
}
|
|
2672
|
+
/**
|
|
2356
2673
|
* Get the execution time in milliseconds.
|
|
2357
2674
|
* @internal
|
|
2358
2675
|
*/
|
|
@@ -2372,6 +2689,67 @@ var init_environment = __esm({
|
|
|
2372
2689
|
}
|
|
2373
2690
|
});
|
|
2374
2691
|
|
|
2692
|
+
// src/app/i18n/Localization.ts
|
|
2693
|
+
var _Localization, Localization;
|
|
2694
|
+
var init_Localization = __esm({
|
|
2695
|
+
"src/app/i18n/Localization.ts"() {
|
|
2696
|
+
"use strict";
|
|
2697
|
+
init_cjs_shims();
|
|
2698
|
+
_Localization = class _Localization {
|
|
2699
|
+
/**
|
|
2700
|
+
* Creates a new localization instance.
|
|
2701
|
+
* @param commandkit The command kit instance.
|
|
2702
|
+
* @param config The localization configuration.
|
|
2703
|
+
*/
|
|
2704
|
+
constructor(commandkit2, config) {
|
|
2705
|
+
this.commandkit = commandkit2;
|
|
2706
|
+
this.config = config;
|
|
2707
|
+
const strategy = this.commandkit.config.localizationStrategy;
|
|
2708
|
+
const { locale, target } = this.config;
|
|
2709
|
+
this.t = (translatable, args) => {
|
|
2710
|
+
return strategy.translate({
|
|
2711
|
+
args,
|
|
2712
|
+
key: translatable,
|
|
2713
|
+
locale,
|
|
2714
|
+
scope: target
|
|
2715
|
+
});
|
|
2716
|
+
};
|
|
2717
|
+
}
|
|
2718
|
+
/**
|
|
2719
|
+
* Translates the given translatable object.
|
|
2720
|
+
* @param translatable The translatable object to translate.
|
|
2721
|
+
*/
|
|
2722
|
+
t;
|
|
2723
|
+
/**
|
|
2724
|
+
* Get the localization strategy.
|
|
2725
|
+
*/
|
|
2726
|
+
getStrategy() {
|
|
2727
|
+
return this.commandkit.config.localizationStrategy;
|
|
2728
|
+
}
|
|
2729
|
+
/**
|
|
2730
|
+
* Get the default locale
|
|
2731
|
+
*/
|
|
2732
|
+
getDefaultLocale() {
|
|
2733
|
+
return this.commandkit.config.defaultLocale;
|
|
2734
|
+
}
|
|
2735
|
+
/**
|
|
2736
|
+
* Get the current locale
|
|
2737
|
+
*/
|
|
2738
|
+
getLocale() {
|
|
2739
|
+
return this.config.locale;
|
|
2740
|
+
}
|
|
2741
|
+
/**
|
|
2742
|
+
* Get the localization target
|
|
2743
|
+
*/
|
|
2744
|
+
getTarget() {
|
|
2745
|
+
return this.config.target;
|
|
2746
|
+
}
|
|
2747
|
+
};
|
|
2748
|
+
__name(_Localization, "Localization");
|
|
2749
|
+
Localization = _Localization;
|
|
2750
|
+
}
|
|
2751
|
+
});
|
|
2752
|
+
|
|
2375
2753
|
// src/app/middleware/signals.ts
|
|
2376
2754
|
function exitMiddleware() {
|
|
2377
2755
|
throw createCommandKitError(CommandKitErrorCodes.ExitMiddleware);
|
|
@@ -2398,8 +2776,8 @@ function md5(data) {
|
|
|
2398
2776
|
return (0, import_node_crypto2.createHash)("md5").update(data).digest("hex");
|
|
2399
2777
|
}
|
|
2400
2778
|
function getCacheProvider() {
|
|
2401
|
-
const
|
|
2402
|
-
const provider =
|
|
2779
|
+
const commandkit2 = getCommandKit(true);
|
|
2780
|
+
const provider = commandkit2.getCacheProvider();
|
|
2403
2781
|
if (!provider) {
|
|
2404
2782
|
throw new Error(
|
|
2405
2783
|
`Cache provider was not found, please provide a cache provider to commandkit.`
|
|
@@ -2566,8 +2944,8 @@ var init_Context = __esm({
|
|
|
2566
2944
|
* @param commandkit The command kit instance.
|
|
2567
2945
|
* @param config The context parameters.
|
|
2568
2946
|
*/
|
|
2569
|
-
constructor(
|
|
2570
|
-
this.commandkit =
|
|
2947
|
+
constructor(commandkit2, config) {
|
|
2948
|
+
this.commandkit = commandkit2;
|
|
2571
2949
|
this.config = config;
|
|
2572
2950
|
/**
|
|
2573
2951
|
* The interaction that triggered the command.
|
|
@@ -2585,7 +2963,7 @@ var init_Context = __esm({
|
|
|
2585
2963
|
__publicField(this, "_locale", null);
|
|
2586
2964
|
this.interaction = config.interaction;
|
|
2587
2965
|
this.message = config.message;
|
|
2588
|
-
this.client =
|
|
2966
|
+
this.client = commandkit2.client;
|
|
2589
2967
|
__privateSet(this, _store, config.store ?? /* @__PURE__ */ new Map());
|
|
2590
2968
|
}
|
|
2591
2969
|
/**
|
|
@@ -2674,639 +3052,317 @@ var init_Context = __esm({
|
|
|
2674
3052
|
}
|
|
2675
3053
|
/**
|
|
2676
3054
|
* Whether the command was triggered by an autocomplete interaction.
|
|
2677
|
-
*/
|
|
2678
|
-
isAutocomplete() {
|
|
2679
|
-
return this.executionMode === CommandExecutionMode.Autocomplete;
|
|
2680
|
-
}
|
|
2681
|
-
/**
|
|
2682
|
-
* Whether the command was triggered by a message context menu interaction.
|
|
2683
|
-
*/
|
|
2684
|
-
isMessageContextMenu() {
|
|
2685
|
-
return this.executionMode === CommandExecutionMode.MessageContextMenu;
|
|
2686
|
-
}
|
|
2687
|
-
/**
|
|
2688
|
-
* Whether the command was triggered by a user context menu interaction.
|
|
2689
|
-
*/
|
|
2690
|
-
isUserContextMenu() {
|
|
2691
|
-
return this.executionMode === CommandExecutionMode.UserContextMenu;
|
|
2692
|
-
}
|
|
2693
|
-
/**
|
|
2694
|
-
* Whether the command was triggered by a message.
|
|
2695
|
-
*/
|
|
2696
|
-
isMessage() {
|
|
2697
|
-
return this.executionMode === CommandExecutionMode.Message;
|
|
2698
|
-
}
|
|
2699
|
-
/**
|
|
2700
|
-
* Returns the command identifier.
|
|
2701
|
-
*/
|
|
2702
|
-
getCommandIdentifier() {
|
|
2703
|
-
if (this.isInteraction()) {
|
|
2704
|
-
return this.interaction.commandName;
|
|
2705
|
-
} else {
|
|
2706
|
-
return this.message.content.split(" ")[0].slice(1);
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
/**
|
|
2710
|
-
* Returns the locale of the guild where this command was triggered.
|
|
2711
|
-
*/
|
|
2712
|
-
getGuildLocale() {
|
|
2713
|
-
var _a;
|
|
2714
|
-
if (this.isInteraction()) {
|
|
2715
|
-
return this.interaction.guildLocale;
|
|
2716
|
-
} else {
|
|
2717
|
-
return ((_a = this.message.guild) == null ? void 0 : _a.preferredLocale) ?? null;
|
|
2718
|
-
}
|
|
2719
|
-
}
|
|
2720
|
-
/**
|
|
2721
|
-
* Returns the locale of the user who triggered this command.
|
|
2722
|
-
*/
|
|
2723
|
-
getUserLocale() {
|
|
2724
|
-
if (this.isInteraction()) {
|
|
2725
|
-
return this.interaction.locale;
|
|
2726
|
-
} else {
|
|
2727
|
-
return null;
|
|
2728
|
-
}
|
|
2729
|
-
}
|
|
2730
|
-
/**
|
|
2731
|
-
* Returns the locale for this command.
|
|
2732
|
-
* @param preferUser Whether to prefer the user's locale over the guild's locale.
|
|
2733
|
-
* @returns The locale for this command. If no locale is found, the default locale is returned.
|
|
2734
|
-
*/
|
|
2735
|
-
getLocale(preferUser = false) {
|
|
2736
|
-
if (this._locale) return this._locale;
|
|
2737
|
-
const locale = preferUser ? this.getUserLocale() : this.getGuildLocale();
|
|
2738
|
-
if (!locale) {
|
|
2739
|
-
return this.commandkit.config.defaultLocale;
|
|
2740
|
-
}
|
|
2741
|
-
return locale;
|
|
2742
|
-
}
|
|
2743
|
-
/**
|
|
2744
|
-
* Sets the locale for this command.
|
|
2745
|
-
* @param locale The locale to set.
|
|
2746
|
-
*/
|
|
2747
|
-
setLocale(locale) {
|
|
2748
|
-
this._locale = locale;
|
|
2749
|
-
}
|
|
2750
|
-
/**
|
|
2751
|
-
* Returns the i18n api for this command.
|
|
2752
|
-
* @param locale The locale to use for the i18n api.
|
|
2753
|
-
*/
|
|
2754
|
-
locale(locale) {
|
|
2755
|
-
const selectedLocale = locale ?? this.getLocale();
|
|
2756
|
-
return new Localization(this.commandkit, {
|
|
2757
|
-
locale: selectedLocale,
|
|
2758
|
-
target: this.getCommandIdentifier()
|
|
2759
|
-
});
|
|
2760
|
-
}
|
|
2761
|
-
/**
|
|
2762
|
-
* Creates a clone of this context
|
|
2763
|
-
*/
|
|
2764
|
-
clone(config) {
|
|
2765
|
-
if (!config) return new _Context(this.commandkit, this.config);
|
|
2766
|
-
const ctx = new _Context(this.commandkit, {
|
|
2767
|
-
...this.config,
|
|
2768
|
-
...config,
|
|
2769
|
-
store: __privateGet(this, _store)
|
|
2770
|
-
});
|
|
2771
|
-
return ctx;
|
|
2772
|
-
}
|
|
2773
|
-
isMiddleware() {
|
|
2774
|
-
return this instanceof MiddlewareContext;
|
|
2775
|
-
}
|
|
2776
|
-
args() {
|
|
2777
|
-
if (this.isMessage()) {
|
|
2778
|
-
return this.config.messageCommandParser.getArgs();
|
|
2779
|
-
}
|
|
2780
|
-
return [];
|
|
2781
|
-
}
|
|
2782
|
-
/**
|
|
2783
|
-
* Stops upcoming middleware or current command execution.
|
|
2784
|
-
* If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
|
|
2785
|
-
* If this is called inside a command itself, it will skip all post-stage middlewares.
|
|
2786
|
-
* If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
|
|
2787
|
-
*/
|
|
2788
|
-
exit() {
|
|
2789
|
-
exitMiddleware();
|
|
2790
|
-
}
|
|
2791
|
-
/**
|
|
2792
|
-
* Defers the given function to be executed after this command's execution.
|
|
2793
|
-
* @param fn The function to defer.
|
|
2794
|
-
* @returns A unique identifier for the deferred function.
|
|
2795
|
-
*/
|
|
2796
|
-
defer(fn) {
|
|
2797
|
-
return afterCommand(fn);
|
|
2798
|
-
}
|
|
2799
|
-
/**
|
|
2800
|
-
* Cancels the deferred function with the given identifier.
|
|
2801
|
-
* @param id The identifier of the deferred function.
|
|
2802
|
-
*/
|
|
2803
|
-
cancelDeferred(id) {
|
|
2804
|
-
cancelAfterCommand(id);
|
|
2805
|
-
}
|
|
2806
|
-
/**
|
|
2807
|
-
* Validates if the given function is a cached function.
|
|
2808
|
-
* @param fn The function to validate.
|
|
2809
|
-
*/
|
|
2810
|
-
isCached(fn) {
|
|
2811
|
-
return isCachedFunction(fn);
|
|
2812
|
-
}
|
|
2813
|
-
};
|
|
2814
|
-
_store = new WeakMap();
|
|
2815
|
-
__name(_Context, "Context");
|
|
2816
|
-
Context = _Context;
|
|
2817
|
-
_MiddlewareContext = class _MiddlewareContext extends Context {
|
|
2818
|
-
constructor() {
|
|
2819
|
-
super(...arguments);
|
|
2820
|
-
__privateAdd(this, _cancel, false);
|
|
3055
|
+
*/
|
|
3056
|
+
isAutocomplete() {
|
|
3057
|
+
return this.executionMode === CommandExecutionMode.Autocomplete;
|
|
2821
3058
|
}
|
|
2822
3059
|
/**
|
|
2823
|
-
* Whether the command
|
|
3060
|
+
* Whether the command was triggered by a message context menu interaction.
|
|
2824
3061
|
*/
|
|
2825
|
-
|
|
2826
|
-
return
|
|
3062
|
+
isMessageContextMenu() {
|
|
3063
|
+
return this.executionMode === CommandExecutionMode.MessageContextMenu;
|
|
2827
3064
|
}
|
|
2828
3065
|
/**
|
|
2829
|
-
*
|
|
3066
|
+
* Whether the command was triggered by a user context menu interaction.
|
|
2830
3067
|
*/
|
|
2831
|
-
|
|
2832
|
-
|
|
3068
|
+
isUserContextMenu() {
|
|
3069
|
+
return this.executionMode === CommandExecutionMode.UserContextMenu;
|
|
2833
3070
|
}
|
|
2834
3071
|
/**
|
|
2835
|
-
*
|
|
2836
|
-
* @param fn The function to set.
|
|
2837
|
-
* @example ctx.setCommandRunner(async (execute) => {
|
|
2838
|
-
* // do something before command execution
|
|
2839
|
-
* await execute();
|
|
2840
|
-
* // do something after command execution
|
|
2841
|
-
* })
|
|
3072
|
+
* Whether the command was triggered by a message.
|
|
2842
3073
|
*/
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
(_b = (_a = this.config.customArgs) == null ? void 0 : _a.setCommandRunner) == null ? void 0 : _b.call(_a, fn);
|
|
2846
|
-
}
|
|
2847
|
-
};
|
|
2848
|
-
_cancel = new WeakMap();
|
|
2849
|
-
__name(_MiddlewareContext, "MiddlewareContext");
|
|
2850
|
-
MiddlewareContext = _MiddlewareContext;
|
|
2851
|
-
}
|
|
2852
|
-
});
|
|
2853
|
-
|
|
2854
|
-
// src/utils/resolve-file-url.ts
|
|
2855
|
-
function toFileURL(filePath, withTs = false) {
|
|
2856
|
-
const resolvedPath = import_path.default.resolve(filePath);
|
|
2857
|
-
return `${"file://" + resolvedPath.replace(/\\\\|\\/g, "/")}${withTs ? `?ts=${Date.now()}` : ""}`;
|
|
2858
|
-
}
|
|
2859
|
-
var import_path;
|
|
2860
|
-
var init_resolve_file_url = __esm({
|
|
2861
|
-
"src/utils/resolve-file-url.ts"() {
|
|
2862
|
-
"use strict";
|
|
2863
|
-
init_cjs_shims();
|
|
2864
|
-
import_path = __toESM(require("path"));
|
|
2865
|
-
__name(toFileURL, "toFileURL");
|
|
2866
|
-
}
|
|
2867
|
-
});
|
|
2868
|
-
|
|
2869
|
-
// src/app/commands/MessageCommandParser.ts
|
|
2870
|
-
var import_discord8, _parsed, _options, _args, _MessageCommandParser, MessageCommandParser, _MessageCommandOptions, MessageCommandOptions;
|
|
2871
|
-
var init_MessageCommandParser = __esm({
|
|
2872
|
-
"src/app/commands/MessageCommandParser.ts"() {
|
|
2873
|
-
"use strict";
|
|
2874
|
-
init_cjs_shims();
|
|
2875
|
-
import_discord8 = require("discord.js");
|
|
2876
|
-
init_error_codes();
|
|
2877
|
-
_MessageCommandParser = class _MessageCommandParser {
|
|
2878
|
-
constructor(message, prefix, schema) {
|
|
2879
|
-
this.message = message;
|
|
2880
|
-
this.prefix = prefix;
|
|
2881
|
-
this.schema = schema;
|
|
2882
|
-
__privateAdd(this, _parsed, null);
|
|
2883
|
-
__privateAdd(this, _options, null);
|
|
2884
|
-
__privateAdd(this, _args, []);
|
|
2885
|
-
}
|
|
2886
|
-
getArgs() {
|
|
2887
|
-
void this.parse();
|
|
2888
|
-
return __privateGet(this, _args);
|
|
3074
|
+
isMessage() {
|
|
3075
|
+
return this.executionMode === CommandExecutionMode.Message;
|
|
2889
3076
|
}
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
3077
|
+
/**
|
|
3078
|
+
* Returns the command identifier.
|
|
3079
|
+
*/
|
|
3080
|
+
getCommandIdentifier() {
|
|
3081
|
+
if (this.isInteraction()) {
|
|
3082
|
+
return this.interaction.commandName;
|
|
3083
|
+
} else {
|
|
3084
|
+
return this.message.content.split(" ")[0].slice(1);
|
|
2893
3085
|
}
|
|
2894
|
-
return __privateGet(this, _options);
|
|
2895
3086
|
}
|
|
2896
|
-
|
|
3087
|
+
/**
|
|
3088
|
+
* Returns the locale of the guild where this command was triggered.
|
|
3089
|
+
*/
|
|
3090
|
+
getGuildLocale() {
|
|
2897
3091
|
var _a;
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
}
|
|
2903
|
-
getSubcommand() {
|
|
2904
|
-
return this.parse().subcommand;
|
|
2905
|
-
}
|
|
2906
|
-
getSubcommandGroup() {
|
|
2907
|
-
return this.parse().subcommandGroup;
|
|
2908
|
-
}
|
|
2909
|
-
getPrefix() {
|
|
2910
|
-
for (const p of this.prefix) {
|
|
2911
|
-
if (this.message.content.startsWith(p)) {
|
|
2912
|
-
return p;
|
|
2913
|
-
}
|
|
3092
|
+
if (this.isInteraction()) {
|
|
3093
|
+
return this.interaction.guildLocale;
|
|
3094
|
+
} else {
|
|
3095
|
+
return ((_a = this.message.guild) == null ? void 0 : _a.preferredLocale) ?? null;
|
|
2914
3096
|
}
|
|
2915
3097
|
}
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
if (
|
|
2921
|
-
return
|
|
2922
|
-
}
|
|
2923
|
-
|
|
2924
|
-
const prefix = this.getPrefix();
|
|
2925
|
-
if (!prefix) {
|
|
2926
|
-
throw createCommandKitError(CommandKitErrorCodes.InvalidCommandPrefix);
|
|
2927
|
-
}
|
|
2928
|
-
const parts = content.slice(prefix.length).trim().split(" ");
|
|
2929
|
-
const command = parts.shift();
|
|
2930
|
-
__privateSet(this, _args, parts);
|
|
2931
|
-
let subcommandGroup;
|
|
2932
|
-
let subcommand;
|
|
2933
|
-
if (command == null ? void 0 : command.includes(":")) {
|
|
2934
|
-
const [, group, cmd] = command.split(":");
|
|
2935
|
-
if (!cmd && group) {
|
|
2936
|
-
subcommand = group;
|
|
2937
|
-
} else if (cmd && group) {
|
|
2938
|
-
subcommandGroup = group;
|
|
2939
|
-
subcommand = cmd;
|
|
2940
|
-
}
|
|
3098
|
+
/**
|
|
3099
|
+
* Returns the locale of the user who triggered this command.
|
|
3100
|
+
*/
|
|
3101
|
+
getUserLocale() {
|
|
3102
|
+
if (this.isInteraction()) {
|
|
3103
|
+
return this.interaction.locale;
|
|
3104
|
+
} else {
|
|
3105
|
+
return null;
|
|
2941
3106
|
}
|
|
2942
|
-
const schema = this.schema(
|
|
2943
|
-
[command, subcommandGroup, subcommand].filter(Boolean).join(" ").trim()
|
|
2944
|
-
);
|
|
2945
|
-
const options = parts.map((part) => {
|
|
2946
|
-
try {
|
|
2947
|
-
const [name, value] = part.split(":");
|
|
2948
|
-
if (!(name in schema)) return null;
|
|
2949
|
-
switch (schema[name]) {
|
|
2950
|
-
case import_discord8.ApplicationCommandOptionType.Boolean:
|
|
2951
|
-
return { name, value: value === "true" };
|
|
2952
|
-
case import_discord8.ApplicationCommandOptionType.Integer:
|
|
2953
|
-
return { name, value: parseInt(value, 10) };
|
|
2954
|
-
case import_discord8.ApplicationCommandOptionType.Number:
|
|
2955
|
-
return { name, value: parseFloat(value) };
|
|
2956
|
-
case import_discord8.ApplicationCommandOptionType.String:
|
|
2957
|
-
return { name, value };
|
|
2958
|
-
case import_discord8.ApplicationCommandOptionType.User:
|
|
2959
|
-
return {
|
|
2960
|
-
name,
|
|
2961
|
-
value: this.message.mentions.users.find((u) => {
|
|
2962
|
-
return u.id === value.replace(/[<@!>]/g, "");
|
|
2963
|
-
})
|
|
2964
|
-
};
|
|
2965
|
-
case import_discord8.ApplicationCommandOptionType.Channel:
|
|
2966
|
-
return {
|
|
2967
|
-
name,
|
|
2968
|
-
value: this.message.mentions.channels.find((c) => {
|
|
2969
|
-
return c.id === value.replace(/[<#>]/g, "");
|
|
2970
|
-
})
|
|
2971
|
-
};
|
|
2972
|
-
case import_discord8.ApplicationCommandOptionType.Role:
|
|
2973
|
-
return {
|
|
2974
|
-
name,
|
|
2975
|
-
value: this.message.mentions.roles.find((r) => {
|
|
2976
|
-
return r.id === value.replace(/[<@&>]/g, "");
|
|
2977
|
-
})
|
|
2978
|
-
};
|
|
2979
|
-
case import_discord8.ApplicationCommandOptionType.Attachment:
|
|
2980
|
-
return {
|
|
2981
|
-
name,
|
|
2982
|
-
value: this.message.attachments.find((a) => {
|
|
2983
|
-
return a.name === value;
|
|
2984
|
-
})
|
|
2985
|
-
};
|
|
2986
|
-
default:
|
|
2987
|
-
return null;
|
|
2988
|
-
}
|
|
2989
|
-
} catch {
|
|
2990
|
-
return null;
|
|
2991
|
-
}
|
|
2992
|
-
}).filter((v) => v !== null);
|
|
2993
|
-
__privateSet(this, _parsed, {
|
|
2994
|
-
command,
|
|
2995
|
-
options,
|
|
2996
|
-
subcommand,
|
|
2997
|
-
subcommandGroup
|
|
2998
|
-
});
|
|
2999
|
-
return __privateGet(this, _parsed);
|
|
3000
|
-
}
|
|
3001
|
-
};
|
|
3002
|
-
_parsed = new WeakMap();
|
|
3003
|
-
_options = new WeakMap();
|
|
3004
|
-
_args = new WeakMap();
|
|
3005
|
-
__name(_MessageCommandParser, "MessageCommandParser");
|
|
3006
|
-
MessageCommandParser = _MessageCommandParser;
|
|
3007
|
-
_MessageCommandOptions = class _MessageCommandOptions {
|
|
3008
|
-
constructor(parser2) {
|
|
3009
|
-
this.parser = parser2;
|
|
3010
3107
|
}
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3108
|
+
/**
|
|
3109
|
+
* Returns the locale for this command.
|
|
3110
|
+
* @param preferUser Whether to prefer the user's locale over the guild's locale.
|
|
3111
|
+
* @returns The locale for this command. If no locale is found, the default locale is returned.
|
|
3112
|
+
*/
|
|
3113
|
+
getLocale(preferUser = false) {
|
|
3114
|
+
if (this._locale) return this._locale;
|
|
3115
|
+
const locale = preferUser ? this.getUserLocale() : this.getGuildLocale();
|
|
3116
|
+
if (!locale) {
|
|
3117
|
+
return this.commandkit.config.defaultLocale;
|
|
3015
3118
|
}
|
|
3016
|
-
return
|
|
3119
|
+
return locale;
|
|
3017
3120
|
}
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
}
|
|
3025
|
-
return member ?? null;
|
|
3121
|
+
/**
|
|
3122
|
+
* Sets the locale for this command.
|
|
3123
|
+
* @param locale The locale to set.
|
|
3124
|
+
*/
|
|
3125
|
+
setLocale(locale) {
|
|
3126
|
+
this._locale = locale;
|
|
3026
3127
|
}
|
|
3027
|
-
|
|
3028
|
-
|
|
3128
|
+
/**
|
|
3129
|
+
* Returns the i18n api for this command.
|
|
3130
|
+
* @param locale The locale to use for the i18n api.
|
|
3131
|
+
*/
|
|
3132
|
+
locale(locale) {
|
|
3133
|
+
const selectedLocale = locale ?? this.getLocale();
|
|
3134
|
+
return new Localization(this.commandkit, {
|
|
3135
|
+
locale: selectedLocale,
|
|
3136
|
+
target: this.getCommandIdentifier()
|
|
3137
|
+
});
|
|
3138
|
+
}
|
|
3139
|
+
/**
|
|
3140
|
+
* Creates a clone of this context
|
|
3141
|
+
*/
|
|
3142
|
+
clone(config) {
|
|
3143
|
+
if (!config) return new _Context(this.commandkit, this.config);
|
|
3144
|
+
const ctx = new _Context(this.commandkit, {
|
|
3145
|
+
...this.config,
|
|
3146
|
+
...config,
|
|
3147
|
+
store: __privateGet(this, _store)
|
|
3148
|
+
});
|
|
3149
|
+
return ctx;
|
|
3029
3150
|
}
|
|
3030
|
-
|
|
3031
|
-
return this
|
|
3151
|
+
isMiddleware() {
|
|
3152
|
+
return this instanceof MiddlewareContext;
|
|
3032
3153
|
}
|
|
3033
|
-
|
|
3034
|
-
|
|
3154
|
+
args() {
|
|
3155
|
+
if (this.isMessage()) {
|
|
3156
|
+
return this.config.messageCommandParser.getArgs();
|
|
3157
|
+
}
|
|
3158
|
+
return [];
|
|
3035
3159
|
}
|
|
3036
|
-
|
|
3037
|
-
|
|
3160
|
+
/**
|
|
3161
|
+
* Stops upcoming middleware or current command execution.
|
|
3162
|
+
* If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
|
|
3163
|
+
* If this is called inside a command itself, it will skip all post-stage middlewares.
|
|
3164
|
+
* If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
|
|
3165
|
+
*/
|
|
3166
|
+
exit() {
|
|
3167
|
+
exitMiddleware();
|
|
3038
3168
|
}
|
|
3039
|
-
|
|
3040
|
-
|
|
3169
|
+
/**
|
|
3170
|
+
* Defers the given function to be executed after this command's execution.
|
|
3171
|
+
* @param fn The function to defer.
|
|
3172
|
+
* @returns A unique identifier for the deferred function.
|
|
3173
|
+
*/
|
|
3174
|
+
defer(fn) {
|
|
3175
|
+
return afterCommand(fn);
|
|
3041
3176
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
3177
|
+
/**
|
|
3178
|
+
* Cancels the deferred function with the given identifier.
|
|
3179
|
+
* @param id The identifier of the deferred function.
|
|
3180
|
+
*/
|
|
3181
|
+
cancelDeferred(id) {
|
|
3182
|
+
cancelAfterCommand(id);
|
|
3044
3183
|
}
|
|
3045
|
-
|
|
3046
|
-
|
|
3184
|
+
/**
|
|
3185
|
+
* Validates if the given function is a cached function.
|
|
3186
|
+
* @param fn The function to validate.
|
|
3187
|
+
*/
|
|
3188
|
+
isCached(fn) {
|
|
3189
|
+
return isCachedFunction(fn);
|
|
3047
3190
|
}
|
|
3048
|
-
|
|
3049
|
-
|
|
3191
|
+
};
|
|
3192
|
+
_store = new WeakMap();
|
|
3193
|
+
__name(_Context, "Context");
|
|
3194
|
+
Context = _Context;
|
|
3195
|
+
_MiddlewareContext = class _MiddlewareContext extends Context {
|
|
3196
|
+
constructor() {
|
|
3197
|
+
super(...arguments);
|
|
3198
|
+
__privateAdd(this, _cancel, false);
|
|
3050
3199
|
}
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
if (required) {
|
|
3057
|
-
throw new Error(`Mentionable "${name}" is required.`);
|
|
3058
|
-
}
|
|
3059
|
-
return null;
|
|
3200
|
+
/**
|
|
3201
|
+
* Whether the command execution was cancelled.
|
|
3202
|
+
*/
|
|
3203
|
+
get cancelled() {
|
|
3204
|
+
return __privateGet(this, _cancel);
|
|
3060
3205
|
}
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
return sub ?? null;
|
|
3206
|
+
/**
|
|
3207
|
+
* Cancels the command execution.
|
|
3208
|
+
*/
|
|
3209
|
+
cancel() {
|
|
3210
|
+
__privateSet(this, _cancel, true);
|
|
3067
3211
|
}
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3212
|
+
/**
|
|
3213
|
+
* Sets command runner function to wrap the command execution.
|
|
3214
|
+
* @param fn The function to set.
|
|
3215
|
+
* @example ctx.setCommandRunner(async (execute) => {
|
|
3216
|
+
* // do something before command execution
|
|
3217
|
+
* await execute();
|
|
3218
|
+
* // do something after command execution
|
|
3219
|
+
* })
|
|
3220
|
+
*/
|
|
3221
|
+
setCommandRunner(fn) {
|
|
3222
|
+
var _a, _b;
|
|
3223
|
+
(_b = (_a = this.config.customArgs) == null ? void 0 : _a.setCommandRunner) == null ? void 0 : _b.call(_a, fn);
|
|
3074
3224
|
}
|
|
3075
3225
|
};
|
|
3076
|
-
|
|
3077
|
-
|
|
3226
|
+
_cancel = new WeakMap();
|
|
3227
|
+
__name(_MiddlewareContext, "MiddlewareContext");
|
|
3228
|
+
MiddlewareContext = _MiddlewareContext;
|
|
3078
3229
|
}
|
|
3079
3230
|
});
|
|
3080
3231
|
|
|
3081
|
-
// src/app/
|
|
3082
|
-
var
|
|
3083
|
-
var
|
|
3084
|
-
"src/app/
|
|
3232
|
+
// src/app/commands/AppCommandRunner.ts
|
|
3233
|
+
var import_discord10, _AppCommandRunner_instances, finalizer_fn, _AppCommandRunner, AppCommandRunner;
|
|
3234
|
+
var init_AppCommandRunner = __esm({
|
|
3235
|
+
"src/app/commands/AppCommandRunner.ts"() {
|
|
3085
3236
|
"use strict";
|
|
3086
3237
|
init_cjs_shims();
|
|
3087
|
-
|
|
3238
|
+
import_discord10 = require("discord.js");
|
|
3239
|
+
init_environment();
|
|
3088
3240
|
init_Logger();
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
this.commandkit = commandkit;
|
|
3096
|
-
this.api.setToken(
|
|
3097
|
-
this.commandkit.client.token ?? process.env.DISCORD_TOKEN ?? process.env.TOKEN ?? ""
|
|
3098
|
-
);
|
|
3099
|
-
}
|
|
3100
|
-
api = new import_discord9.REST();
|
|
3101
|
-
/**
|
|
3102
|
-
* Gets the commands data.
|
|
3103
|
-
*/
|
|
3104
|
-
getCommandsData() {
|
|
3105
|
-
const handler = this.commandkit.commandHandler;
|
|
3106
|
-
const commands = handler.getCommandsArray();
|
|
3107
|
-
return commands.flatMap((cmd) => {
|
|
3108
|
-
var _a;
|
|
3109
|
-
const json = "toJSON" in cmd.data.command ? cmd.data.command.toJSON() : cmd.data.command;
|
|
3110
|
-
if (((_a = cmd.command.subcommands) == null ? void 0 : _a.length) > 0 && (!json.type || json.type === import_discord9.ApplicationCommandType.ChatInput)) {
|
|
3111
|
-
this.processSubcommands(json, cmd.command.subcommands);
|
|
3112
|
-
}
|
|
3113
|
-
const collections = [json];
|
|
3114
|
-
if (cmd.data.userContextMenu && json.type !== import_discord9.ApplicationCommandType.User) {
|
|
3115
|
-
collections.push({
|
|
3116
|
-
...json,
|
|
3117
|
-
type: import_discord9.ApplicationCommandType.User,
|
|
3118
|
-
options: void 0,
|
|
3119
|
-
description_localizations: void 0,
|
|
3120
|
-
// @ts-ignore
|
|
3121
|
-
description: void 0
|
|
3122
|
-
});
|
|
3123
|
-
}
|
|
3124
|
-
if (cmd.data.messageContextMenu && json.type !== import_discord9.ApplicationCommandType.Message) {
|
|
3125
|
-
collections.push({
|
|
3126
|
-
...json,
|
|
3127
|
-
type: import_discord9.ApplicationCommandType.Message,
|
|
3128
|
-
description_localizations: void 0,
|
|
3129
|
-
// @ts-ignore
|
|
3130
|
-
description: void 0,
|
|
3131
|
-
options: void 0
|
|
3132
|
-
});
|
|
3133
|
-
}
|
|
3134
|
-
return collections;
|
|
3135
|
-
});
|
|
3241
|
+
init_Context();
|
|
3242
|
+
init_async_context();
|
|
3243
|
+
_AppCommandRunner = class _AppCommandRunner {
|
|
3244
|
+
constructor(handler) {
|
|
3245
|
+
this.handler = handler;
|
|
3246
|
+
__privateAdd(this, _AppCommandRunner_instances);
|
|
3136
3247
|
}
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
processSubcommands(commandData, subcommands) {
|
|
3141
|
-
var _a, _b, _c;
|
|
3142
|
-
if (!commandData.options) {
|
|
3143
|
-
commandData.options = [];
|
|
3248
|
+
async runCommand(prepared, source) {
|
|
3249
|
+
if (source instanceof import_discord10.Message && (source.editedTimestamp || source.partial)) {
|
|
3250
|
+
return;
|
|
3144
3251
|
}
|
|
3145
|
-
const
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3252
|
+
const { commandkit: commandkit2 } = this.handler;
|
|
3253
|
+
const executionMode = this.getExecutionMode(source);
|
|
3254
|
+
let runCommand = null;
|
|
3255
|
+
const env = new CommandKitEnvironment(commandkit2);
|
|
3256
|
+
env.setType("COMMAND_HANDLER" /* CommandHandler */);
|
|
3257
|
+
env.variables.set("commandHandlerType", "app");
|
|
3258
|
+
env.variables.set("currentCommandName", prepared.command.command.name);
|
|
3259
|
+
env.variables.set("execHandlerKind", executionMode);
|
|
3260
|
+
const ctx = new MiddlewareContext(commandkit2, {
|
|
3261
|
+
environment: env,
|
|
3262
|
+
executionMode,
|
|
3263
|
+
interaction: !(source instanceof import_discord10.Message) ? source : null,
|
|
3264
|
+
message: source instanceof import_discord10.Message ? source : null,
|
|
3265
|
+
forwarded: false,
|
|
3266
|
+
customArgs: {
|
|
3267
|
+
setCommandRunner: /* @__PURE__ */ __name((fn2) => {
|
|
3268
|
+
runCommand = fn2;
|
|
3269
|
+
}, "setCommandRunner")
|
|
3150
3270
|
}
|
|
3151
|
-
|
|
3271
|
+
});
|
|
3272
|
+
for (const middleware of prepared.middlewares) {
|
|
3273
|
+
await middleware.data.beforeExecute(ctx);
|
|
3152
3274
|
}
|
|
3153
|
-
const
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3275
|
+
const targetData = prepared.command.data;
|
|
3276
|
+
const fn = targetData[executionMode];
|
|
3277
|
+
if (!fn) {
|
|
3278
|
+
Logger.warn(
|
|
3279
|
+
`Command ${prepared.command.command.name} has no handler for ${executionMode}`
|
|
3158
3280
|
);
|
|
3159
|
-
if (subcommandData) {
|
|
3160
|
-
const subcommandOption = {
|
|
3161
|
-
type: import_discord9.ApplicationCommandOptionType.Subcommand,
|
|
3162
|
-
name: subcommand.name,
|
|
3163
|
-
description: subcommandData.description || "No description provided",
|
|
3164
|
-
options: subcommandData.options || [],
|
|
3165
|
-
name_localizations: subcommandData.name_localizations,
|
|
3166
|
-
description_localizations: subcommandData.description_localizations
|
|
3167
|
-
};
|
|
3168
|
-
commandData.options.push(subcommandOption);
|
|
3169
|
-
}
|
|
3170
3281
|
}
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3282
|
+
if (fn) {
|
|
3283
|
+
try {
|
|
3284
|
+
const _executeCommand = makeContextAwareFunction(
|
|
3285
|
+
env,
|
|
3286
|
+
async () => {
|
|
3287
|
+
afterCommand((env2) => {
|
|
3288
|
+
const error = env2.getExecutionError();
|
|
3289
|
+
const marker = env2.getMarker();
|
|
3290
|
+
const time = `${env2.getExecutionTime().toFixed(2)}ms`;
|
|
3291
|
+
if (error) {
|
|
3292
|
+
Logger.error(
|
|
3293
|
+
`[${marker} - ${time}] Error executing command: ${error.stack || error}`
|
|
3294
|
+
);
|
|
3295
|
+
return;
|
|
3296
|
+
}
|
|
3297
|
+
Logger.info(
|
|
3298
|
+
`[${marker} - ${time}] Command executed successfully`
|
|
3299
|
+
);
|
|
3300
|
+
});
|
|
3301
|
+
return fn(ctx.clone());
|
|
3302
|
+
},
|
|
3303
|
+
__privateMethod(this, _AppCommandRunner_instances, finalizer_fn).bind(this)
|
|
3183
3304
|
);
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
description_localizations: subcommandData.description_localizations
|
|
3192
|
-
});
|
|
3193
|
-
}
|
|
3194
|
-
}
|
|
3195
|
-
if ((((_c = subcommandGroupOption.options) == null ? void 0 : _c.length) || 0) > 0) {
|
|
3196
|
-
commandData.options.push(subcommandGroupOption);
|
|
3197
|
-
}
|
|
3198
|
-
}
|
|
3199
|
-
}
|
|
3200
|
-
/**
|
|
3201
|
-
* Registers loaded commands.
|
|
3202
|
-
*/
|
|
3203
|
-
async register() {
|
|
3204
|
-
if (!this.commandkit.client.isReady()) {
|
|
3205
|
-
throw new Error("Cannot register commands before the client is ready");
|
|
3206
|
-
}
|
|
3207
|
-
const commands = this.getCommandsData();
|
|
3208
|
-
const guildCommands = commands.filter((command) => {
|
|
3209
|
-
var _a;
|
|
3210
|
-
return (_a = command.guilds) == null ? void 0 : _a.filter(Boolean).length;
|
|
3211
|
-
}).map((c) => {
|
|
3212
|
-
var _a;
|
|
3213
|
-
return {
|
|
3214
|
-
...c,
|
|
3215
|
-
guilds: Array.from(new Set((_a = c.guilds) == null ? void 0 : _a.filter(Boolean)))
|
|
3216
|
-
};
|
|
3217
|
-
});
|
|
3218
|
-
const globalCommands = commands.filter(
|
|
3219
|
-
(command) => {
|
|
3220
|
-
var _a;
|
|
3221
|
-
return !((_a = command.guilds) == null ? void 0 : _a.filter(Boolean).length);
|
|
3222
|
-
}
|
|
3223
|
-
);
|
|
3224
|
-
await this.updateGlobalCommands(globalCommands);
|
|
3225
|
-
await this.updateGuildCommands(guildCommands);
|
|
3226
|
-
}
|
|
3227
|
-
/**
|
|
3228
|
-
* Updates the global commands.
|
|
3229
|
-
*/
|
|
3230
|
-
async updateGlobalCommands(commands) {
|
|
3231
|
-
if (!commands.length) return;
|
|
3232
|
-
try {
|
|
3233
|
-
const data = await this.api.put(
|
|
3234
|
-
import_discord9.Routes.applicationCommands(this.commandkit.client.user.id),
|
|
3235
|
-
{
|
|
3236
|
-
body: commands.map((c) => ({
|
|
3237
|
-
...c,
|
|
3238
|
-
guilds: void 0
|
|
3239
|
-
}))
|
|
3305
|
+
const executeCommand = runCommand != null ? runCommand(_executeCommand) : _executeCommand;
|
|
3306
|
+
env.markStart(prepared.command.command.name);
|
|
3307
|
+
const res = await commandkit2.plugins.execute(async (ctx2, plugin) => {
|
|
3308
|
+
return plugin.executeCommand(ctx2, source, prepared, executeCommand);
|
|
3309
|
+
});
|
|
3310
|
+
if (!res) {
|
|
3311
|
+
await executeCommand();
|
|
3240
3312
|
}
|
|
3241
|
-
)
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
);
|
|
3245
|
-
} catch (e) {
|
|
3246
|
-
Logger.error("Failed to update global application (/) commands", e);
|
|
3313
|
+
} catch (e) {
|
|
3314
|
+
Logger.error(e);
|
|
3315
|
+
}
|
|
3247
3316
|
}
|
|
3248
|
-
}
|
|
3249
|
-
/**
|
|
3250
|
-
* Updates the guild commands.
|
|
3251
|
-
*/
|
|
3252
|
-
async updateGuildCommands(commands) {
|
|
3253
3317
|
try {
|
|
3254
|
-
const
|
|
3255
|
-
|
|
3256
|
-
var _a;
|
|
3257
|
-
if (!((_a = command.guilds) == null ? void 0 : _a.length)) return;
|
|
3258
|
-
command.guilds.forEach((guild) => {
|
|
3259
|
-
if (!guildCommandsMap.has(guild)) {
|
|
3260
|
-
guildCommandsMap.set(guild, []);
|
|
3261
|
-
}
|
|
3262
|
-
guildCommandsMap.get(guild).push(command);
|
|
3263
|
-
});
|
|
3264
|
-
});
|
|
3265
|
-
if (!guildCommandsMap.size) return;
|
|
3266
|
-
let count = 0;
|
|
3267
|
-
for (const [guild, guildCommands] of guildCommandsMap) {
|
|
3268
|
-
const data = await this.api.put(
|
|
3269
|
-
import_discord9.Routes.applicationGuildCommands(
|
|
3270
|
-
this.commandkit.client.user.id,
|
|
3271
|
-
guild
|
|
3272
|
-
),
|
|
3273
|
-
{
|
|
3274
|
-
body: guildCommands.map((b) => ({
|
|
3275
|
-
...b,
|
|
3276
|
-
guilds: void 0
|
|
3277
|
-
}))
|
|
3278
|
-
}
|
|
3279
|
-
);
|
|
3280
|
-
count += data.length;
|
|
3318
|
+
for (const middleware of prepared.middlewares) {
|
|
3319
|
+
await middleware.data.afterExecute(ctx);
|
|
3281
3320
|
}
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3321
|
+
} finally {
|
|
3322
|
+
env.markEnd();
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
getExecutionMode(source) {
|
|
3326
|
+
if (source instanceof import_discord10.Message) return CommandExecutionMode.Message;
|
|
3327
|
+
if (source.isChatInputCommand()) return CommandExecutionMode.SlashCommand;
|
|
3328
|
+
if (source.isAutocomplete()) {
|
|
3329
|
+
return CommandExecutionMode.Autocomplete;
|
|
3285
3330
|
}
|
|
3331
|
+
if (source.isMessageContextMenuCommand()) {
|
|
3332
|
+
return CommandExecutionMode.MessageContextMenu;
|
|
3333
|
+
}
|
|
3334
|
+
if (source.isUserContextMenuCommand()) {
|
|
3335
|
+
return CommandExecutionMode.UserContextMenu;
|
|
3336
|
+
}
|
|
3337
|
+
return null;
|
|
3286
3338
|
}
|
|
3287
3339
|
};
|
|
3288
|
-
|
|
3289
|
-
|
|
3340
|
+
_AppCommandRunner_instances = new WeakSet();
|
|
3341
|
+
finalizer_fn = /* @__PURE__ */ __name(async function() {
|
|
3342
|
+
const env = useEnvironment();
|
|
3343
|
+
await env.runDeferredFunctions();
|
|
3344
|
+
env.clearAllDeferredFunctions();
|
|
3345
|
+
}, "#finalizer");
|
|
3346
|
+
__name(_AppCommandRunner, "AppCommandRunner");
|
|
3347
|
+
AppCommandRunner = _AppCommandRunner;
|
|
3290
3348
|
}
|
|
3291
3349
|
});
|
|
3292
3350
|
|
|
3293
3351
|
// src/app/handlers/AppCommandHandler.ts
|
|
3294
|
-
var
|
|
3352
|
+
var import_discord11, commandDataSchema, middlewareDataSchema, _AppCommandHandler, AppCommandHandler;
|
|
3295
3353
|
var init_AppCommandHandler = __esm({
|
|
3296
3354
|
"src/app/handlers/AppCommandHandler.ts"() {
|
|
3297
3355
|
"use strict";
|
|
3298
3356
|
init_cjs_shims();
|
|
3299
|
-
|
|
3300
|
-
init_Context();
|
|
3357
|
+
import_discord11 = require("discord.js");
|
|
3301
3358
|
init_resolve_file_url();
|
|
3302
3359
|
init_MessageCommandParser();
|
|
3303
3360
|
init_error_codes();
|
|
3304
3361
|
init_CommandRegistrar();
|
|
3305
|
-
init_async_context();
|
|
3306
3362
|
init_Logger();
|
|
3307
|
-
|
|
3363
|
+
init_AppCommandRunner();
|
|
3308
3364
|
commandDataSchema = {
|
|
3309
|
-
command: /* @__PURE__ */ __name((c) => c instanceof
|
|
3365
|
+
command: /* @__PURE__ */ __name((c) => c instanceof import_discord11.SlashCommandBuilder || c instanceof import_discord11.ContextMenuCommandBuilder || c && typeof c === "object", "command"),
|
|
3310
3366
|
chatInput: /* @__PURE__ */ __name((c) => typeof c === "function", "chatInput"),
|
|
3311
3367
|
autocomplete: /* @__PURE__ */ __name((c) => typeof c === "function", "autocomplete"),
|
|
3312
3368
|
message: /* @__PURE__ */ __name((c) => typeof c === "function", "message"),
|
|
@@ -3318,35 +3374,23 @@ var init_AppCommandHandler = __esm({
|
|
|
3318
3374
|
afterExecute: /* @__PURE__ */ __name((c) => typeof c === "function", "afterExecute")
|
|
3319
3375
|
};
|
|
3320
3376
|
_AppCommandHandler = class _AppCommandHandler {
|
|
3321
|
-
constructor(
|
|
3322
|
-
this.commandkit =
|
|
3323
|
-
__privateAdd(this, _AppCommandHandler_instances);
|
|
3324
|
-
__publicField(this, "loadedCommands", new import_discord10.Collection());
|
|
3325
|
-
__publicField(this, "loadedSubCommands", new import_discord10.Collection());
|
|
3326
|
-
__publicField(this, "loadedMiddlewares", new import_discord10.Collection());
|
|
3327
|
-
// Name-to-ID mapping for easier lookup
|
|
3328
|
-
__publicField(this, "commandNameToId", /* @__PURE__ */ new Map());
|
|
3329
|
-
__publicField(this, "subcommandPathToId", /* @__PURE__ */ new Map());
|
|
3330
|
-
__publicField(this, "registrar");
|
|
3331
|
-
__publicField(this, "onInteraction", null);
|
|
3332
|
-
__publicField(this, "onMessageCreate", null);
|
|
3333
|
-
__publicField(this, "onMessageUpdate", null);
|
|
3377
|
+
constructor(commandkit2) {
|
|
3378
|
+
this.commandkit = commandkit2;
|
|
3334
3379
|
this.registrar = new CommandRegistrar(this.commandkit);
|
|
3335
3380
|
}
|
|
3381
|
+
loadedCommands = new import_discord11.Collection();
|
|
3382
|
+
loadedMiddlewares = new import_discord11.Collection();
|
|
3383
|
+
// Name-to-ID mapping for easier lookup
|
|
3384
|
+
commandNameToId = /* @__PURE__ */ new Map();
|
|
3385
|
+
subcommandPathToId = /* @__PURE__ */ new Map();
|
|
3386
|
+
registrar;
|
|
3387
|
+
onInteraction = null;
|
|
3388
|
+
onMessageCreate = null;
|
|
3389
|
+
onMessageUpdate = null;
|
|
3390
|
+
commandRunner = new AppCommandRunner(this);
|
|
3336
3391
|
getCommandsArray() {
|
|
3337
3392
|
return Array.from(this.loadedCommands.values());
|
|
3338
3393
|
}
|
|
3339
|
-
/**
|
|
3340
|
-
* Get subcommand data by command ID and subcommand name
|
|
3341
|
-
*/
|
|
3342
|
-
getSubcommandData(commandId, subcommandName) {
|
|
3343
|
-
const subcommand = Array.from(this.loadedSubCommands.values()).find(
|
|
3344
|
-
(sub) => sub.subcommand.command === commandId && sub.subcommand.name === subcommandName
|
|
3345
|
-
);
|
|
3346
|
-
if (!subcommand) return null;
|
|
3347
|
-
const commandData = subcommand.data.command;
|
|
3348
|
-
return "toJSON" in commandData ? commandData.toJSON() : commandData;
|
|
3349
|
-
}
|
|
3350
3394
|
registerCommandHandler() {
|
|
3351
3395
|
this.onInteraction ??= async (interaction) => {
|
|
3352
3396
|
const success = await this.commandkit.plugins.execute(
|
|
@@ -3359,7 +3403,7 @@ var init_AppCommandHandler = __esm({
|
|
|
3359
3403
|
if (!isCommandLike) return;
|
|
3360
3404
|
const prepared = await this.prepareCommandRun(interaction);
|
|
3361
3405
|
if (!prepared) return;
|
|
3362
|
-
return this.runCommand(prepared, interaction);
|
|
3406
|
+
return this.commandRunner.runCommand(prepared, interaction);
|
|
3363
3407
|
};
|
|
3364
3408
|
this.onMessageCreate ??= async (message) => {
|
|
3365
3409
|
const success = await this.commandkit.plugins.execute(
|
|
@@ -3371,7 +3415,7 @@ var init_AppCommandHandler = __esm({
|
|
|
3371
3415
|
if (message.author.bot) return;
|
|
3372
3416
|
const prepared = await this.prepareCommandRun(message);
|
|
3373
3417
|
if (!prepared) return;
|
|
3374
|
-
return this.runCommand(prepared, message);
|
|
3418
|
+
return this.commandRunner.runCommand(prepared, message);
|
|
3375
3419
|
};
|
|
3376
3420
|
this.onMessageUpdate ??= async (oldMessage, newMessage) => {
|
|
3377
3421
|
const success = await this.commandkit.plugins.execute(
|
|
@@ -3388,107 +3432,17 @@ var init_AppCommandHandler = __esm({
|
|
|
3388
3432
|
if (oldMessage.author.bot) return;
|
|
3389
3433
|
const prepared = await this.prepareCommandRun(newMessage);
|
|
3390
3434
|
if (!prepared) return;
|
|
3391
|
-
return this.runCommand(prepared, newMessage);
|
|
3435
|
+
return this.commandRunner.runCommand(prepared, newMessage);
|
|
3392
3436
|
};
|
|
3393
|
-
this.commandkit.client.on(
|
|
3394
|
-
this.commandkit.client.on(
|
|
3395
|
-
this.commandkit.client.on(
|
|
3396
|
-
}
|
|
3397
|
-
getExecutionMode(source) {
|
|
3398
|
-
if (source instanceof import_discord10.Message) return CommandExecutionMode.Message;
|
|
3399
|
-
if (source.isChatInputCommand()) return CommandExecutionMode.SlashCommand;
|
|
3400
|
-
if (source.isAutocomplete()) {
|
|
3401
|
-
return CommandExecutionMode.Autocomplete;
|
|
3402
|
-
}
|
|
3403
|
-
if (source.isMessageContextMenuCommand()) {
|
|
3404
|
-
return CommandExecutionMode.MessageContextMenu;
|
|
3405
|
-
}
|
|
3406
|
-
if (source.isUserContextMenuCommand()) {
|
|
3407
|
-
return CommandExecutionMode.UserContextMenu;
|
|
3408
|
-
}
|
|
3409
|
-
return null;
|
|
3410
|
-
}
|
|
3411
|
-
async runCommand(prepared, source) {
|
|
3412
|
-
if (source instanceof import_discord10.Message && (source.editedTimestamp || source.partial)) {
|
|
3413
|
-
return;
|
|
3414
|
-
}
|
|
3415
|
-
const executionMode = this.getExecutionMode(source);
|
|
3416
|
-
let runCommand = null;
|
|
3417
|
-
const env = new CommandKitEnvironment(this.commandkit);
|
|
3418
|
-
env.setType("COMMAND_HANDLER" /* CommandHandler */);
|
|
3419
|
-
env.variables.set("commandHandlerType", "app");
|
|
3420
|
-
env.variables.set("currentCommandName", prepared.command.command.name);
|
|
3421
|
-
env.variables.set("execHandlerKind", executionMode);
|
|
3422
|
-
const ctx = new MiddlewareContext(this.commandkit, {
|
|
3423
|
-
environment: env,
|
|
3424
|
-
executionMode,
|
|
3425
|
-
interaction: !(source instanceof import_discord10.Message) ? source : null,
|
|
3426
|
-
message: source instanceof import_discord10.Message ? source : null,
|
|
3427
|
-
forwarded: false,
|
|
3428
|
-
customArgs: {
|
|
3429
|
-
setCommandRunner: /* @__PURE__ */ __name((fn2) => {
|
|
3430
|
-
runCommand = fn2;
|
|
3431
|
-
}, "setCommandRunner")
|
|
3432
|
-
}
|
|
3433
|
-
});
|
|
3434
|
-
for (const middleware of prepared.middlewares) {
|
|
3435
|
-
await middleware.data.beforeExecute(ctx);
|
|
3436
|
-
}
|
|
3437
|
-
const targetData = prepared.subcommand ? prepared.subcommand.data : prepared.command.data;
|
|
3438
|
-
const fn = targetData[executionMode];
|
|
3439
|
-
if (!fn) {
|
|
3440
|
-
Logger.warn(
|
|
3441
|
-
`Command ${prepared.command.command.name}${prepared.subcommand ? "/" + prepared.subcommand.subcommand.name : ""} has no handler for ${executionMode}`
|
|
3442
|
-
);
|
|
3443
|
-
}
|
|
3444
|
-
if (fn) {
|
|
3445
|
-
try {
|
|
3446
|
-
const _executeCommand = makeContextAwareFunction(
|
|
3447
|
-
env,
|
|
3448
|
-
async () => fn(ctx.clone()),
|
|
3449
|
-
__privateMethod(this, _AppCommandHandler_instances, finalizer_fn).bind(this)
|
|
3450
|
-
);
|
|
3451
|
-
const executeCommand = runCommand != null ? runCommand(_executeCommand) : _executeCommand;
|
|
3452
|
-
afterCommand((env2) => {
|
|
3453
|
-
const error = env2.getExecutionError();
|
|
3454
|
-
const marker = env2.getMarker();
|
|
3455
|
-
const time = `${env2.getExecutionTime().toFixed(2)}ms`;
|
|
3456
|
-
if (error) {
|
|
3457
|
-
Logger.error(
|
|
3458
|
-
`[${marker} - ${time}] Error executing command: ${error.stack || error}`
|
|
3459
|
-
);
|
|
3460
|
-
return;
|
|
3461
|
-
}
|
|
3462
|
-
Logger.info(`[${marker} - ${time}] Command executed successfully`);
|
|
3463
|
-
});
|
|
3464
|
-
env.markStart(prepared.command.command.name);
|
|
3465
|
-
const res = await this.commandkit.plugins.execute(
|
|
3466
|
-
async (ctx2, plugin) => {
|
|
3467
|
-
return plugin.executeCommand(ctx2, source, prepared, executeCommand);
|
|
3468
|
-
}
|
|
3469
|
-
);
|
|
3470
|
-
if (!res) {
|
|
3471
|
-
await executeCommand();
|
|
3472
|
-
}
|
|
3473
|
-
} catch (e) {
|
|
3474
|
-
Logger.error(e);
|
|
3475
|
-
}
|
|
3476
|
-
}
|
|
3477
|
-
try {
|
|
3478
|
-
for (const middleware of prepared.middlewares) {
|
|
3479
|
-
await middleware.data.afterExecute(ctx);
|
|
3480
|
-
}
|
|
3481
|
-
} finally {
|
|
3482
|
-
env.markEnd();
|
|
3483
|
-
}
|
|
3437
|
+
this.commandkit.client.on(import_discord11.Events.InteractionCreate, this.onInteraction);
|
|
3438
|
+
this.commandkit.client.on(import_discord11.Events.MessageCreate, this.onMessageCreate);
|
|
3439
|
+
this.commandkit.client.on(import_discord11.Events.MessageUpdate, this.onMessageUpdate);
|
|
3484
3440
|
}
|
|
3485
3441
|
async prepareCommandRun(source) {
|
|
3486
3442
|
var _a;
|
|
3487
3443
|
let cmdName;
|
|
3488
|
-
let subcommandGroupName = null;
|
|
3489
|
-
let subcommandName = null;
|
|
3490
3444
|
let parser2;
|
|
3491
|
-
if (source instanceof
|
|
3445
|
+
if (source instanceof import_discord11.Message) {
|
|
3492
3446
|
if (source.author.bot) return null;
|
|
3493
3447
|
const prefix = await this.commandkit.config.getMessageCommandPrefix(source);
|
|
3494
3448
|
parser2 = new MessageCommandParser(
|
|
@@ -3517,14 +3471,6 @@ var init_AppCommandHandler = __esm({
|
|
|
3517
3471
|
const fullCommand = parser2.getFullCommand();
|
|
3518
3472
|
const parts = fullCommand.split(" ");
|
|
3519
3473
|
cmdName = parts[0];
|
|
3520
|
-
if (parts.length > 1) {
|
|
3521
|
-
if (parts.length === 3) {
|
|
3522
|
-
subcommandGroupName = parts[1];
|
|
3523
|
-
subcommandName = parts[2];
|
|
3524
|
-
} else {
|
|
3525
|
-
subcommandName = parts[1];
|
|
3526
|
-
}
|
|
3527
|
-
}
|
|
3528
3474
|
} catch (e) {
|
|
3529
3475
|
if (isErrorType(e, CommandKitErrorCodes.InvalidCommandPrefix)) {
|
|
3530
3476
|
return null;
|
|
@@ -3535,31 +3481,16 @@ var init_AppCommandHandler = __esm({
|
|
|
3535
3481
|
} else {
|
|
3536
3482
|
if (!source.isCommand()) return null;
|
|
3537
3483
|
cmdName = source.commandName;
|
|
3538
|
-
if (source.isChatInputCommand()) {
|
|
3539
|
-
subcommandGroupName = source.options.getSubcommandGroup(false);
|
|
3540
|
-
subcommandName = source.options.getSubcommand(false);
|
|
3541
|
-
}
|
|
3542
3484
|
}
|
|
3543
3485
|
const commandId = this.commandNameToId.get(cmdName);
|
|
3544
3486
|
if (!commandId) return null;
|
|
3545
3487
|
const loadedCommand = this.loadedCommands.get(commandId);
|
|
3546
3488
|
if (!loadedCommand) return null;
|
|
3547
|
-
if (source instanceof
|
|
3489
|
+
if (source instanceof import_discord11.CommandInteraction && source.guildId && ((_a = loadedCommand.guilds) == null ? void 0 : _a.length) && !loadedCommand.guilds.includes(source.guildId)) {
|
|
3548
3490
|
return null;
|
|
3549
3491
|
}
|
|
3550
|
-
let loadedSubCommand = null;
|
|
3551
|
-
if (subcommandName) {
|
|
3552
|
-
let subcommandPath = `${loadedCommand.command.id}/${subcommandName}`;
|
|
3553
|
-
if (subcommandGroupName) {
|
|
3554
|
-
subcommandPath = `${loadedCommand.command.id}/${subcommandGroupName}/${subcommandName}`;
|
|
3555
|
-
}
|
|
3556
|
-
const subCommandId = this.subcommandPathToId.get(subcommandPath);
|
|
3557
|
-
if (subCommandId) {
|
|
3558
|
-
loadedSubCommand = this.loadedSubCommands.get(subCommandId) || null;
|
|
3559
|
-
}
|
|
3560
|
-
}
|
|
3561
3492
|
const middlewares = [];
|
|
3562
|
-
for (const middlewareId of loadedCommand.command.
|
|
3493
|
+
for (const middlewareId of loadedCommand.command.middlewares) {
|
|
3563
3494
|
const middleware = this.loadedMiddlewares.get(middlewareId);
|
|
3564
3495
|
if (middleware) {
|
|
3565
3496
|
middlewares.push(middleware);
|
|
@@ -3567,14 +3498,12 @@ var init_AppCommandHandler = __esm({
|
|
|
3567
3498
|
}
|
|
3568
3499
|
return {
|
|
3569
3500
|
command: loadedCommand,
|
|
3570
|
-
subcommand: loadedSubCommand,
|
|
3571
3501
|
middlewares,
|
|
3572
3502
|
messageCommandParser: parser2
|
|
3573
3503
|
};
|
|
3574
3504
|
}
|
|
3575
3505
|
async reloadCommands() {
|
|
3576
3506
|
this.loadedCommands.clear();
|
|
3577
|
-
this.loadedSubCommands.clear();
|
|
3578
3507
|
this.loadedMiddlewares.clear();
|
|
3579
3508
|
this.commandNameToId.clear();
|
|
3580
3509
|
this.subcommandPathToId.clear();
|
|
@@ -3592,13 +3521,6 @@ var init_AppCommandHandler = __esm({
|
|
|
3592
3521
|
for (const [id, command] of commands) {
|
|
3593
3522
|
await this.loadCommand(id, command);
|
|
3594
3523
|
}
|
|
3595
|
-
for (const loadedCommand of this.loadedCommands.values()) {
|
|
3596
|
-
if (loadedCommand.command.subcommands) {
|
|
3597
|
-
for (const subcommand of loadedCommand.command.subcommands) {
|
|
3598
|
-
await this.loadSubcommand(subcommand);
|
|
3599
|
-
}
|
|
3600
|
-
}
|
|
3601
|
-
}
|
|
3602
3524
|
}
|
|
3603
3525
|
async loadMiddleware(id, middleware) {
|
|
3604
3526
|
try {
|
|
@@ -3673,59 +3595,20 @@ var init_AppCommandHandler = __esm({
|
|
|
3673
3595
|
Logger.error(`Failed to load command ${command.name} (${id})`, error);
|
|
3674
3596
|
}
|
|
3675
3597
|
}
|
|
3676
|
-
async
|
|
3677
|
-
try {
|
|
3678
|
-
const data = await import(`${toFileURL(subcommand.path)}?t=${Date.now()}`);
|
|
3679
|
-
if (!data.command) {
|
|
3680
|
-
throw new Error(
|
|
3681
|
-
`Invalid export for subcommand ${subcommand.name}: no command definition found`
|
|
3682
|
-
);
|
|
3683
|
-
}
|
|
3684
|
-
let handlerCount = 0;
|
|
3685
|
-
for (const [key, validator] of Object.entries(commandDataSchema)) {
|
|
3686
|
-
if (key !== "command" && data[key]) handlerCount++;
|
|
3687
|
-
if (data[key] && !await validator(data[key])) {
|
|
3688
|
-
throw new Error(
|
|
3689
|
-
`Invalid export for subcommand ${subcommand.name}: ${key} does not match expected value`
|
|
3690
|
-
);
|
|
3691
|
-
}
|
|
3692
|
-
}
|
|
3693
|
-
if (handlerCount === 0) {
|
|
3694
|
-
throw new Error(
|
|
3695
|
-
`Invalid export for subcommand ${subcommand.name}: at least one handler function must be provided`
|
|
3696
|
-
);
|
|
3697
|
-
}
|
|
3698
|
-
const localizedCommand = await this.applyLocalizations(
|
|
3699
|
-
{ ...data.command },
|
|
3700
|
-
subcommand
|
|
3701
|
-
);
|
|
3702
|
-
const subcommandId = subcommand.command + "/" + subcommand.name;
|
|
3703
|
-
this.loadedSubCommands.set(subcommandId, {
|
|
3704
|
-
subcommand,
|
|
3705
|
-
data: {
|
|
3706
|
-
...data,
|
|
3707
|
-
command: localizedCommand
|
|
3708
|
-
}
|
|
3709
|
-
});
|
|
3710
|
-
this.subcommandPathToId.set(subcommandId, subcommandId);
|
|
3711
|
-
} catch (error) {
|
|
3712
|
-
Logger.error(`Failed to load subcommand ${subcommand.name}`, error);
|
|
3713
|
-
}
|
|
3714
|
-
}
|
|
3715
|
-
async applyLocalizations(command, subcommand) {
|
|
3598
|
+
async applyLocalizations(command) {
|
|
3716
3599
|
var _a, _b, _c, _d, _e;
|
|
3717
3600
|
const localization = this.commandkit.config.localizationStrategy;
|
|
3718
|
-
const validLocales = Object.values(
|
|
3601
|
+
const validLocales = Object.values(import_discord11.Locale).filter(
|
|
3719
3602
|
(v) => typeof v === "string"
|
|
3720
3603
|
);
|
|
3721
|
-
const localizationKey =
|
|
3604
|
+
const localizationKey = command.name;
|
|
3722
3605
|
for (const locale of validLocales) {
|
|
3723
3606
|
const translation = await localization.locateTranslation(
|
|
3724
3607
|
localizationKey,
|
|
3725
3608
|
locale
|
|
3726
3609
|
);
|
|
3727
3610
|
if (!(translation == null ? void 0 : translation.command)) continue;
|
|
3728
|
-
if (command instanceof
|
|
3611
|
+
if (command instanceof import_discord11.SlashCommandBuilder) {
|
|
3729
3612
|
if (translation.command.name) {
|
|
3730
3613
|
command.setNameLocalization(locale, translation.command.name);
|
|
3731
3614
|
}
|
|
@@ -3742,7 +3625,6 @@ var init_AppCommandHandler = __esm({
|
|
|
3742
3625
|
while (o = opt.shift()) {
|
|
3743
3626
|
(_c = raw.options) == null ? void 0 : _c.forEach((option) => {
|
|
3744
3627
|
var _a2;
|
|
3745
|
-
if (subcommand && option.name !== subcommand.name) return;
|
|
3746
3628
|
if (option.name === o.ref) {
|
|
3747
3629
|
if (option.name) {
|
|
3748
3630
|
option.name_localizations ??= {};
|
|
@@ -3772,14 +3654,14 @@ var init_AppCommandHandler = __esm({
|
|
|
3772
3654
|
});
|
|
3773
3655
|
}
|
|
3774
3656
|
}
|
|
3775
|
-
} else if (command instanceof
|
|
3657
|
+
} else if (command instanceof import_discord11.ContextMenuCommandBuilder) {
|
|
3776
3658
|
if (translation.command.name) {
|
|
3777
3659
|
command.setNameLocalization(locale, translation.command.name);
|
|
3778
3660
|
}
|
|
3779
3661
|
} else {
|
|
3780
3662
|
command.name_localizations ??= {};
|
|
3781
3663
|
command.name_localizations[locale] = translation.command.name;
|
|
3782
|
-
if (
|
|
3664
|
+
if (command.description) {
|
|
3783
3665
|
command.description_localizations ??= {};
|
|
3784
3666
|
command.description_localizations[locale] = translation.command.description;
|
|
3785
3667
|
}
|
|
@@ -3789,7 +3671,6 @@ var init_AppCommandHandler = __esm({
|
|
|
3789
3671
|
while (o = opt.shift()) {
|
|
3790
3672
|
command.options.forEach((option) => {
|
|
3791
3673
|
var _a2;
|
|
3792
|
-
if (subcommand && option.name !== subcommand.name) return;
|
|
3793
3674
|
if (option.name === o.ref) {
|
|
3794
3675
|
option.name_localizations ??= {};
|
|
3795
3676
|
option.name_localizations[locale] = o.name;
|
|
@@ -3822,50 +3703,70 @@ var init_AppCommandHandler = __esm({
|
|
|
3822
3703
|
return command;
|
|
3823
3704
|
}
|
|
3824
3705
|
};
|
|
3825
|
-
_AppCommandHandler_instances = new WeakSet();
|
|
3826
|
-
finalizer_fn = /* @__PURE__ */ __name(async function() {
|
|
3827
|
-
const env = useEnvironment();
|
|
3828
|
-
await env.runDeferredFunctions();
|
|
3829
|
-
env.clearAllDeferredFunctions();
|
|
3830
|
-
}, "#finalizer");
|
|
3831
3706
|
__name(_AppCommandHandler, "AppCommandHandler");
|
|
3832
3707
|
AppCommandHandler = _AppCommandHandler;
|
|
3833
3708
|
}
|
|
3834
3709
|
});
|
|
3835
3710
|
|
|
3836
3711
|
// src/app/router/CommandsRouter.ts
|
|
3837
|
-
var
|
|
3712
|
+
var import_node_fs3, import_promises3, import_node_path3, MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
|
|
3838
3713
|
var init_CommandsRouter = __esm({
|
|
3839
3714
|
"src/app/router/CommandsRouter.ts"() {
|
|
3840
3715
|
"use strict";
|
|
3841
3716
|
init_cjs_shims();
|
|
3842
|
-
import_discord11 = require("discord.js");
|
|
3843
3717
|
import_node_fs3 = require("fs");
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3718
|
+
import_promises3 = require("fs/promises");
|
|
3719
|
+
import_node_path3 = require("path");
|
|
3720
|
+
MIDDLEWARE_PATTERN = /^\+middleware\.(m|c)?(j|t)sx?$/;
|
|
3721
|
+
COMMAND_PATTERN = /^(\w+)\.(m|c)?(j|t)sx?$/;
|
|
3722
|
+
CATEGORY_PATTERN = /^\(\w+\)$/;
|
|
3847
3723
|
_CommandsRouter = class _CommandsRouter {
|
|
3848
3724
|
constructor(options) {
|
|
3849
3725
|
this.options = options;
|
|
3850
3726
|
}
|
|
3851
|
-
commands = new
|
|
3852
|
-
middlewares = new
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
id,
|
|
3861
|
-
middleware
|
|
3862
|
-
]
|
|
3863
|
-
)
|
|
3864
|
-
);
|
|
3727
|
+
commands = /* @__PURE__ */ new Map();
|
|
3728
|
+
middlewares = /* @__PURE__ */ new Map();
|
|
3729
|
+
populate(data) {
|
|
3730
|
+
for (const [id, command] of Object.entries(data.commands)) {
|
|
3731
|
+
this.commands.set(id, command);
|
|
3732
|
+
}
|
|
3733
|
+
for (const [id, middleware] of Object.entries(data.middlewares)) {
|
|
3734
|
+
this.middlewares.set(id, middleware);
|
|
3735
|
+
}
|
|
3865
3736
|
}
|
|
3866
3737
|
isValidPath() {
|
|
3867
3738
|
return (0, import_node_fs3.existsSync)(this.options.entrypoint);
|
|
3868
3739
|
}
|
|
3740
|
+
isCommand(name) {
|
|
3741
|
+
return COMMAND_PATTERN.test(name);
|
|
3742
|
+
}
|
|
3743
|
+
isMiddleware(name) {
|
|
3744
|
+
return MIDDLEWARE_PATTERN.test(name);
|
|
3745
|
+
}
|
|
3746
|
+
isCategory(name) {
|
|
3747
|
+
return CATEGORY_PATTERN.test(name);
|
|
3748
|
+
}
|
|
3749
|
+
clear() {
|
|
3750
|
+
this.commands.clear();
|
|
3751
|
+
this.middlewares.clear();
|
|
3752
|
+
}
|
|
3753
|
+
async scan() {
|
|
3754
|
+
const entries = await (0, import_promises3.readdir)(this.options.entrypoint, {
|
|
3755
|
+
withFileTypes: true
|
|
3756
|
+
});
|
|
3757
|
+
for (const entry of entries) {
|
|
3758
|
+
if (entry.name.startsWith("_")) continue;
|
|
3759
|
+
const fullPath = (0, import_node_path3.join)(this.options.entrypoint, entry.name);
|
|
3760
|
+
if (entry.isDirectory()) {
|
|
3761
|
+
const category = this.isCategory(entry.name) ? entry.name.slice(1, -1) : null;
|
|
3762
|
+
await this.traverse(fullPath, category);
|
|
3763
|
+
} else {
|
|
3764
|
+
await this.handle(entry);
|
|
3765
|
+
}
|
|
3766
|
+
}
|
|
3767
|
+
await this.applyMiddlewares();
|
|
3768
|
+
return this.toJSON();
|
|
3769
|
+
}
|
|
3869
3770
|
getData() {
|
|
3870
3771
|
return {
|
|
3871
3772
|
commands: this.commands,
|
|
@@ -3878,164 +3779,58 @@ var init_CommandsRouter = __esm({
|
|
|
3878
3779
|
middlewares: Object.fromEntries(this.middlewares.entries())
|
|
3879
3780
|
};
|
|
3880
3781
|
}
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
if (!this.isValidPath()) {
|
|
3891
|
-
throw new Error("Invalid path");
|
|
3892
|
-
}
|
|
3893
|
-
await this.traverse();
|
|
3894
|
-
this.applyBindings();
|
|
3895
|
-
return this.toJSON();
|
|
3896
|
-
}
|
|
3897
|
-
async traverse() {
|
|
3898
|
-
const validFile = /\.(c|m)?(j|t)sx?$/;
|
|
3899
|
-
const middleware = /^(\w+\.)?middleware\.(c|m)?(j|t)sx?$/;
|
|
3900
|
-
const categoryDir = /^\((\w+)\)$/;
|
|
3901
|
-
const isCategory = /* @__PURE__ */ __name((name) => categoryDir.test(name), "isCategory");
|
|
3902
|
-
const isMiddleware = /* @__PURE__ */ __name((name) => middleware.test(name), "isMiddleware");
|
|
3903
|
-
const isCommand = /* @__PURE__ */ __name((name) => validFile.test(name) && !isMiddleware(name), "isCommand");
|
|
3904
|
-
await import_walk.default.walk(
|
|
3905
|
-
this.options.entrypoint,
|
|
3906
|
-
async (error, pathname, dirent) => {
|
|
3907
|
-
if (error) throw error;
|
|
3908
|
-
const name = dirent.name;
|
|
3909
|
-
if (dirent.isDirectory()) {
|
|
3910
|
-
if (isCategory(name) && this.distanceFromRoot(pathname) > 1) {
|
|
3911
|
-
throw new Error(
|
|
3912
|
-
`Category directories must be at the root. Found "${name}" at "${pathname}"`
|
|
3913
|
-
);
|
|
3914
|
-
}
|
|
3915
|
-
return;
|
|
3916
|
-
}
|
|
3917
|
-
if (this.distanceFromRoot(pathname, true) > 1) return;
|
|
3918
|
-
if (isMiddleware(name)) {
|
|
3919
|
-
const middleware2 = {
|
|
3920
|
-
id: import_node_crypto3.default.randomUUID(),
|
|
3921
|
-
path: pathname,
|
|
3922
|
-
relativePath: this.toRelativePath(pathname)
|
|
3923
|
-
};
|
|
3924
|
-
this.middlewares.set(middleware2.id, middleware2);
|
|
3925
|
-
return;
|
|
3926
|
-
}
|
|
3927
|
-
if (!isCommand(name)) return;
|
|
3928
|
-
const command = {
|
|
3929
|
-
id: import_node_crypto3.default.randomUUID(),
|
|
3930
|
-
name: this.parseFileName(name),
|
|
3931
|
-
category: this.parseCategory(pathname),
|
|
3932
|
-
middlewareIds: [],
|
|
3933
|
-
path: pathname,
|
|
3934
|
-
relativePath: this.toRelativePath(pathname),
|
|
3935
|
-
subcommands: []
|
|
3936
|
-
};
|
|
3937
|
-
this.commands.set(command.id, command);
|
|
3938
|
-
}
|
|
3939
|
-
);
|
|
3940
|
-
await import_walk.default.walk(
|
|
3941
|
-
this.options.entrypoint,
|
|
3942
|
-
async (error, pathname, dirent) => {
|
|
3943
|
-
if (error) throw error;
|
|
3944
|
-
const name = dirent.name;
|
|
3945
|
-
if (dirent.isDirectory()) return;
|
|
3946
|
-
if (this.distanceFromRoot(pathname, true) <= 1) return;
|
|
3947
|
-
if (isMiddleware(name)) {
|
|
3948
|
-
const middleware2 = {
|
|
3949
|
-
id: import_node_crypto3.default.randomUUID(),
|
|
3950
|
-
path: pathname,
|
|
3951
|
-
relativePath: this.toRelativePath(pathname)
|
|
3952
|
-
};
|
|
3953
|
-
this.middlewares.set(middleware2.id, middleware2);
|
|
3954
|
-
return;
|
|
3955
|
-
}
|
|
3956
|
-
if (!isCommand(name)) return;
|
|
3957
|
-
let currentDir = import_node_path3.default.dirname(pathname);
|
|
3958
|
-
let parentCommand;
|
|
3959
|
-
while (currentDir !== this.options.entrypoint) {
|
|
3960
|
-
const dirName = import_node_path3.default.basename(currentDir);
|
|
3961
|
-
parentCommand = Array.from(this.commands.values()).find(
|
|
3962
|
-
(cmd) => import_node_path3.default.basename(import_node_path3.default.dirname(cmd.path)) === import_node_path3.default.basename(import_node_path3.default.dirname(currentDir)) && this.parseFileName(cmd.path) === dirName
|
|
3963
|
-
);
|
|
3964
|
-
if (parentCommand) break;
|
|
3965
|
-
currentDir = import_node_path3.default.dirname(currentDir);
|
|
3966
|
-
}
|
|
3967
|
-
if (parentCommand) {
|
|
3968
|
-
const subcommand = {
|
|
3969
|
-
name: this.parseFileName(name),
|
|
3970
|
-
group: this.parseGroup(pathname),
|
|
3971
|
-
path: pathname,
|
|
3972
|
-
relativePath: this.toRelativePath(pathname),
|
|
3973
|
-
command: parentCommand.id
|
|
3974
|
-
};
|
|
3975
|
-
parentCommand.subcommands.push(subcommand);
|
|
3976
|
-
}
|
|
3977
|
-
}
|
|
3978
|
-
);
|
|
3979
|
-
}
|
|
3980
|
-
applyBindings() {
|
|
3981
|
-
for (const command of this.commands.values()) {
|
|
3982
|
-
const commandName = command.name;
|
|
3983
|
-
const commandDir = import_node_path3.default.dirname(command.path);
|
|
3984
|
-
for (const middleware of this.middlewares.values()) {
|
|
3985
|
-
const middlewareDir = import_node_path3.default.dirname(middleware.path);
|
|
3986
|
-
const middlewareFileName = import_node_path3.default.basename(middleware.path);
|
|
3987
|
-
const isCommandSpecificMiddleware = middlewareFileName.startsWith(
|
|
3988
|
-
commandName + "."
|
|
3989
|
-
);
|
|
3990
|
-
const isSharedMiddleware = middlewareFileName === "middleware.ts" || middlewareFileName === "middleware.js";
|
|
3991
|
-
if (isCommandSpecificMiddleware && middlewareFileName.startsWith(commandName + ".")) {
|
|
3992
|
-
command.middlewareIds.push(middleware.id);
|
|
3993
|
-
continue;
|
|
3994
|
-
}
|
|
3995
|
-
if (isSharedMiddleware) {
|
|
3996
|
-
const relPath = import_node_path3.default.relative(middlewareDir, commandDir);
|
|
3997
|
-
if (!relPath.startsWith("..") && !import_node_path3.default.isAbsolute(relPath)) {
|
|
3998
|
-
command.middlewareIds.push(middleware.id);
|
|
3999
|
-
}
|
|
3782
|
+
async traverse(path2, category) {
|
|
3783
|
+
const entries = await (0, import_promises3.readdir)(path2, {
|
|
3784
|
+
withFileTypes: true
|
|
3785
|
+
});
|
|
3786
|
+
for (const entry of entries) {
|
|
3787
|
+
if (entry.name.startsWith("_")) continue;
|
|
3788
|
+
if (entry.isFile()) {
|
|
3789
|
+
if (this.isCommand(entry.name) || this.isMiddleware(entry.name)) {
|
|
3790
|
+
await this.handle(entry, category);
|
|
4000
3791
|
}
|
|
4001
3792
|
}
|
|
4002
3793
|
}
|
|
4003
3794
|
}
|
|
4004
|
-
|
|
4005
|
-
const
|
|
4006
|
-
const
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
const relativeIndex = entrypointParts.length;
|
|
4028
|
-
const categoryDir = parts[relativeIndex];
|
|
4029
|
-
if (!categoryDir || !/^\((\w+)\)$/.test(categoryDir)) {
|
|
4030
|
-
return null;
|
|
3795
|
+
async handle(entry, category = null) {
|
|
3796
|
+
const name = entry.name;
|
|
3797
|
+
const path2 = (0, import_node_path3.join)(entry.parentPath, entry.name);
|
|
3798
|
+
if (this.isCommand(name)) {
|
|
3799
|
+
const command = {
|
|
3800
|
+
id: crypto.randomUUID(),
|
|
3801
|
+
name: (0, import_node_path3.basename)(path2, (0, import_node_path3.extname)(path2)),
|
|
3802
|
+
path: path2,
|
|
3803
|
+
category,
|
|
3804
|
+
parentPath: entry.parentPath,
|
|
3805
|
+
relativePath: this.replaceEntrypoint(path2),
|
|
3806
|
+
middlewares: []
|
|
3807
|
+
};
|
|
3808
|
+
this.commands.set(command.id, command);
|
|
3809
|
+
} else if (this.isMiddleware(name)) {
|
|
3810
|
+
const middleware = {
|
|
3811
|
+
id: crypto.randomUUID(),
|
|
3812
|
+
name: (0, import_node_path3.basename)(path2, (0, import_node_path3.extname)(path2)),
|
|
3813
|
+
path: path2,
|
|
3814
|
+
relativePath: this.replaceEntrypoint(path2),
|
|
3815
|
+
parentPath: entry.parentPath
|
|
3816
|
+
};
|
|
3817
|
+
this.middlewares.set(middleware.id, middleware);
|
|
4031
3818
|
}
|
|
4032
|
-
return categoryDir.slice(1, -1);
|
|
4033
3819
|
}
|
|
4034
|
-
|
|
4035
|
-
|
|
3820
|
+
applyMiddlewares() {
|
|
3821
|
+
this.commands.forEach((command) => {
|
|
3822
|
+
const commandPath = command.parentPath;
|
|
3823
|
+
const samePathMiddlewares = Array.from(this.middlewares.values()).filter((middleware) => {
|
|
3824
|
+
return middleware.parentPath === commandPath;
|
|
3825
|
+
}).map((middleware) => middleware.id);
|
|
3826
|
+
command.middlewares = Array.from(
|
|
3827
|
+
/* @__PURE__ */ new Set([...command.middlewares, ...samePathMiddlewares])
|
|
3828
|
+
);
|
|
3829
|
+
});
|
|
4036
3830
|
}
|
|
4037
|
-
|
|
4038
|
-
|
|
3831
|
+
replaceEntrypoint(path2) {
|
|
3832
|
+
const normalized = (0, import_node_path3.normalize)(path2);
|
|
3833
|
+
return normalized.replace(this.options.entrypoint, "");
|
|
4039
3834
|
}
|
|
4040
3835
|
};
|
|
4041
3836
|
__name(_CommandsRouter, "CommandsRouter");
|
|
@@ -4044,13 +3839,13 @@ var init_CommandsRouter = __esm({
|
|
|
4044
3839
|
});
|
|
4045
3840
|
|
|
4046
3841
|
// src/app/router/EventsRouter.ts
|
|
4047
|
-
var import_node_fs4,
|
|
3842
|
+
var import_node_fs4, import_promises4, import_node_path4, _EventsRouter, EventsRouter;
|
|
4048
3843
|
var init_EventsRouter = __esm({
|
|
4049
3844
|
"src/app/router/EventsRouter.ts"() {
|
|
4050
3845
|
"use strict";
|
|
4051
3846
|
init_cjs_shims();
|
|
4052
3847
|
import_node_fs4 = require("fs");
|
|
4053
|
-
|
|
3848
|
+
import_promises4 = require("fs/promises");
|
|
4054
3849
|
import_node_path4 = require("path");
|
|
4055
3850
|
_EventsRouter = class _EventsRouter {
|
|
4056
3851
|
/**
|
|
@@ -4106,12 +3901,11 @@ var init_EventsRouter = __esm({
|
|
|
4106
3901
|
* @returns Promise resolving to the events tree
|
|
4107
3902
|
*/
|
|
4108
3903
|
async scan() {
|
|
4109
|
-
const dirs = await (0,
|
|
3904
|
+
const dirs = await (0, import_promises4.readdir)(this.entrypoint, { withFileTypes: true });
|
|
4110
3905
|
for (const dir of dirs) {
|
|
4111
3906
|
if (dir.isDirectory()) {
|
|
4112
|
-
const
|
|
4113
|
-
|
|
4114
|
-
this.events.set(event.event, event);
|
|
3907
|
+
const path2 = (0, import_node_path4.join)(this.entrypoint, dir.name);
|
|
3908
|
+
await this.scanEvent(dir.name, path2, null, [], true);
|
|
4115
3909
|
}
|
|
4116
3910
|
}
|
|
4117
3911
|
return Object.fromEntries(this.events);
|
|
@@ -4130,23 +3924,24 @@ var init_EventsRouter = __esm({
|
|
|
4130
3924
|
* @param listeners - Array to collect listener file paths
|
|
4131
3925
|
* @returns Promise resolving to the parsed event metadata
|
|
4132
3926
|
*/
|
|
4133
|
-
async scanEvent(event,
|
|
4134
|
-
|
|
4135
|
-
const
|
|
3927
|
+
async scanEvent(event, path2, _namespace = null, listeners = [], isRoot = false) {
|
|
3928
|
+
const files = await (0, import_promises4.readdir)(path2, { withFileTypes: true });
|
|
3929
|
+
const isNamespace = isRoot && /^\(.+\)$/.test(event);
|
|
3930
|
+
const namespace = isNamespace ? event.slice(1, -1) : _namespace ?? null;
|
|
4136
3931
|
for (const file of files) {
|
|
4137
|
-
if (
|
|
3932
|
+
if (file.name.includes("_")) continue;
|
|
4138
3933
|
if (file.isDirectory()) {
|
|
4139
|
-
const nextPath = (0, import_node_path4.join)(
|
|
4140
|
-
await this.scanEvent(
|
|
3934
|
+
const nextPath = (0, import_node_path4.join)(path2, file.name);
|
|
3935
|
+
await this.scanEvent(file.name, nextPath, namespace, listeners);
|
|
4141
3936
|
continue;
|
|
4142
3937
|
}
|
|
4143
3938
|
if (file.isFile() && /\.(m|c)?(j|t)sx?$/.test(file.name)) {
|
|
4144
3939
|
listeners.push((0, import_node_path4.join)(file.parentPath, file.name));
|
|
4145
3940
|
}
|
|
4146
3941
|
}
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
3942
|
+
if (!isNamespace) {
|
|
3943
|
+
this.events.set(event, { event, path: path2, listeners, namespace });
|
|
3944
|
+
}
|
|
4150
3945
|
}
|
|
4151
3946
|
};
|
|
4152
3947
|
__name(_EventsRouter, "EventsRouter");
|
|
@@ -4173,8 +3968,8 @@ var init_AppEventsHandler = __esm({
|
|
|
4173
3968
|
init_Logger();
|
|
4174
3969
|
init_resolve_file_url();
|
|
4175
3970
|
_AppEventsHandler = class _AppEventsHandler {
|
|
4176
|
-
constructor(
|
|
4177
|
-
this.commandkit =
|
|
3971
|
+
constructor(commandkit2) {
|
|
3972
|
+
this.commandkit = commandkit2;
|
|
4178
3973
|
}
|
|
4179
3974
|
loadedEvents = /* @__PURE__ */ new Map();
|
|
4180
3975
|
async reloadEvents() {
|
|
@@ -4344,21 +4139,21 @@ async function generateTypesPackage() {
|
|
|
4344
4139
|
command: CommandTypeData;
|
|
4345
4140
|
}
|
|
4346
4141
|
}`;
|
|
4347
|
-
await (0,
|
|
4348
|
-
await (0,
|
|
4349
|
-
await (0,
|
|
4350
|
-
await (0,
|
|
4351
|
-
await (0,
|
|
4352
|
-
await (0,
|
|
4142
|
+
await (0, import_promises5.mkdir)(location, { recursive: true });
|
|
4143
|
+
await (0, import_promises5.writeFile)(packageJSON, JSON.stringify(packageJSONContent, null, 2));
|
|
4144
|
+
await (0, import_promises5.writeFile)(index, indexContent);
|
|
4145
|
+
await (0, import_promises5.writeFile)(types, typesContent);
|
|
4146
|
+
await (0, import_promises5.writeFile)(locale, "");
|
|
4147
|
+
await (0, import_promises5.writeFile)(command, "");
|
|
4353
4148
|
return location;
|
|
4354
4149
|
}
|
|
4355
|
-
var import_node_fs5,
|
|
4150
|
+
var import_node_fs5, import_promises5, import_node_path5;
|
|
4356
4151
|
var init_types_package = __esm({
|
|
4357
4152
|
"src/utils/types-package.ts"() {
|
|
4358
4153
|
"use strict";
|
|
4359
4154
|
init_cjs_shims();
|
|
4360
4155
|
import_node_fs5 = require("fs");
|
|
4361
|
-
|
|
4156
|
+
import_promises5 = require("fs/promises");
|
|
4362
4157
|
import_node_path5 = require("path");
|
|
4363
4158
|
__name(generateTypesPackage, "generateTypesPackage");
|
|
4364
4159
|
}
|
|
@@ -4477,24 +4272,24 @@ var init_loader = __esm({
|
|
|
4477
4272
|
});
|
|
4478
4273
|
|
|
4479
4274
|
// src/utils/dev-hooks.ts
|
|
4480
|
-
function registerDevHooks(
|
|
4275
|
+
function registerDevHooks(commandkit2) {
|
|
4481
4276
|
if (!COMMANDKIT_IS_DEV) return;
|
|
4482
4277
|
process.on("message", (message) => {
|
|
4483
4278
|
if (typeof message !== "object" || message === null) return;
|
|
4484
|
-
const { event, path:
|
|
4279
|
+
const { event, path: path2 } = message;
|
|
4485
4280
|
if (!event) return;
|
|
4486
4281
|
if (process.env.COMMANDKIT_DEBUG_HMR === "true") {
|
|
4487
|
-
Logger.info(`Received HMR event: ${event}${
|
|
4282
|
+
Logger.info(`Received HMR event: ${event}${path2 ? ` for ${path2}` : ""}`);
|
|
4488
4283
|
}
|
|
4489
4284
|
switch (event) {
|
|
4490
4285
|
case "reload-commands":
|
|
4491
|
-
|
|
4286
|
+
commandkit2.commandHandler.reloadCommands();
|
|
4492
4287
|
break;
|
|
4493
4288
|
case "reload-events":
|
|
4494
|
-
|
|
4289
|
+
commandkit2.eventHandler.reloadEvents();
|
|
4495
4290
|
break;
|
|
4496
4291
|
case "reload-locales":
|
|
4497
|
-
|
|
4292
|
+
commandkit2.commandHandler.reloadCommands();
|
|
4498
4293
|
break;
|
|
4499
4294
|
}
|
|
4500
4295
|
});
|
|
@@ -4517,8 +4312,8 @@ var init_CommandKitEventsChannel = __esm({
|
|
|
4517
4312
|
init_cjs_shims();
|
|
4518
4313
|
import_node_events = __toESM(require("events"));
|
|
4519
4314
|
_CommandKitEventsChannel = class _CommandKitEventsChannel {
|
|
4520
|
-
constructor(
|
|
4521
|
-
this.commandkit =
|
|
4315
|
+
constructor(commandkit2) {
|
|
4316
|
+
this.commandkit = commandkit2;
|
|
4522
4317
|
}
|
|
4523
4318
|
emitter = new import_node_events.default();
|
|
4524
4319
|
to(namespace) {
|
|
@@ -4556,7 +4351,7 @@ var init_CommandKitEventsChannel = __esm({
|
|
|
4556
4351
|
});
|
|
4557
4352
|
|
|
4558
4353
|
// src/CommandKit.ts
|
|
4559
|
-
var import_node_events2, import_discord12, import_node_path8, import_node_fs8, _started, _CommandKit_instances, init_fn, initCommands_fn, initEvents_fn, _CommandKit, CommandKit;
|
|
4354
|
+
var import_node_events2, import_discord12, import_node_path8, import_node_fs8, commandkit, _started, _CommandKit_instances, init_fn, initCommands_fn, initEvents_fn, _CommandKit, CommandKit;
|
|
4560
4355
|
var init_CommandKit = __esm({
|
|
4561
4356
|
"src/CommandKit.ts"() {
|
|
4562
4357
|
"use strict";
|
|
@@ -4634,6 +4429,7 @@ var init_CommandKit = __esm({
|
|
|
4634
4429
|
if (!_CommandKit.instance) {
|
|
4635
4430
|
_CommandKit.instance = this;
|
|
4636
4431
|
}
|
|
4432
|
+
commandkit = _CommandKit.instance;
|
|
4637
4433
|
}
|
|
4638
4434
|
/**
|
|
4639
4435
|
* Starts the commandkit application.
|
|
@@ -4868,7 +4664,7 @@ var init_version = __esm({
|
|
|
4868
4664
|
"use strict";
|
|
4869
4665
|
init_cjs_shims();
|
|
4870
4666
|
version = /* @__MACRO__ $version */
|
|
4871
|
-
"0.1.11-dev.
|
|
4667
|
+
"0.1.11-dev.20250327153237";
|
|
4872
4668
|
}
|
|
4873
4669
|
});
|
|
4874
4670
|
|
|
@@ -5027,9 +4823,9 @@ async function main() {
|
|
|
5027
4823
|
await main();
|
|
5028
4824
|
`;
|
|
5029
4825
|
const dist = isDev ? ".commandkit" : distDir || "dist";
|
|
5030
|
-
await (0,
|
|
4826
|
+
await (0, import_promises6.writeFile)((0, import_node_path10.join)(configPath, dist, "index.js"), code);
|
|
5031
4827
|
}
|
|
5032
|
-
var import_tsup,
|
|
4828
|
+
var import_tsup, import_promises6, import_node_path10, envScript, requireScript, antiCrashScript, wrapInAsyncIIFE;
|
|
5033
4829
|
var init_build = __esm({
|
|
5034
4830
|
"src/cli/build.ts"() {
|
|
5035
4831
|
"use strict";
|
|
@@ -5037,7 +4833,7 @@ var init_build = __esm({
|
|
|
5037
4833
|
import_tsup = require("tsup");
|
|
5038
4834
|
init_plugins();
|
|
5039
4835
|
init_loader();
|
|
5040
|
-
|
|
4836
|
+
import_promises6 = require("fs/promises");
|
|
5041
4837
|
import_node_path10 = require("path");
|
|
5042
4838
|
init_env();
|
|
5043
4839
|
__name(buildApplication, "buildApplication");
|
|
@@ -5117,40 +4913,40 @@ async function bootstrapDevelopmentServer(configPath) {
|
|
|
5117
4913
|
ignoreInitial: true
|
|
5118
4914
|
});
|
|
5119
4915
|
let ps = null;
|
|
5120
|
-
const performHMR = debounce(async (
|
|
5121
|
-
if (!
|
|
4916
|
+
const performHMR = debounce(async (path2) => {
|
|
4917
|
+
if (!path2 || !ps) return false;
|
|
5122
4918
|
if (!ps.send) return false;
|
|
5123
|
-
if (isCommandSource(
|
|
4919
|
+
if (isCommandSource(path2)) {
|
|
5124
4920
|
console.log(
|
|
5125
|
-
`${colors_default.cyanBright("Reloading command(s) at ")} ${colors_default.yellowBright(
|
|
4921
|
+
`${colors_default.cyanBright("Reloading command(s) at ")} ${colors_default.yellowBright(path2)}`
|
|
5126
4922
|
);
|
|
5127
4923
|
await buildAndStart(cwd, true);
|
|
5128
|
-
ps.send({ event: "reload-commands", path:
|
|
4924
|
+
ps.send({ event: "reload-commands", path: path2 });
|
|
5129
4925
|
return true;
|
|
5130
4926
|
}
|
|
5131
|
-
if (isEventSource(
|
|
4927
|
+
if (isEventSource(path2)) {
|
|
5132
4928
|
console.log(
|
|
5133
|
-
`${colors_default.cyanBright("Reloading event(s) at ")} ${colors_default.yellowBright(
|
|
4929
|
+
`${colors_default.cyanBright("Reloading event(s) at ")} ${colors_default.yellowBright(path2)}`
|
|
5134
4930
|
);
|
|
5135
4931
|
await buildAndStart(cwd, true);
|
|
5136
|
-
ps.send({ event: "reload-events", path:
|
|
4932
|
+
ps.send({ event: "reload-events", path: path2 });
|
|
5137
4933
|
return true;
|
|
5138
4934
|
}
|
|
5139
|
-
if (isLocaleSource(
|
|
4935
|
+
if (isLocaleSource(path2)) {
|
|
5140
4936
|
console.log(
|
|
5141
|
-
`${colors_default.cyanBright("Reloading locale(s) at ")} ${colors_default.yellowBright(
|
|
4937
|
+
`${colors_default.cyanBright("Reloading locale(s) at ")} ${colors_default.yellowBright(path2)}`
|
|
5142
4938
|
);
|
|
5143
4939
|
await buildAndStart(cwd, true);
|
|
5144
|
-
ps.send({ event: "reload-locales", path:
|
|
4940
|
+
ps.send({ event: "reload-locales", path: path2 });
|
|
5145
4941
|
return true;
|
|
5146
4942
|
}
|
|
5147
4943
|
return false;
|
|
5148
4944
|
}, 300);
|
|
5149
|
-
const hmrHandler = /* @__PURE__ */ __name(async (
|
|
5150
|
-
const hmr = await performHMR(
|
|
4945
|
+
const hmrHandler = /* @__PURE__ */ __name(async (path2) => {
|
|
4946
|
+
const hmr = await performHMR(path2);
|
|
5151
4947
|
if (hmr) return;
|
|
5152
4948
|
console.log(
|
|
5153
|
-
`${colors_default.yellowBright("\u26A1\uFE0F Performing full restart due to the changes in")} ${colors_default.cyanBright(
|
|
4949
|
+
`${colors_default.yellowBright("\u26A1\uFE0F Performing full restart due to the changes in")} ${colors_default.cyanBright(path2)}`
|
|
5154
4950
|
);
|
|
5155
4951
|
ps == null ? void 0 : ps.kill();
|
|
5156
4952
|
ps = await buildAndStart(cwd);
|
|
@@ -5230,7 +5026,7 @@ async function createSpinner(text) {
|
|
|
5230
5026
|
});
|
|
5231
5027
|
}
|
|
5232
5028
|
var ora;
|
|
5233
|
-
var
|
|
5029
|
+
var init_utils = __esm({
|
|
5234
5030
|
"src/cli/utils.ts"() {
|
|
5235
5031
|
"use strict";
|
|
5236
5032
|
init_cjs_shims();
|
|
@@ -5280,7 +5076,7 @@ var init_production = __esm({
|
|
|
5280
5076
|
init_common();
|
|
5281
5077
|
init_build();
|
|
5282
5078
|
init_plugins();
|
|
5283
|
-
|
|
5079
|
+
init_utils();
|
|
5284
5080
|
__name(bootstrapProductionServer, "bootstrapProductionServer");
|
|
5285
5081
|
__name(createProductionBuild, "createProductionBuild");
|
|
5286
5082
|
}
|
|
@@ -5295,7 +5091,7 @@ __export(generators_exports, {
|
|
|
5295
5091
|
});
|
|
5296
5092
|
async function generateCommand(name, customPath) {
|
|
5297
5093
|
const cmdPath = (0, import_path4.join)(customPath || COMMANDS_DIR, name);
|
|
5298
|
-
if (!(0, import_fs2.existsSync)(cmdPath)) await (0,
|
|
5094
|
+
if (!(0, import_fs2.existsSync)(cmdPath)) await (0, import_promises7.mkdir)(cmdPath, { recursive: true });
|
|
5299
5095
|
if ((0, import_fs2.existsSync)((0, import_path4.join)(cmdPath, "command.ts"))) {
|
|
5300
5096
|
panic(`Command ${name} already exists.`);
|
|
5301
5097
|
}
|
|
@@ -5315,7 +5111,7 @@ export const message: MessageCommand = async (ctx) => {
|
|
|
5315
5111
|
await ctx.message.reply('Hello from ${name}!');
|
|
5316
5112
|
};
|
|
5317
5113
|
`.trim();
|
|
5318
|
-
await (0,
|
|
5114
|
+
await (0, import_promises7.writeFile)((0, import_path4.join)(cmdPath, "command.ts"), commandFile);
|
|
5319
5115
|
console.log(
|
|
5320
5116
|
colors_default.green(
|
|
5321
5117
|
`Command ${colors_default.magenta(name)} created at ${colors_default.blue(formatPath(cmdPath))}/command.ts`
|
|
@@ -5324,10 +5120,10 @@ export const message: MessageCommand = async (ctx) => {
|
|
|
5324
5120
|
}
|
|
5325
5121
|
async function generateEvent(name, customPath) {
|
|
5326
5122
|
const eventPath = (0, import_path4.join)(customPath || EVENTS_DIR, name);
|
|
5327
|
-
if (!(0, import_fs2.existsSync)(eventPath)) await (0,
|
|
5123
|
+
if (!(0, import_fs2.existsSync)(eventPath)) await (0, import_promises7.mkdir)(eventPath, { recursive: true });
|
|
5328
5124
|
let filename = "event.ts";
|
|
5329
5125
|
if ((0, import_fs2.existsSync)((0, import_path4.join)(eventPath, filename))) {
|
|
5330
|
-
const count = (await (0,
|
|
5126
|
+
const count = (await (0, import_promises7.readdir)(eventPath)).length;
|
|
5331
5127
|
filename = `${String(count).padStart(2, "0")}_${filename}`;
|
|
5332
5128
|
}
|
|
5333
5129
|
const eventFile = `
|
|
@@ -5335,7 +5131,7 @@ export default async function on${name[0].toUpperCase() + name.slice(1)}() {
|
|
|
5335
5131
|
console.log('${name} event fired!');
|
|
5336
5132
|
};
|
|
5337
5133
|
`.trim();
|
|
5338
|
-
await (0,
|
|
5134
|
+
await (0, import_promises7.writeFile)((0, import_path4.join)(eventPath, filename), eventFile);
|
|
5339
5135
|
console.log(
|
|
5340
5136
|
colors_default.green(
|
|
5341
5137
|
`Event ${colors_default.magenta(name)} created at ${colors_default.blue(formatPath(eventPath))}/${colors_default.magenta(filename)}`
|
|
@@ -5353,7 +5149,7 @@ async function generateLocale(locale, commandName, customPath) {
|
|
|
5353
5149
|
panic("Command name is required.");
|
|
5354
5150
|
}
|
|
5355
5151
|
const localePath = (0, import_path4.join)(customPath || LOCALES_DIR, locale);
|
|
5356
|
-
if (!(0, import_fs2.existsSync)(localePath)) await (0,
|
|
5152
|
+
if (!(0, import_fs2.existsSync)(localePath)) await (0, import_promises7.mkdir)(localePath, { recursive: true });
|
|
5357
5153
|
if ((0, import_fs2.existsSync)((0, import_path4.join)(localePath, `${commandName}.json`))) {
|
|
5358
5154
|
panic(`Locale file for ${commandName} already exists.`);
|
|
5359
5155
|
}
|
|
@@ -5364,7 +5160,7 @@ async function generateLocale(locale, commandName, customPath) {
|
|
|
5364
5160
|
},
|
|
5365
5161
|
translations: {}
|
|
5366
5162
|
};
|
|
5367
|
-
await (0,
|
|
5163
|
+
await (0, import_promises7.writeFile)(
|
|
5368
5164
|
(0, import_path4.join)(localePath, `${commandName}.json`),
|
|
5369
5165
|
JSON.stringify(localeFile, null, 2)
|
|
5370
5166
|
);
|
|
@@ -5376,12 +5172,12 @@ async function generateLocale(locale, commandName, customPath) {
|
|
|
5376
5172
|
)
|
|
5377
5173
|
);
|
|
5378
5174
|
}
|
|
5379
|
-
var
|
|
5175
|
+
var import_promises7, import_path4, import_discord13, import_fs2, BASE_PATH, COMMANDS_DIR, EVENTS_DIR, LOCALES_DIR, formatPath;
|
|
5380
5176
|
var init_generators = __esm({
|
|
5381
5177
|
"src/cli/generators.ts"() {
|
|
5382
5178
|
"use strict";
|
|
5383
5179
|
init_cjs_shims();
|
|
5384
|
-
|
|
5180
|
+
import_promises7 = require("fs/promises");
|
|
5385
5181
|
import_path4 = require("path");
|
|
5386
5182
|
import_discord13 = require("discord.js");
|
|
5387
5183
|
init_common();
|
|
@@ -5391,7 +5187,7 @@ var init_generators = __esm({
|
|
|
5391
5187
|
COMMANDS_DIR = (0, import_path4.join)(BASE_PATH, "src/app/commands");
|
|
5392
5188
|
EVENTS_DIR = (0, import_path4.join)(BASE_PATH, "src/app/events");
|
|
5393
5189
|
LOCALES_DIR = (0, import_path4.join)(BASE_PATH, "src/app/locales");
|
|
5394
|
-
formatPath = /* @__PURE__ */ __name((
|
|
5190
|
+
formatPath = /* @__PURE__ */ __name((path2) => path2.replace(process.cwd(), ".").replace(/\\/g, "/"), "formatPath");
|
|
5395
5191
|
__name(generateCommand, "generateCommand");
|
|
5396
5192
|
__name(generateEvent, "generateEvent");
|
|
5397
5193
|
__name(generateLocale, "generateLocale");
|
|
@@ -5410,7 +5206,10 @@ __export(index_exports, {
|
|
|
5410
5206
|
CommandKit: () => CommandKit,
|
|
5411
5207
|
CommandKitEnvironment: () => CommandKitEnvironment,
|
|
5412
5208
|
CommandKitEnvironmentType: () => CommandKitEnvironmentType,
|
|
5209
|
+
CommandKitPluginRuntime: () => CommandKitPluginRuntime,
|
|
5413
5210
|
CommandsRouter: () => CommandsRouter,
|
|
5211
|
+
CompilerPlugin: () => CompilerPlugin,
|
|
5212
|
+
CompilerPluginRuntime: () => CompilerPluginRuntime,
|
|
5414
5213
|
Context: () => Context,
|
|
5415
5214
|
DefaultLocalizationStrategy: () => DefaultLocalizationStrategy,
|
|
5416
5215
|
DefaultLogger: () => DefaultLogger,
|
|
@@ -5427,6 +5226,7 @@ __export(index_exports, {
|
|
|
5427
5226
|
Modal: () => Modal,
|
|
5428
5227
|
ModalKit: () => ModalKit,
|
|
5429
5228
|
ParagraphInput: () => ParagraphInput,
|
|
5229
|
+
RuntimePlugin: () => RuntimePlugin,
|
|
5430
5230
|
ShortInput: () => ShortInput,
|
|
5431
5231
|
TextInput: () => TextInput,
|
|
5432
5232
|
afterCommand: () => afterCommand,
|
|
@@ -5435,6 +5235,7 @@ __export(index_exports, {
|
|
|
5435
5235
|
cacheLife: () => cacheLife,
|
|
5436
5236
|
cacheTag: () => cacheTag,
|
|
5437
5237
|
cancelAfterCommand: () => cancelAfterCommand,
|
|
5238
|
+
commandkit: () => commandkit,
|
|
5438
5239
|
createElement: () => createElement,
|
|
5439
5240
|
createLogger: () => createLogger,
|
|
5440
5241
|
default: () => index_default,
|
|
@@ -5442,6 +5243,7 @@ __export(index_exports, {
|
|
|
5442
5243
|
dmOnly: () => dmOnly,
|
|
5443
5244
|
exitContext: () => exitContext,
|
|
5444
5245
|
exitMiddleware: () => exitMiddleware,
|
|
5246
|
+
fromEsbuildPlugin: () => fromEsbuildPlugin,
|
|
5445
5247
|
getCommandKit: () => getCommandKit,
|
|
5446
5248
|
getConfig: () => getConfig,
|
|
5447
5249
|
getContext: () => getContext,
|
|
@@ -5450,6 +5252,8 @@ __export(index_exports, {
|
|
|
5450
5252
|
invalidate: () => invalidate,
|
|
5451
5253
|
isCachedFunction: () => isCachedFunction,
|
|
5452
5254
|
isCommandKitElement: () => isCommandKitElement,
|
|
5255
|
+
isCompilerPlugin: () => isCompilerPlugin,
|
|
5256
|
+
isRuntimePlugin: () => isRuntimePlugin,
|
|
5453
5257
|
makeContextAwareFunction: () => makeContextAwareFunction,
|
|
5454
5258
|
redirect: () => redirect,
|
|
5455
5259
|
rethrow: () => rethrow,
|
|
@@ -5495,6 +5299,7 @@ init_cjs_shims();
|
|
|
5495
5299
|
init_Logger();
|
|
5496
5300
|
init_router();
|
|
5497
5301
|
init_version();
|
|
5302
|
+
init_plugins();
|
|
5498
5303
|
|
|
5499
5304
|
// src/cli/init.ts
|
|
5500
5305
|
init_cjs_shims();
|
|
@@ -5561,7 +5366,10 @@ var index_default = CommandKit;
|
|
|
5561
5366
|
CommandKit,
|
|
5562
5367
|
CommandKitEnvironment,
|
|
5563
5368
|
CommandKitEnvironmentType,
|
|
5369
|
+
CommandKitPluginRuntime,
|
|
5564
5370
|
CommandsRouter,
|
|
5371
|
+
CompilerPlugin,
|
|
5372
|
+
CompilerPluginRuntime,
|
|
5565
5373
|
Context,
|
|
5566
5374
|
DefaultLocalizationStrategy,
|
|
5567
5375
|
DefaultLogger,
|
|
@@ -5578,6 +5386,7 @@ var index_default = CommandKit;
|
|
|
5578
5386
|
Modal,
|
|
5579
5387
|
ModalKit,
|
|
5580
5388
|
ParagraphInput,
|
|
5389
|
+
RuntimePlugin,
|
|
5581
5390
|
ShortInput,
|
|
5582
5391
|
TextInput,
|
|
5583
5392
|
afterCommand,
|
|
@@ -5586,12 +5395,14 @@ var index_default = CommandKit;
|
|
|
5586
5395
|
cacheLife,
|
|
5587
5396
|
cacheTag,
|
|
5588
5397
|
cancelAfterCommand,
|
|
5398
|
+
commandkit,
|
|
5589
5399
|
createElement,
|
|
5590
5400
|
createLogger,
|
|
5591
5401
|
defineConfig,
|
|
5592
5402
|
dmOnly,
|
|
5593
5403
|
exitContext,
|
|
5594
5404
|
exitMiddleware,
|
|
5405
|
+
fromEsbuildPlugin,
|
|
5595
5406
|
getCommandKit,
|
|
5596
5407
|
getConfig,
|
|
5597
5408
|
getContext,
|
|
@@ -5600,6 +5411,8 @@ var index_default = CommandKit;
|
|
|
5600
5411
|
invalidate,
|
|
5601
5412
|
isCachedFunction,
|
|
5602
5413
|
isCommandKitElement,
|
|
5414
|
+
isCompilerPlugin,
|
|
5415
|
+
isRuntimePlugin,
|
|
5603
5416
|
makeContextAwareFunction,
|
|
5604
5417
|
redirect,
|
|
5605
5418
|
rethrow,
|