commandkit 1.0.0-dev.20250613125159 → 1.0.0-dev.20250614015940
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/{CommandKit-BWzWBBGf.d.ts → CommandKit-BSXFD1Tt.d.ts} +359 -342
- package/dist/{CommandKit-BwxIJqBr.js → CommandKit-CT3K-Cac.js} +178 -174
- package/dist/CommandKit-CT3K-Cac.js.map +1 -0
- package/dist/CommandKit.d.ts +1 -1
- package/dist/CommandKit.js +4 -4
- package/dist/{EventWorkerContext-DdzSorsU.d.ts → EventWorkerContext-BnghX_KV.d.ts} +2 -2
- package/dist/{MessageCommandParser-Cz-3I-wL.js → MessageCommandParser-ClkDMI8g.js} +1 -1
- package/dist/{MessageCommandParser-Cz-3I-wL.js.map → MessageCommandParser-ClkDMI8g.js.map} +1 -1
- package/dist/analytics/analytics-engine.d.ts +1 -1
- package/dist/analytics/analytics-engine.js +4 -4
- package/dist/analytics/analytics-provider.d.ts +1 -1
- package/dist/analytics/utils.js +4 -4
- package/dist/app/commands/AppCommandRunner.d.ts +1 -1
- package/dist/app/commands/AppCommandRunner.js +4 -4
- package/dist/app/commands/Context.d.ts +1 -1
- package/dist/app/commands/Context.js +4 -4
- package/dist/app/commands/MessageCommandParser.js +1 -1
- package/dist/app/events/EventWorkerContext.d.ts +2 -2
- package/dist/app/handlers/AppCommandHandler.d.ts +2 -2
- package/dist/app/handlers/AppCommandHandler.js +4 -4
- package/dist/app/handlers/AppEventsHandler.d.ts +1 -1
- package/dist/app/handlers/AppEventsHandler.js +4 -4
- package/dist/app/index.d.ts +2 -2
- package/dist/app/index.js +4 -4
- package/dist/app/register/CommandRegistrar.d.ts +1 -1
- package/dist/app/register/CommandRegistrar.js +4 -4
- package/dist/{app-process-Bo-LedP8.js → app-process-DKNuvPMz.js} +2 -2
- package/dist/{app-process-Bo-LedP8.js.map → app-process-DKNuvPMz.js.map} +1 -1
- package/dist/{build-m0yxcs2c.js → build-CpZp-wxh.js} +4 -4
- package/dist/{build-m0yxcs2c.js.map → build-CpZp-wxh.js.map} +1 -1
- package/dist/cli/app-process.d.ts +2 -2
- package/dist/cli/app-process.js +3 -3
- package/dist/cli/build.d.ts +1 -1
- package/dist/cli/build.js +6 -6
- package/dist/cli/common.d.ts +5 -5
- package/dist/cli/common.js +2 -2
- package/dist/cli/development.js +7 -7
- package/dist/cli/generators.js +2 -2
- package/dist/cli/information.js +1 -1
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.js +5 -5
- package/dist/cli/production.d.ts +2 -2
- package/dist/cli/production.js +7 -7
- package/dist/cli/type-checker.js +3 -3
- package/dist/{common-Dasi9oKU.js → common-D11Ax__S.js} +2 -2
- package/dist/{common-Dasi9oKU.js.map → common-D11Ax__S.js.map} +1 -1
- package/dist/components/index.js +4 -4
- package/dist/components/v1/button/Button.js +4 -4
- package/dist/components/v1/button/ButtonKit.js +4 -4
- package/dist/components/v1/modal/Modal.js +4 -4
- package/dist/components/v1/modal/ModalKit.js +4 -4
- package/dist/components/v1/select-menu/ChannelSelectMenuKit.js +4 -4
- package/dist/components/v1/select-menu/MentionableSelectMenuKit.js +4 -4
- package/dist/components/v1/select-menu/RoleSelectMenuKit.js +4 -4
- package/dist/components/v1/select-menu/SelectMenu.js +4 -4
- package/dist/components/v1/select-menu/StringSelectMenuKit.js +4 -4
- package/dist/components/v1/select-menu/UserSelectMenuKit.js +4 -4
- package/dist/config/config.d.ts +4 -4
- package/dist/config/config.js +4 -4
- package/dist/config/default.d.ts +3 -3
- package/dist/config/default.js +4 -4
- package/dist/config/loader.d.ts +3 -3
- package/dist/config/loader.js +4 -4
- package/dist/config/types.d.ts +2 -2
- package/dist/config/utils.d.ts +3 -3
- package/dist/{config-BEl-UW2l.d.ts → config-CRU_9adq.d.ts} +3 -3
- package/dist/context/async-context.d.ts +1 -1
- package/dist/context/async-context.js +4 -4
- package/dist/context/environment.d.ts +1 -1
- package/dist/context/environment.js +4 -4
- package/dist/events/CommandKitEventsChannel.d.ts +1 -1
- package/dist/{feature-flags-DG5Ozd1p.js → feature-flags-B1rI-fjI.js} +2 -2
- package/dist/{feature-flags-DG5Ozd1p.js.map → feature-flags-B1rI-fjI.js.map} +1 -1
- package/dist/flags/FlagProvider.d.ts +1 -1
- package/dist/flags/feature-flags.d.ts +1 -1
- package/dist/flags/feature-flags.js +5 -5
- package/dist/flags/store.d.ts +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +7 -7
- package/dist/{init-CpYlmrSy.d.ts → init-CEa28dgv.d.ts} +3 -3
- package/dist/{init-8cDqgA8y.js → init-Da3dcKxi.js} +4 -4
- package/dist/{init-8cDqgA8y.js.map → init-Da3dcKxi.js.map} +1 -1
- package/dist/logger/DefaultLogger.js +4 -4
- package/dist/logger/Logger.js +4 -4
- package/dist/plugins/CompilerPlugin.d.ts +1 -1
- package/dist/plugins/PluginCommon.d.ts +1 -1
- package/dist/plugins/RuntimePlugin.d.ts +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +4 -4
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.d.ts +1 -1
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +4 -4
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.d.ts +1 -1
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.d.ts +1 -1
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +4 -4
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.d.ts +1 -1
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +4 -4
- package/dist/plugins/plugin-runtime/runtime.d.ts +1 -1
- package/dist/plugins/types.d.ts +1 -1
- package/dist/{type-checker-P8oyY259.js → type-checker-BgT1Ukbb.js} +2 -2
- package/dist/{type-checker-P8oyY259.js.map → type-checker-BgT1Ukbb.js.map} +1 -1
- package/dist/{types-C8GYFCIt.d.ts → types-CY8KcUfk.d.ts} +2 -2
- package/dist/{types-package-BpY3acyl.js → types-package-TSiYacaj.js} +1 -1
- package/dist/{types-package-BpY3acyl.js.map → types-package-TSiYacaj.js.map} +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/colors.d.ts +2 -2
- package/dist/utils/dev-hooks.d.ts +1 -1
- package/dist/utils/dev-hooks.js +4 -4
- package/dist/utils/types-package.js +1 -1
- package/dist/utils/utilities.js +4 -4
- package/dist/{utils-BjK-2R7h.d.ts → utils-PsznLC5X.d.ts} +2 -2
- package/dist/{version-rxKNvLPW.js → version-DiuoSTyi.js} +2 -2
- package/dist/{version-rxKNvLPW.js.map → version-DiuoSTyi.js.map} +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/dist/CommandKit-BwxIJqBr.js.map +0 -1
|
@@ -9,13 +9,13 @@ const require_CompilerPlugin = require('./CompilerPlugin-Bmy4izKz.js');
|
|
|
9
9
|
const require_RuntimePlugin = require('./RuntimePlugin-CehKbceZ.js');
|
|
10
10
|
const require_EventWorkerContext = require('./EventWorkerContext-DxfS_0fJ.js');
|
|
11
11
|
const require_resolve_file_url = require('./resolve-file-url-ifwdwqmq.js');
|
|
12
|
-
const
|
|
12
|
+
const require_types_package = require('./types-package-TSiYacaj.js');
|
|
13
13
|
const require_signals = require('./signals-CSSSZAZ6.js');
|
|
14
14
|
const require_constants$1 = require('./constants-CXwjhIYH.js');
|
|
15
|
-
const
|
|
15
|
+
const require_MessageCommandParser = require('./MessageCommandParser-ClkDMI8g.js');
|
|
16
16
|
const require_CommandsRouter = require('./CommandsRouter-DFRh47qD.js');
|
|
17
17
|
const require_EventsRouter = require('./EventsRouter-CqnrlbjN.js');
|
|
18
|
-
const require_common = require('./common-
|
|
18
|
+
const require_common = require('./common-D11Ax__S.js');
|
|
19
19
|
const require_CommandKitEventsChannel = require('./CommandKitEventsChannel-BL_YN3Rm.js');
|
|
20
20
|
const require_store = require('./store-x93NXUy_.js');
|
|
21
21
|
const node_events = require_chunk.__toESM(require("node:events"));
|
|
@@ -1804,167 +1804,6 @@ function createProxy(target) {
|
|
|
1804
1804
|
};
|
|
1805
1805
|
}
|
|
1806
1806
|
|
|
1807
|
-
//#endregion
|
|
1808
|
-
//#region src/app/register/CommandRegistrar.ts
|
|
1809
|
-
/**
|
|
1810
|
-
* Handles registration of Discord application commands (slash commands, context menus).
|
|
1811
|
-
*/
|
|
1812
|
-
var CommandRegistrar = class {
|
|
1813
|
-
/**
|
|
1814
|
-
* @private
|
|
1815
|
-
* @internal
|
|
1816
|
-
*/
|
|
1817
|
-
api = new discord_js.REST();
|
|
1818
|
-
/**
|
|
1819
|
-
* Creates an instance of CommandRegistrar.
|
|
1820
|
-
* @param commandkit The commandkit instance.
|
|
1821
|
-
*/
|
|
1822
|
-
constructor(commandkit$1) {
|
|
1823
|
-
this.commandkit = commandkit$1;
|
|
1824
|
-
this.api.setToken(this.commandkit.client.token ?? process.env.DISCORD_TOKEN ?? process.env.TOKEN ?? "");
|
|
1825
|
-
}
|
|
1826
|
-
/**
|
|
1827
|
-
* Gets the commands data.
|
|
1828
|
-
*/
|
|
1829
|
-
getCommandsData() {
|
|
1830
|
-
const handler = this.commandkit.commandHandler;
|
|
1831
|
-
const commands = handler.getCommandsArray();
|
|
1832
|
-
return commands.flatMap((cmd) => {
|
|
1833
|
-
const json$1 = "toJSON" in cmd.data.command ? cmd.data.command.toJSON() : cmd.data.command;
|
|
1834
|
-
const collections = [json$1];
|
|
1835
|
-
if (cmd.data.userContextMenu && json$1.type !== discord_js.ApplicationCommandType.User) collections.push({
|
|
1836
|
-
...json$1,
|
|
1837
|
-
type: discord_js.ApplicationCommandType.User,
|
|
1838
|
-
options: void 0,
|
|
1839
|
-
description_localizations: void 0,
|
|
1840
|
-
description: void 0
|
|
1841
|
-
});
|
|
1842
|
-
if (cmd.data.messageContextMenu && json$1.type !== discord_js.ApplicationCommandType.Message) collections.push({
|
|
1843
|
-
...json$1,
|
|
1844
|
-
type: discord_js.ApplicationCommandType.Message,
|
|
1845
|
-
description_localizations: void 0,
|
|
1846
|
-
description: void 0,
|
|
1847
|
-
options: void 0
|
|
1848
|
-
});
|
|
1849
|
-
return collections;
|
|
1850
|
-
});
|
|
1851
|
-
}
|
|
1852
|
-
/**
|
|
1853
|
-
* Registers loaded commands.
|
|
1854
|
-
*/
|
|
1855
|
-
async register() {
|
|
1856
|
-
const commands = this.getCommandsData();
|
|
1857
|
-
let preRegistrationPrevented = false;
|
|
1858
|
-
const preRegisterEvent = {
|
|
1859
|
-
preventDefault() {
|
|
1860
|
-
preRegistrationPrevented = true;
|
|
1861
|
-
},
|
|
1862
|
-
commands
|
|
1863
|
-
};
|
|
1864
|
-
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
1865
|
-
if (preRegistrationPrevented) return;
|
|
1866
|
-
return plugin.onBeforeRegisterCommands(ctx, preRegisterEvent);
|
|
1867
|
-
});
|
|
1868
|
-
if (preRegistrationPrevented) return;
|
|
1869
|
-
if (!this.commandkit.client.isReady()) throw new Error("Cannot register commands before the client is ready");
|
|
1870
|
-
const guildCommands = commands.filter((command) => {
|
|
1871
|
-
var _command$guilds;
|
|
1872
|
-
return (_command$guilds = command.guilds) === null || _command$guilds === void 0 ? void 0 : _command$guilds.filter(Boolean).length;
|
|
1873
|
-
}).map((c) => {
|
|
1874
|
-
var _c$guilds;
|
|
1875
|
-
return {
|
|
1876
|
-
...c,
|
|
1877
|
-
guilds: Array.from(new Set((_c$guilds = c.guilds) === null || _c$guilds === void 0 ? void 0 : _c$guilds.filter(Boolean)))
|
|
1878
|
-
};
|
|
1879
|
-
});
|
|
1880
|
-
const globalCommands = commands.filter((command) => {
|
|
1881
|
-
var _command$guilds2;
|
|
1882
|
-
return !((_command$guilds2 = command.guilds) === null || _command$guilds2 === void 0 ? void 0 : _command$guilds2.filter(Boolean).length);
|
|
1883
|
-
});
|
|
1884
|
-
await this.updateGlobalCommands(globalCommands);
|
|
1885
|
-
await this.updateGuildCommands(guildCommands);
|
|
1886
|
-
}
|
|
1887
|
-
/**
|
|
1888
|
-
* Updates the global commands.
|
|
1889
|
-
*/
|
|
1890
|
-
async updateGlobalCommands(commands) {
|
|
1891
|
-
if (!commands.length) return;
|
|
1892
|
-
let prevented = false;
|
|
1893
|
-
const preRegisterEvent = {
|
|
1894
|
-
preventDefault() {
|
|
1895
|
-
prevented = true;
|
|
1896
|
-
},
|
|
1897
|
-
commands
|
|
1898
|
-
};
|
|
1899
|
-
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
1900
|
-
if (prevented) return;
|
|
1901
|
-
return plugin.onBeforeRegisterGlobalCommands(ctx, preRegisterEvent);
|
|
1902
|
-
});
|
|
1903
|
-
try {
|
|
1904
|
-
const data = await this.api.put(discord_js.Routes.applicationCommands(this.commandkit.client.user.id), { body: commands.map((c) => ({
|
|
1905
|
-
...c,
|
|
1906
|
-
guilds: void 0
|
|
1907
|
-
})) });
|
|
1908
|
-
Logger.info(`✨ Refreshed ${data.length} global application (/) commands`);
|
|
1909
|
-
} catch (e) {
|
|
1910
|
-
Logger.error("Failed to update global application (/) commands", e);
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
/**
|
|
1914
|
-
* Updates the guild commands.
|
|
1915
|
-
*/
|
|
1916
|
-
async updateGuildCommands(commands) {
|
|
1917
|
-
if (!commands.length) return;
|
|
1918
|
-
let prevented = false;
|
|
1919
|
-
const preRegisterEvent = {
|
|
1920
|
-
preventDefault() {
|
|
1921
|
-
prevented = true;
|
|
1922
|
-
},
|
|
1923
|
-
commands
|
|
1924
|
-
};
|
|
1925
|
-
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
1926
|
-
if (prevented) return;
|
|
1927
|
-
return plugin.onBeforePrepareGuildCommandsRegistration(ctx, preRegisterEvent);
|
|
1928
|
-
});
|
|
1929
|
-
if (prevented) return;
|
|
1930
|
-
try {
|
|
1931
|
-
const guildCommandsMap = /* @__PURE__ */ new Map();
|
|
1932
|
-
commands.forEach((command) => {
|
|
1933
|
-
var _command$guilds3;
|
|
1934
|
-
if (!((_command$guilds3 = command.guilds) === null || _command$guilds3 === void 0 ? void 0 : _command$guilds3.length)) return;
|
|
1935
|
-
command.guilds.forEach((guild) => {
|
|
1936
|
-
if (!guildCommandsMap.has(guild)) guildCommandsMap.set(guild, []);
|
|
1937
|
-
guildCommandsMap.get(guild).push(command);
|
|
1938
|
-
});
|
|
1939
|
-
});
|
|
1940
|
-
if (!guildCommandsMap.size) return;
|
|
1941
|
-
let count = 0;
|
|
1942
|
-
for (const [guild, guildCommands] of guildCommandsMap) {
|
|
1943
|
-
let prevented$1 = false;
|
|
1944
|
-
const preRegisterEvent$1 = {
|
|
1945
|
-
preventDefault() {
|
|
1946
|
-
prevented$1 = true;
|
|
1947
|
-
},
|
|
1948
|
-
commands: guildCommands
|
|
1949
|
-
};
|
|
1950
|
-
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
1951
|
-
if (prevented$1) return;
|
|
1952
|
-
return plugin.onBeforeRegisterGuildCommands(ctx, preRegisterEvent$1);
|
|
1953
|
-
});
|
|
1954
|
-
if (prevented$1) continue;
|
|
1955
|
-
const data = await this.api.put(discord_js.Routes.applicationGuildCommands(this.commandkit.client.user.id, guild), { body: guildCommands.map((b) => ({
|
|
1956
|
-
...b,
|
|
1957
|
-
guilds: void 0
|
|
1958
|
-
})) });
|
|
1959
|
-
count += data.length;
|
|
1960
|
-
}
|
|
1961
|
-
Logger.info(`✨ Refreshed ${count} guild application (/) commands`);
|
|
1962
|
-
} catch (e) {
|
|
1963
|
-
Logger.error("Failed to update guild application (/) commands", e);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
};
|
|
1967
|
-
|
|
1968
1807
|
//#endregion
|
|
1969
1808
|
//#region src/context/environment.ts
|
|
1970
1809
|
/**
|
|
@@ -2616,6 +2455,167 @@ var AppCommandRunner = class {
|
|
|
2616
2455
|
}
|
|
2617
2456
|
};
|
|
2618
2457
|
|
|
2458
|
+
//#endregion
|
|
2459
|
+
//#region src/app/register/CommandRegistrar.ts
|
|
2460
|
+
/**
|
|
2461
|
+
* Handles registration of Discord application commands (slash commands, context menus).
|
|
2462
|
+
*/
|
|
2463
|
+
var CommandRegistrar = class {
|
|
2464
|
+
/**
|
|
2465
|
+
* @private
|
|
2466
|
+
* @internal
|
|
2467
|
+
*/
|
|
2468
|
+
api = new discord_js.REST();
|
|
2469
|
+
/**
|
|
2470
|
+
* Creates an instance of CommandRegistrar.
|
|
2471
|
+
* @param commandkit The commandkit instance.
|
|
2472
|
+
*/
|
|
2473
|
+
constructor(commandkit$1) {
|
|
2474
|
+
this.commandkit = commandkit$1;
|
|
2475
|
+
this.api.setToken(this.commandkit.client.token ?? process.env.DISCORD_TOKEN ?? process.env.TOKEN ?? "");
|
|
2476
|
+
}
|
|
2477
|
+
/**
|
|
2478
|
+
* Gets the commands data.
|
|
2479
|
+
*/
|
|
2480
|
+
getCommandsData() {
|
|
2481
|
+
const handler = this.commandkit.commandHandler;
|
|
2482
|
+
const commands = handler.getCommandsArray();
|
|
2483
|
+
return commands.flatMap((cmd) => {
|
|
2484
|
+
const json$1 = "toJSON" in cmd.data.command ? cmd.data.command.toJSON() : cmd.data.command;
|
|
2485
|
+
const collections = [json$1];
|
|
2486
|
+
if (cmd.data.userContextMenu && json$1.type !== discord_js.ApplicationCommandType.User) collections.push({
|
|
2487
|
+
...json$1,
|
|
2488
|
+
type: discord_js.ApplicationCommandType.User,
|
|
2489
|
+
options: void 0,
|
|
2490
|
+
description_localizations: void 0,
|
|
2491
|
+
description: void 0
|
|
2492
|
+
});
|
|
2493
|
+
if (cmd.data.messageContextMenu && json$1.type !== discord_js.ApplicationCommandType.Message) collections.push({
|
|
2494
|
+
...json$1,
|
|
2495
|
+
type: discord_js.ApplicationCommandType.Message,
|
|
2496
|
+
description_localizations: void 0,
|
|
2497
|
+
description: void 0,
|
|
2498
|
+
options: void 0
|
|
2499
|
+
});
|
|
2500
|
+
return collections;
|
|
2501
|
+
});
|
|
2502
|
+
}
|
|
2503
|
+
/**
|
|
2504
|
+
* Registers loaded commands.
|
|
2505
|
+
*/
|
|
2506
|
+
async register() {
|
|
2507
|
+
const commands = this.getCommandsData();
|
|
2508
|
+
let preRegistrationPrevented = false;
|
|
2509
|
+
const preRegisterEvent = {
|
|
2510
|
+
preventDefault() {
|
|
2511
|
+
preRegistrationPrevented = true;
|
|
2512
|
+
},
|
|
2513
|
+
commands
|
|
2514
|
+
};
|
|
2515
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
2516
|
+
if (preRegistrationPrevented) return;
|
|
2517
|
+
return plugin.onBeforeRegisterCommands(ctx, preRegisterEvent);
|
|
2518
|
+
});
|
|
2519
|
+
if (preRegistrationPrevented) return;
|
|
2520
|
+
if (!this.commandkit.client.isReady()) throw new Error("Cannot register commands before the client is ready");
|
|
2521
|
+
const guildCommands = commands.filter((command) => {
|
|
2522
|
+
var _command$guilds;
|
|
2523
|
+
return (_command$guilds = command.guilds) === null || _command$guilds === void 0 ? void 0 : _command$guilds.filter(Boolean).length;
|
|
2524
|
+
}).map((c) => {
|
|
2525
|
+
var _c$guilds;
|
|
2526
|
+
return {
|
|
2527
|
+
...c,
|
|
2528
|
+
guilds: Array.from(new Set((_c$guilds = c.guilds) === null || _c$guilds === void 0 ? void 0 : _c$guilds.filter(Boolean)))
|
|
2529
|
+
};
|
|
2530
|
+
});
|
|
2531
|
+
const globalCommands = commands.filter((command) => {
|
|
2532
|
+
var _command$guilds2;
|
|
2533
|
+
return !((_command$guilds2 = command.guilds) === null || _command$guilds2 === void 0 ? void 0 : _command$guilds2.filter(Boolean).length);
|
|
2534
|
+
});
|
|
2535
|
+
await this.updateGlobalCommands(globalCommands);
|
|
2536
|
+
await this.updateGuildCommands(guildCommands);
|
|
2537
|
+
}
|
|
2538
|
+
/**
|
|
2539
|
+
* Updates the global commands.
|
|
2540
|
+
*/
|
|
2541
|
+
async updateGlobalCommands(commands) {
|
|
2542
|
+
if (!commands.length) return;
|
|
2543
|
+
let prevented = false;
|
|
2544
|
+
const preRegisterEvent = {
|
|
2545
|
+
preventDefault() {
|
|
2546
|
+
prevented = true;
|
|
2547
|
+
},
|
|
2548
|
+
commands
|
|
2549
|
+
};
|
|
2550
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
2551
|
+
if (prevented) return;
|
|
2552
|
+
return plugin.onBeforeRegisterGlobalCommands(ctx, preRegisterEvent);
|
|
2553
|
+
});
|
|
2554
|
+
try {
|
|
2555
|
+
const data = await this.api.put(discord_js.Routes.applicationCommands(this.commandkit.client.user.id), { body: commands.map((c) => ({
|
|
2556
|
+
...c,
|
|
2557
|
+
guilds: void 0
|
|
2558
|
+
})) });
|
|
2559
|
+
Logger.info(`✨ Refreshed ${data.length} global application (/) commands`);
|
|
2560
|
+
} catch (e) {
|
|
2561
|
+
Logger.error("Failed to update global application (/) commands", e);
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
/**
|
|
2565
|
+
* Updates the guild commands.
|
|
2566
|
+
*/
|
|
2567
|
+
async updateGuildCommands(commands) {
|
|
2568
|
+
if (!commands.length) return;
|
|
2569
|
+
let prevented = false;
|
|
2570
|
+
const preRegisterEvent = {
|
|
2571
|
+
preventDefault() {
|
|
2572
|
+
prevented = true;
|
|
2573
|
+
},
|
|
2574
|
+
commands
|
|
2575
|
+
};
|
|
2576
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
2577
|
+
if (prevented) return;
|
|
2578
|
+
return plugin.onBeforePrepareGuildCommandsRegistration(ctx, preRegisterEvent);
|
|
2579
|
+
});
|
|
2580
|
+
if (prevented) return;
|
|
2581
|
+
try {
|
|
2582
|
+
const guildCommandsMap = /* @__PURE__ */ new Map();
|
|
2583
|
+
commands.forEach((command) => {
|
|
2584
|
+
var _command$guilds3;
|
|
2585
|
+
if (!((_command$guilds3 = command.guilds) === null || _command$guilds3 === void 0 ? void 0 : _command$guilds3.length)) return;
|
|
2586
|
+
command.guilds.forEach((guild) => {
|
|
2587
|
+
if (!guildCommandsMap.has(guild)) guildCommandsMap.set(guild, []);
|
|
2588
|
+
guildCommandsMap.get(guild).push(command);
|
|
2589
|
+
});
|
|
2590
|
+
});
|
|
2591
|
+
if (!guildCommandsMap.size) return;
|
|
2592
|
+
let count = 0;
|
|
2593
|
+
for (const [guild, guildCommands] of guildCommandsMap) {
|
|
2594
|
+
let prevented$1 = false;
|
|
2595
|
+
const preRegisterEvent$1 = {
|
|
2596
|
+
preventDefault() {
|
|
2597
|
+
prevented$1 = true;
|
|
2598
|
+
},
|
|
2599
|
+
commands: guildCommands
|
|
2600
|
+
};
|
|
2601
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
2602
|
+
if (prevented$1) return;
|
|
2603
|
+
return plugin.onBeforeRegisterGuildCommands(ctx, preRegisterEvent$1);
|
|
2604
|
+
});
|
|
2605
|
+
if (prevented$1) continue;
|
|
2606
|
+
const data = await this.api.put(discord_js.Routes.applicationGuildCommands(this.commandkit.client.user.id, guild), { body: guildCommands.map((b) => ({
|
|
2607
|
+
...b,
|
|
2608
|
+
guilds: void 0
|
|
2609
|
+
})) });
|
|
2610
|
+
count += data.length;
|
|
2611
|
+
}
|
|
2612
|
+
Logger.info(`✨ Refreshed ${count} guild application (/) commands`);
|
|
2613
|
+
} catch (e) {
|
|
2614
|
+
Logger.error("Failed to update guild application (/) commands", e);
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
};
|
|
2618
|
+
|
|
2619
2619
|
//#endregion
|
|
2620
2620
|
//#region src/app/handlers/AppCommandHandler.ts
|
|
2621
2621
|
/**
|
|
@@ -2965,30 +2965,34 @@ var AppCommandHandler = class {
|
|
|
2965
2965
|
command,
|
|
2966
2966
|
data: { command: {
|
|
2967
2967
|
name: command.name,
|
|
2968
|
-
description: `${command.name}
|
|
2968
|
+
description: `${command.name} command`,
|
|
2969
2969
|
type: 1
|
|
2970
2970
|
} }
|
|
2971
2971
|
});
|
|
2972
2972
|
return;
|
|
2973
2973
|
}
|
|
2974
|
-
const
|
|
2975
|
-
if (!
|
|
2974
|
+
const commandFileData = await import(`${require_resolve_file_url.toFileURL(command.path)}?t=${Date.now()}`);
|
|
2975
|
+
if (!commandFileData.command) throw new Error(`Invalid export for command ${command.name}: no command definition found`);
|
|
2976
|
+
if ((!commandFileData.command.type || commandFileData.command.type === discord_js.ApplicationCommandType.ChatInput) && !commandFileData.command.description) commandFileData.command.description = `${command.name} command`;
|
|
2976
2977
|
let handlerCount = 0;
|
|
2977
|
-
for (const [key,
|
|
2978
|
-
|
|
2979
|
-
if (
|
|
2978
|
+
for (const [key, propValidator] of Object.entries(commandDataSchema)) {
|
|
2979
|
+
const exportedProp = commandFileData[key];
|
|
2980
|
+
if (exportedProp) {
|
|
2981
|
+
if (!await propValidator(exportedProp)) throw new Error(`Invalid export for command ${command.name}: ${key} does not match expected value`);
|
|
2982
|
+
if (key !== "command") handlerCount++;
|
|
2983
|
+
}
|
|
2980
2984
|
}
|
|
2981
2985
|
if (handlerCount === 0) throw new Error(`Invalid export for command ${command.name}: at least one handler function must be provided`);
|
|
2982
|
-
let lastUpdated =
|
|
2986
|
+
let lastUpdated = commandFileData.command;
|
|
2983
2987
|
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
2984
2988
|
const res = await plugin.prepareCommand(ctx, lastUpdated);
|
|
2985
2989
|
if (res) lastUpdated = res;
|
|
2986
2990
|
});
|
|
2987
2991
|
this.loadedCommands.set(id, {
|
|
2988
2992
|
command,
|
|
2989
|
-
guilds:
|
|
2993
|
+
guilds: commandFileData.command.guilds,
|
|
2990
2994
|
data: {
|
|
2991
|
-
...
|
|
2995
|
+
...commandFileData,
|
|
2992
2996
|
command: "toJSON" in lastUpdated ? lastUpdated.toJSON() : lastUpdated
|
|
2993
2997
|
}
|
|
2994
2998
|
});
|
|
@@ -4131,4 +4135,4 @@ Object.defineProperty(exports, 'useEnvironment', {
|
|
|
4131
4135
|
return useEnvironment;
|
|
4132
4136
|
}
|
|
4133
4137
|
});
|
|
4134
|
-
//# sourceMappingURL=CommandKit-
|
|
4138
|
+
//# sourceMappingURL=CommandKit-CT3K-Cac.js.map
|