Skip to content

Commit 8f576c0

Browse files
committed
Add /walkthrough command. (#6)
1 parent 2ec642b commit 8f576c0

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

lib/discord/interactions/commands/commands.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import "package:codercord/discord/client.dart" show logger;
33
import "tag.dart" as command_tag;
44
import "close.dart" as command_close;
55
import "reopen.dart" as command_reopen;
6+
import "walkthrough.dart" as command_walkthrough;
67

78
import "package:nyxx_interactions/nyxx_interactions.dart";
89

@@ -11,6 +12,7 @@ Future<List<SlashCommandBuilder>> getSlashCommands() async {
1112
command_tag.getCommand(await command_tag.getTags()),
1213
command_close.getCommand(),
1314
command_reopen.getCommand(),
15+
command_walkthrough.getCommand()
1416
];
1517
}
1618

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import "package:codercord/discord/components/category_multi_select.dart";
2+
import "package:codercord/discord/interactions/commands/close.dart";
3+
import "package:codercord/discord/utils.dart";
4+
import "package:codercord/values.dart";
5+
6+
import "package:nyxx/nyxx.dart";
7+
8+
import "package:nyxx_interactions/nyxx_interactions.dart";
9+
10+
SlashCommandBuilder getCommand() {
11+
return SlashCommandBuilder(
12+
"walkthrough",
13+
"Sends the walkthrough message in case the bot didn't send it",
14+
[],
15+
guild: coderServer.id,
16+
canBeUsedInDm: false,
17+
)..registerHandler((p0) async {
18+
final interactionChannel = await p0.interaction.channel.getOrDownload();
19+
20+
if (interactionChannel.channelType == ChannelType.guildPublicThread) {
21+
final threadChannel = interactionChannel as IThreadChannel;
22+
23+
if (await threadChannel.isHelpPost) {
24+
if (threadChannel.appliedTags.isEmpty) {
25+
await threadChannel.setPostTags([openedTagID]);
26+
}
27+
28+
final channelMessages = threadChannel.downloadMessages(
29+
limit: 10,
30+
around: Snowflake.fromDateTime(threadChannel.createdAt),
31+
);
32+
33+
try {
34+
IMessage walkthroughMessage = await channelMessages.firstWhere(
35+
(message) =>
36+
message.author.id == (p0.client as INyxxWebsocket).self.id &&
37+
(message.components.isNotEmpty || message.embeds.isNotEmpty),
38+
);
39+
40+
await p0.respond(
41+
MessageBuilder.content(
42+
"You cannot run the walkthrough again because a walkthrough already exists in this channel\n(${walkthroughMessage.url})",
43+
),
44+
hidden: true);
45+
} on StateError catch (_) {
46+
p0.respond(categoryMultiSelectMessage);
47+
}
48+
}
49+
}
50+
});
51+
}

0 commit comments

Comments
 (0)