Skip to content

Commit 53091ca

Browse files
committed
Remove distinction
1 parent cc1af3f commit 53091ca

4 files changed

Lines changed: 19 additions & 29 deletions

File tree

src/commands/hilfe.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ export default class HilfeCommand implements MessageCommand {
1616
const prefix = context.prefix.command;
1717

1818
const lines = [];
19-
const newCommands = await commandService.readAvailableCommands(context, ["normal"]);
19+
const newCommands = await commandService.readAvailableCommands(context);
2020
for (const command of newCommands) {
21+
if (command.modCommand) {
22+
continue;
23+
}
24+
2125
// TODO: Hack to exclude faulenzerping and video download
2226
if (
2327
"applicationCommand" in command &&

src/commands/modcommands/modhilfe.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ export default class ModHilfeCommand implements MessageCommand {
1515
const prefix = context.prefix.modCommand;
1616

1717
const lines = [];
18-
const newCommands = await commandService.readAvailableCommands(context, ["mod"]);
18+
const newCommands = await commandService.readAvailableCommands(context);
1919
for (const command of newCommands) {
20+
if (!command.modCommand) {
21+
continue;
22+
}
23+
2024
const commandStr = prefix + command.name;
2125
lines.push(
2226
`${commandStr}: ${replacePrefixPlaceholders(command.description, context)}\n`,

src/handler/commandHandler.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,14 @@ const getMessageCommands = (modCommand: boolean) =>
5050
const latestSpecialCommandInvocations: Record<string, number> = {};
5151

5252
export const loadCommands = async (context: BotContext): Promise<void> => {
53-
const availableCommands = await commandService.readAvailableCommands(context, [
54-
"mod",
55-
"normal",
56-
]);
53+
const availableCommands = await commandService.readAvailableCommands(context);
5754

58-
// We also respect the modCommand flag, so we can load .hilfe and ~hilfe
59-
const loadedCommandNames = new Set(
60-
staticCommands.map(c => `${c.name}-${c.modCommand ?? false}`),
61-
);
55+
const loadedCommandNames = new Set(staticCommands.map(c => c.name));
6256

6357
const dynamicCommands = [];
6458
for (const instance of availableCommands) {
65-
const loadedName = `${instance.name}-${instance.modCommand ?? false}`;
66-
if (loadedCommandNames.has(loadedName)) {
67-
log.debug(`Command "${loadedName}" is already loaded, skipping`);
59+
if (loadedCommandNames.has(instance.name)) {
60+
log.debug(`Command "${instance.name}" is already loaded, skipping`);
6861
continue;
6962
}
7063

src/service/command.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,11 @@ import log from "#log";
1212
const commandExtensions = [".ts", ".js"];
1313
const ignoredExtensions = [".spec.ts", ".test.ts", ".d.ts", ".test.js", ".spec.js"];
1414

15-
export type CommandKind = "mod" | "normal";
16-
17-
export async function readAvailableCommands(
18-
context: BotContext,
19-
kinds: readonly CommandKind[],
20-
): Promise<Command[]> {
21-
const modules = [];
22-
23-
if (kinds.includes("mod")) {
24-
const modCommands = await loadRawCommandModulesFromDirectory(context.path.modCommands);
25-
modules.push(...modCommands);
26-
}
27-
if (kinds.includes("normal")) {
28-
const commands = await loadRawCommandModulesFromDirectory(context.path.commands);
29-
modules.push(...commands);
30-
}
15+
export async function readAvailableCommands(context: BotContext): Promise<Command[]> {
16+
const modules = [
17+
...(await loadRawCommandModulesFromDirectory(context.path.modCommands)),
18+
...(await loadRawCommandModulesFromDirectory(context.path.commands)),
19+
];
3120

3221
const res = [];
3322
for (const { module } of modules) {

0 commit comments

Comments
 (0)