|
| 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