Skip to content

Commit 670fd2a

Browse files
committed
refactor(cli): simplify message action registration
1 parent b6df91f commit 670fd2a

10 files changed

Lines changed: 53 additions & 117 deletions

‎src/cli/program/message/register.broadcast.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ export function registerMessageBroadcastCommand(message: Command, helpers: Messa
1212
.requiredOption("--targets <target...>", CHANNEL_TARGETS_DESCRIPTION)
1313
.option("--message <text>", "Message to send")
1414
.option("--media <url>", "Media URL")
15-
.action(async (options: Record<string, unknown>) => {
16-
await helpers.runMessageAction("broadcast", options);
17-
});
15+
.action((options: Record<string, unknown>) => helpers.runMessageAction("broadcast", options));
1816
}

‎src/cli/program/message/register.discord-admin.ts‎

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
99
.withMessageBase(
1010
role.command("info").description("List roles").requiredOption("--guild-id <id>", "Guild id"),
1111
)
12-
.action(async (opts) => {
13-
await helpers.runMessageAction("role-info", opts);
14-
});
12+
.action((opts) => helpers.runMessageAction("role-info", opts));
1513

1614
helpers
1715
.withMessageBase(
@@ -22,9 +20,7 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
2220
.requiredOption("--user-id <id>", "User id")
2321
.requiredOption("--role-id <id>", "Role id"),
2422
)
25-
.action(async (opts) => {
26-
await helpers.runMessageAction("role-add", opts);
27-
});
23+
.action((opts) => helpers.runMessageAction("role-add", opts));
2824

2925
helpers
3026
.withMessageBase(
@@ -35,18 +31,14 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
3531
.requiredOption("--user-id <id>", "User id")
3632
.requiredOption("--role-id <id>", "Role id"),
3733
)
38-
.action(async (opts) => {
39-
await helpers.runMessageAction("role-remove", opts);
40-
});
34+
.action((opts) => helpers.runMessageAction("role-remove", opts));
4135

4236
const channel = message.command("channel").description("Channel actions");
4337
helpers
4438
.withMessageBase(
4539
helpers.withRequiredMessageTarget(channel.command("info").description("Fetch channel info")),
4640
)
47-
.action(async (opts) => {
48-
await helpers.runMessageAction("channel-info", opts);
49-
});
41+
.action((opts) => helpers.runMessageAction("channel-info", opts));
5042

5143
helpers
5244
.withMessageBase(
@@ -55,9 +47,7 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
5547
.description("List channels")
5648
.requiredOption("--guild-id <id>", "Guild id"),
5749
)
58-
.action(async (opts) => {
59-
await helpers.runMessageAction("channel-list", opts);
60-
});
50+
.action((opts) => helpers.runMessageAction("channel-list", opts));
6151

6252
const member = message.command("member").description("Member actions");
6353
helpers
@@ -68,9 +58,7 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
6858
.requiredOption("--user-id <id>", "User id"),
6959
)
7060
.option("--guild-id <id>", "Guild id (Discord)")
71-
.action(async (opts) => {
72-
await helpers.runMessageAction("member-info", opts);
73-
});
61+
.action((opts) => helpers.runMessageAction("member-info", opts));
7462

7563
const voice = message.command("voice").description("Voice actions");
7664
helpers
@@ -81,9 +69,7 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
8169
.requiredOption("--guild-id <id>", "Guild id")
8270
.requiredOption("--user-id <id>", "User id"),
8371
)
84-
.action(async (opts) => {
85-
await helpers.runMessageAction("voice-status", opts);
86-
});
72+
.action((opts) => helpers.runMessageAction("voice-status", opts));
8773

8874
const event = message.command("event").description("Event actions");
8975
helpers
@@ -93,9 +79,7 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
9379
.description("List scheduled events")
9480
.requiredOption("--guild-id <id>", "Guild id"),
9581
)
96-
.action(async (opts) => {
97-
await helpers.runMessageAction("event-list", opts);
98-
});
82+
.action((opts) => helpers.runMessageAction("event-list", opts));
9983

10084
helpers
10185
.withMessageBase(
@@ -112,9 +96,7 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
11296
.option("--location <text>", "Event location")
11397
.option("--event-type <stage|external|voice>", "Event type")
11498
.option("--image <url>", "Cover image URL or local file path")
115-
.action(async (opts) => {
116-
await helpers.runMessageAction("event-create", opts);
117-
});
99+
.action((opts) => helpers.runMessageAction("event-create", opts));
118100

119101
helpers
120102
.withMessageBase(
@@ -127,9 +109,7 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
127109
.option("--duration-min <n>", "Timeout duration minutes")
128110
.option("--until <iso>", "Timeout until")
129111
.option("--reason <text>", "Moderation reason")
130-
.action(async (opts) => {
131-
await helpers.runMessageAction("timeout", opts);
132-
});
112+
.action((opts) => helpers.runMessageAction("timeout", opts));
133113

134114
helpers
135115
.withMessageBase(
@@ -140,9 +120,7 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
140120
.requiredOption("--user-id <id>", "User id"),
141121
)
142122
.option("--reason <text>", "Moderation reason")
143-
.action(async (opts) => {
144-
await helpers.runMessageAction("kick", opts);
145-
});
123+
.action((opts) => helpers.runMessageAction("kick", opts));
146124

147125
helpers
148126
.withMessageBase(
@@ -154,7 +132,5 @@ export function registerMessageDiscordAdminCommands(message: Command, helpers: M
154132
)
155133
.option("--reason <text>", "Moderation reason")
156134
.option("--delete-days <n>", "Ban delete message days")
157-
.action(async (opts) => {
158-
await helpers.runMessageAction("ban", opts);
159-
});
135+
.action((opts) => helpers.runMessageAction("ban", opts));
160136
}

‎src/cli/program/message/register.emoji-sticker.ts‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ export function registerMessageEmojiCommands(message: Command, helpers: MessageC
1010
helpers
1111
.withMessageBase(emoji.command("list").description("List emojis"))
1212
.option("--guild-id <id>", "Guild id (Discord)")
13-
.action(async (opts) => {
14-
await helpers.runMessageAction("emoji-list", opts);
15-
});
13+
.action((opts) => helpers.runMessageAction("emoji-list", opts));
1614

1715
helpers
1816
.withMessageBase(
@@ -24,9 +22,7 @@ export function registerMessageEmojiCommands(message: Command, helpers: MessageC
2422
.requiredOption("--emoji-name <name>", "Emoji name")
2523
.requiredOption("--media <path-or-url>", "Emoji media (path or URL)")
2624
.option("--role-ids <id>", "Role id (repeat)", collectOption, [] as string[])
27-
.action(async (opts) => {
28-
await helpers.runMessageAction("emoji-upload", opts);
29-
});
25+
.action((opts) => helpers.runMessageAction("emoji-upload", opts));
3026
}
3127

3228
/** Register sticker send/upload commands. */
@@ -39,9 +35,7 @@ export function registerMessageStickerCommands(message: Command, helpers: Messag
3935
)
4036
.requiredOption("--sticker-id <id>", "Sticker id (repeat)", collectOption)
4137
.option("-m, --message <text>", "Optional message body")
42-
.action(async (opts) => {
43-
await helpers.runMessageAction("sticker", opts);
44-
});
38+
.action((opts) => helpers.runMessageAction("sticker", opts));
4539

4640
helpers
4741
.withMessageBase(
@@ -54,7 +48,5 @@ export function registerMessageStickerCommands(message: Command, helpers: Messag
5448
.requiredOption("--sticker-desc <text>", "Sticker description")
5549
.requiredOption("--sticker-tags <tags>", "Sticker tags")
5650
.requiredOption("--media <path-or-url>", "Sticker media (path or URL)")
57-
.action(async (opts) => {
58-
await helpers.runMessageAction("sticker-upload", opts);
59-
});
51+
.action((opts) => helpers.runMessageAction("sticker-upload", opts));
6052
}

‎src/cli/program/message/register.permissions-search.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ export function registerMessagePermissionsCommand(message: Command, helpers: Mes
1111
message.command("permissions").description("Fetch channel permissions"),
1212
),
1313
)
14-
.action(async (opts) => {
15-
await helpers.runMessageAction("permissions", opts);
16-
});
14+
.action((opts) => helpers.runMessageAction("permissions", opts));
1715
}
1816

1917
/** Register Discord message search command and repeatable filters. */
@@ -27,7 +25,5 @@ export function registerMessageSearchCommand(message: Command, helpers: MessageC
2725
.option("--author-id <id>", "Author id")
2826
.option("--author-ids <id>", "Author id (repeat)", collectOption, [] as string[])
2927
.option("--limit <n>", "Result limit")
30-
.action(async (opts) => {
31-
await helpers.runMessageAction("search", opts);
32-
});
28+
.action((opts) => helpers.runMessageAction("search", opts));
3329
}

‎src/cli/program/message/register.pins.ts‎

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,30 @@ import type { MessageCliHelpers } from "./helpers.js";
44

55
/** Register message pin management commands. */
66
export function registerMessagePinCommands(message: Command, helpers: MessageCliHelpers) {
7-
const pins = [
8-
helpers
9-
.withMessageBase(
10-
helpers.withRequiredMessageTarget(message.command("pin").description("Pin a message")),
11-
)
12-
.requiredOption("--message-id <id>", "Message id")
13-
.action(async (opts) => {
14-
await helpers.runMessageAction("pin", opts);
15-
}),
16-
helpers
17-
.withMessageBase(
18-
helpers.withRequiredMessageTarget(message.command("unpin").description("Unpin a message")),
19-
)
20-
.requiredOption("--message-id <id>", "Message id (or pinned message resource id for MSTeams)")
21-
.option(
22-
"--pinned-message-id <id>",
23-
"Pinned message resource id (MSTeams: from pin or list-pins, not the chat message id)",
24-
)
25-
.action(async (opts) => {
26-
await helpers.runMessageAction("unpin", opts);
27-
}),
28-
helpers
29-
.withMessageBase(
30-
helpers.withRequiredMessageTarget(
31-
message.command("pins").description("List pinned messages"),
32-
),
33-
)
34-
.option("--limit <n>", "Result limit")
35-
.action(async (opts) => {
36-
await helpers.runMessageAction("list-pins", opts);
37-
}),
38-
] as const;
7+
helpers
8+
.withMessageBase(
9+
helpers.withRequiredMessageTarget(message.command("pin").description("Pin a message")),
10+
)
11+
.requiredOption("--message-id <id>", "Message id")
12+
.action((opts) => helpers.runMessageAction("pin", opts));
3913

40-
void pins;
14+
helpers
15+
.withMessageBase(
16+
helpers.withRequiredMessageTarget(message.command("unpin").description("Unpin a message")),
17+
)
18+
.requiredOption("--message-id <id>", "Message id (or pinned message resource id for MSTeams)")
19+
.option(
20+
"--pinned-message-id <id>",
21+
"Pinned message resource id (MSTeams: from pin or list-pins, not the chat message id)",
22+
)
23+
.action((opts) => helpers.runMessageAction("unpin", opts));
24+
25+
helpers
26+
.withMessageBase(
27+
helpers.withRequiredMessageTarget(
28+
message.command("pins").description("List pinned messages"),
29+
),
30+
)
31+
.option("--limit <n>", "Result limit")
32+
.action((opts) => helpers.runMessageAction("list-pins", opts));
4133
}

‎src/cli/program/message/register.poll.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,5 @@ export function registerMessagePollCommand(message: Command, helpers: MessageCli
2828
false,
2929
)
3030
.option("--thread-id <id>", "Thread id (Telegram forum topic / Slack thread ts)")
31-
.action(async (opts) => {
32-
await helpers.runMessageAction("poll", opts);
33-
});
31+
.action((opts) => helpers.runMessageAction("poll", opts));
3432
}

‎src/cli/program/message/register.reactions.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ export function registerMessageReactionsCommands(message: Command, helpers: Mess
1717
.option("--from-me", "WhatsApp reaction fromMe", false)
1818
.option("--target-author <id>", "Signal reaction target author (uuid or phone)")
1919
.option("--target-author-uuid <uuid>", "Signal reaction target author uuid")
20-
.action(async (opts) => {
21-
await helpers.runMessageAction("react", opts);
22-
});
20+
.action((opts) => helpers.runMessageAction("react", opts));
2321

2422
helpers
2523
.withMessageBase(
@@ -29,7 +27,5 @@ export function registerMessageReactionsCommands(message: Command, helpers: Mess
2927
)
3028
.requiredOption("--message-id <id>", "Message id")
3129
.option("--limit <n>", "Result limit")
32-
.action(async (opts) => {
33-
await helpers.runMessageAction("reactions", opts);
34-
});
30+
.action((opts) => helpers.runMessageAction("reactions", opts));
3531
}

‎src/cli/program/message/register.read-edit-delete.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ export function registerMessageReadEditDeleteCommands(
2020
.option("--around <id>", "Read around id")
2121
.option("--thread-id <id>", "Thread id (Slack thread timestamp)")
2222
.option("--include-thread", "Include thread replies (Discord)", false)
23-
.action(async (opts) => {
24-
await helpers.runMessageAction("read", opts);
25-
});
23+
.action((opts) => helpers.runMessageAction("read", opts));
2624

2725
helpers
2826
.withMessageBase(
@@ -35,9 +33,7 @@ export function registerMessageReadEditDeleteCommands(
3533
),
3634
)
3735
.option("--thread-id <id>", "Thread id (Telegram forum thread)")
38-
.action(async (opts) => {
39-
await helpers.runMessageAction("edit", opts);
40-
});
36+
.action((opts) => helpers.runMessageAction("edit", opts));
4137

4238
helpers
4339
.withMessageBase(
@@ -48,7 +44,5 @@ export function registerMessageReadEditDeleteCommands(
4844
.requiredOption("--message-id <id>", "Message id"),
4945
),
5046
)
51-
.action(async (opts) => {
52-
await helpers.runMessageAction("delete", opts);
53-
});
47+
.action((opts) => helpers.runMessageAction("delete", opts));
5448
}

‎src/cli/program/message/register.send.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,5 @@ export function registerMessageSendCommand(message: Command, helpers: MessageCli
4040
false,
4141
),
4242
)
43-
.action(async (opts) => {
44-
await helpers.runMessageAction("send", opts);
45-
});
43+
.action((opts) => helpers.runMessageAction("send", opts));
4644
}

‎src/cli/program/message/register.thread.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ export function registerMessageThreadCommands(message: Command, helpers: Message
5757
.option("--include-archived", "Include archived threads", false)
5858
.option("--before <id>", "Read/search before id")
5959
.option("--limit <n>", "Result limit")
60-
.action(async (opts) => {
61-
await helpers.runMessageAction("thread-list", opts);
62-
});
60+
.action((opts) => helpers.runMessageAction("thread-list", opts));
6361

6462
helpers
6563
.withMessageBase(
@@ -75,7 +73,5 @@ export function registerMessageThreadCommands(message: Command, helpers: Message
7573
"Attach media (image/audio/video/document). Accepts local paths or URLs.",
7674
)
7775
.option("--reply-to <id>", "Reply-to message id")
78-
.action(async (opts) => {
79-
await helpers.runMessageAction("thread-reply", opts);
80-
});
76+
.action((opts) => helpers.runMessageAction("thread-reply", opts));
8177
}

0 commit comments

Comments
 (0)