From 471b12d591a4303ae5f9ebef22c9313d3701a878 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 6 May 2023 14:35:15 +0100 Subject: [PATCH 01/10] Forums: Tag management commands --- .idea/modules.xml | 2 + .../modes/quilt/extensions/ForumExtension.kt | 116 +++++++++++++++++- 2 files changed, 112 insertions(+), 6 deletions(-) diff --git a/.idea/modules.xml b/.idea/modules.xml index de6965c4..9f8a802d 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,6 +2,8 @@ + + diff --git a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt index d9911e67..c9eecdf0 100644 --- a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt +++ b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt @@ -12,8 +12,11 @@ package org.quiltmc.community.modes.quilt.extensions import com.kotlindiscord.kord.extensions.checks.hasRole import com.kotlindiscord.kord.extensions.checks.or import com.kotlindiscord.kord.extensions.commands.Arguments +import com.kotlindiscord.kord.extensions.commands.application.slash.ephemeralSubCommand import com.kotlindiscord.kord.extensions.commands.converters.impl.channel import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalChannel +import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalTag +import com.kotlindiscord.kord.extensions.commands.converters.impl.tag import com.kotlindiscord.kord.extensions.components.forms.ModalForm import com.kotlindiscord.kord.extensions.extensions.Extension import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand @@ -21,6 +24,7 @@ import com.kotlindiscord.kord.extensions.modules.unsafe.annotations.UnsafeAPI import com.kotlindiscord.kord.extensions.modules.unsafe.extensions.unsafeSubCommand import com.kotlindiscord.kord.extensions.modules.unsafe.types.InitialSlashCommandResponse import com.kotlindiscord.kord.extensions.modules.unsafe.types.ackEphemeral +import com.kotlindiscord.kord.extensions.types.respond import com.kotlindiscord.kord.extensions.utils.extraData import dev.kord.common.annotation.KordUnsafe import dev.kord.common.entity.ChannelType @@ -31,6 +35,7 @@ import dev.kord.core.behavior.edit import dev.kord.core.behavior.interaction.modal import dev.kord.core.behavior.interaction.response.createEphemeralFollowup import dev.kord.core.entity.channel.ForumChannel +import dev.kord.core.entity.channel.thread.TextChannelThread import dev.kord.core.entity.channel.thread.ThreadChannel import kotlinx.coroutines.delay import org.quiltmc.community.* @@ -58,7 +63,7 @@ class ForumExtension : Extension() { } } - unsafeSubCommand(::ForumChannelArgs) { + unsafeSubCommand(::CreatePostArgs) { name = "create-post" description = "Create a Cozy-managed forum post" @@ -112,9 +117,11 @@ class ForumExtension : Extension() { } val thread = forum.startPublicThread(title) { - // TODO: Tags? - message(text) + + if (arguments.tag != null) { + appliedTags = mutableListOf(arguments.tag!!.id) + } } interactionResponse.createEphemeralFollowup { @@ -147,7 +154,7 @@ class ForumExtension : Extension() { } } - unsafeSubCommand(::ForumPostArgs) { + unsafeSubCommand(::EditPostArgs) { name = "edit-post" description = "Edit an existing Cozy-managed forum post" @@ -230,19 +237,116 @@ class ForumExtension : Extension() { } } } + + ephemeralSubCommand(::PostTagArgs) { + name = "add-tag" + description = "Add a tag to the given post" + + action { + val post = arguments.post.asChannelOfOrNull() + val parent = post?.parent?.asChannelOfOrNull() + + if (parent == null) { + respond { + content = "Please provide a forum thread to edit the tags for." + } + + return@action + } + + if (post.appliedTags.contains(arguments.tag.id)) { + respond { + content = "This thread already has that tag applied." + } + + return@action + } + + post.edit { + appliedTags = post.appliedTags.toMutableList() + appliedTags?.add(arguments.tag.id) + } + + respond { + content = "Thread tags updated." + } + } + } + + ephemeralSubCommand(::PostTagArgs) { + name = "remove-tag" + description = "Remove a tag from the given post" + + action { + val post = arguments.post.asChannelOfOrNull() + val parent = post?.parent?.asChannelOfOrNull() + + if (parent == null) { + respond { + content = "Please provide a forum thread to edit the tags for." + } + + return@action + } + + if (!post.appliedTags.contains(arguments.tag.id)) { + respond { + content = "This thread doesn't have that tag applied." + } + + return@action + } + + post.edit { + appliedTags = post.appliedTags.toMutableList() + appliedTags?.remove(arguments.tag.id) + } + + respond { + content = "Thread tags updated." + } + } + } } } - inner class ForumChannelArgs : Arguments() { + inner class PostTagArgs : Arguments() { + override val parseForAutocomplete: Boolean = true + + val post by channel { + name = "post" + description = "Thread to edit the tags for" + + requireChannelType(ChannelType.PublicGuildThread) + } + + val tag by tag { + name = "tag" + description = "Tag to create the post with" + + channelGetter = { post.asChannelOfOrNull()?.parent?.asChannelOfOrNull() } + } + } + + inner class CreatePostArgs : Arguments() { + override val parseForAutocomplete: Boolean = true + val channel by channel { name = "channel" description = "Forum channel to post in" requireChannelType(ChannelType.GuildForum) } + + val tag by optionalTag { + name = "tag" + description = "Tag to create the post with" + + channelGetter = { channel.asChannelOfOrNull() } + } } - inner class ForumPostArgs : Arguments() { + inner class EditPostArgs : Arguments() { val post by optionalChannel { name = "post" description = "Thread to edit the first post for" From 87230437422b46b80ce6849c9f7ce1909c7e47e7 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 6 May 2023 14:41:55 +0100 Subject: [PATCH 02/10] Forums: Handle tag restrictions --- .../modes/quilt/extensions/ForumExtension.kt | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt index c9eecdf0..831d1c75 100644 --- a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt +++ b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt @@ -27,6 +27,7 @@ import com.kotlindiscord.kord.extensions.modules.unsafe.types.ackEphemeral import com.kotlindiscord.kord.extensions.types.respond import com.kotlindiscord.kord.extensions.utils.extraData import dev.kord.common.annotation.KordUnsafe +import dev.kord.common.entity.ChannelFlag import dev.kord.common.entity.ChannelType import dev.kord.core.behavior.channel.asChannelOfOrNull import dev.kord.core.behavior.channel.createMessage @@ -81,6 +82,14 @@ class ForumExtension : Extension() { return@action } + if (forum.flags?.contains(ChannelFlag.RequireTag) == true && arguments.tag == null) { + ackEphemeral { + content = "This forum requires that you provide an initial tag for the post." + } + + return@action + } + if (isDeveloper && forum.categoryId != COMMUNITY_DEVELOPER_CATEGORY) { ackEphemeral { content = "Quilt Developers may only use this command to create posts in the developer " + @@ -172,8 +181,8 @@ class ForumExtension : Extension() { if (parent == null) { ackEphemeral { - content = "Please provide a forum thread to edit the first post for, or run this " + - "command directly within the thread." + content = "Please provide a forum post to edit the first post for, or run this " + + "command directly within the post thread." } return@action @@ -181,7 +190,7 @@ class ForumExtension : Extension() { if (isDeveloper && parent.categoryId != COMMUNITY_DEVELOPER_CATEGORY) { ackEphemeral { - content = "Quilt Developers may only use this command for threads in the developer " + + content = "Quilt Developers may only use this command for posts in the developer " + "forum channels." } @@ -192,7 +201,7 @@ class ForumExtension : Extension() { if (firstMessage == null) { ackEphemeral { - content = "Unable to find the first message for this thread - is it a Cozy-managed thread?" + content = "Unable to find the first message for this post - is it a Cozy-managed post?" } return@action @@ -248,7 +257,7 @@ class ForumExtension : Extension() { if (parent == null) { respond { - content = "Please provide a forum thread to edit the tags for." + content = "Please provide a forum post to edit the tags for." } return@action @@ -256,7 +265,7 @@ class ForumExtension : Extension() { if (post.appliedTags.contains(arguments.tag.id)) { respond { - content = "This thread already has that tag applied." + content = "This post already has that tag applied." } return@action @@ -268,7 +277,7 @@ class ForumExtension : Extension() { } respond { - content = "Thread tags updated." + content = "Post tags updated." } } } @@ -283,7 +292,7 @@ class ForumExtension : Extension() { if (parent == null) { respond { - content = "Please provide a forum thread to edit the tags for." + content = "Please provide a forum post to edit the tags for." } return@action @@ -291,7 +300,15 @@ class ForumExtension : Extension() { if (!post.appliedTags.contains(arguments.tag.id)) { respond { - content = "This thread doesn't have that tag applied." + content = "This post doesn't have that tag applied." + } + + return@action + } + + if (parent.flags?.contains(ChannelFlag.RequireTag) == true && post.appliedTags.size < 2) { + respond { + content = "You may not remove the last tag for a post in this forum." } return@action @@ -303,7 +320,7 @@ class ForumExtension : Extension() { } respond { - content = "Thread tags updated." + content = "Post tags updated." } } } From be3b1b6e52548b47c075d3a9a6cd2c09cace6321 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 6 May 2023 14:57:47 +0100 Subject: [PATCH 03/10] [skip ci] Community role picker --- yaml-files/welcome-community.yaml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/yaml-files/welcome-community.yaml b/yaml-files/welcome-community.yaml index d2998f9b..6a129991 100644 --- a/yaml-files/welcome-community.yaml +++ b/yaml-files/welcome-community.yaml @@ -151,6 +151,34 @@ For any question or request regarding your data, please contact us at privacy@quiltmc.org. +- type: roles + + id: community-roles + + title: "Role Assignment" + description: "Click the button below to assign or remove any of the following roles." + template: "{EMOJI} **{NAME}**: {DESCRIPTION}\n" + + roles: + 976178214269497366: + description: "Get pinged when we post announcements in <#832357051463630947>." + emoji: "📢" + + 1086037902577909870: + description: > + Get pinged with infrastructure status updates, notifying you about outages and their resolutions in + <#1086035355339333752>. + + emoji: "📢" + + 1003614007237816361: + description: "Get pinged when a new Minecraft snapshot or release is published in <#838805249271267398>." + emoji: "📢" + + 976082711817113610: + description: "Let people know that you're using a translator to talk." + emoji: "<:via_translator:976173251720015922>" + - type: text text: https://cdn.discordapp.com/attachments/863707104903561216/977162805373435925/forum-header-community.png From d35c0fe1f8b400403af932834ee31055cc60f5f8 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 6 May 2023 15:00:01 +0100 Subject: [PATCH 04/10] [skip ci] Update Levi's artist section --- yaml-files/welcome-community.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/yaml-files/welcome-community.yaml b/yaml-files/welcome-community.yaml index 6a129991..5f7d1bbf 100644 --- a/yaml-files/welcome-community.yaml +++ b/yaml-files/welcome-community.yaml @@ -131,14 +131,15 @@ description: > We're lucky to have a few talented artists in our community: - **»** [**Arathain**](https://twitter.com/arathainfarqoe) - Creator of Pineapple-Chan, Quilt-Chan and a few + **»** [**Arathain**](https://twitter.com/arathainfarqoe) - Creator of Pineapple-Chan, Quilt-Chan and a bunch of related emotes - **»** [**Iro**](https://iroki-sueun.tumblr.com/) - Our current banners and logo designer - **»** [**Katto / Digital Whiskers**](https://digital-whiskers.carrd.co/) - Designed a banner and a few other pieces + **»** [**Levi**](https://twitter.com/remote_getaway) - One of our Community Managers, has contributed many + banners and icons + We're very grateful to all of them for their amazing work! Don't hesitate to reach out to them if you'd like to commission them for your own projects. From 7b8495fb10d70b72c807977e8a71d6ed39f2d209 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 6 May 2023 15:01:22 +0100 Subject: [PATCH 05/10] [skip ci] Discord broke some link markdown --- yaml-files/welcome-community.yaml | 2 +- yaml-files/welcome-toolchain.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yaml-files/welcome-community.yaml b/yaml-files/welcome-community.yaml index 5f7d1bbf..292e5a59 100644 --- a/yaml-files/welcome-community.yaml +++ b/yaml-files/welcome-community.yaml @@ -197,7 +197,7 @@ If you're interested in long-form discussions, development help, news or community project, please feel free - to join our forum at [https://forum.quiltmc.org](https://forum.quiltmc.org)! + to join our forum at [https://forum.quiltmc.org](https://forum.quiltmc.org) - type: links diff --git a/yaml-files/welcome-toolchain.yaml b/yaml-files/welcome-toolchain.yaml index b55a4c77..e88424b1 100644 --- a/yaml-files/welcome-toolchain.yaml +++ b/yaml-files/welcome-toolchain.yaml @@ -148,7 +148,7 @@ If you're interested in long-form discussions, development help, news or community project, please feel free - to join our forum at [https://forum.quiltmc.org](https://forum.quiltmc.org)! + to join our forum at [https://forum.quiltmc.org](https://forum.quiltmc.org) - type: links From 5a0d48bf7cadb0d81e1d75a7751b9e879758b0df Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 6 May 2023 15:14:16 +0100 Subject: [PATCH 06/10] [skip ci] Actually we don't need the role picker now --- yaml-files/welcome-community.yaml | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/yaml-files/welcome-community.yaml b/yaml-files/welcome-community.yaml index 292e5a59..0b8eee65 100644 --- a/yaml-files/welcome-community.yaml +++ b/yaml-files/welcome-community.yaml @@ -152,34 +152,6 @@ For any question or request regarding your data, please contact us at privacy@quiltmc.org. -- type: roles - - id: community-roles - - title: "Role Assignment" - description: "Click the button below to assign or remove any of the following roles." - template: "{EMOJI} **{NAME}**: {DESCRIPTION}\n" - - roles: - 976178214269497366: - description: "Get pinged when we post announcements in <#832357051463630947>." - emoji: "📢" - - 1086037902577909870: - description: > - Get pinged with infrastructure status updates, notifying you about outages and their resolutions in - <#1086035355339333752>. - - emoji: "📢" - - 1003614007237816361: - description: "Get pinged when a new Minecraft snapshot or release is published in <#838805249271267398>." - emoji: "📢" - - 976082711817113610: - description: "Let people know that you're using a translator to talk." - emoji: "<:via_translator:976173251720015922>" - - type: text text: https://cdn.discordapp.com/attachments/863707104903561216/977162805373435925/forum-header-community.png From 72f014ae4dd7baa484526ad31461161225fdf507 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sat, 6 May 2023 16:07:59 +0100 Subject: [PATCH 07/10] [skip ci] Dev info channel --- yaml-files/dev-info-channel.yaml | 85 ++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 yaml-files/dev-info-channel.yaml diff --git a/yaml-files/dev-info-channel.yaml b/yaml-files/dev-info-channel.yaml new file mode 100644 index 00000000..75a3d8b5 --- /dev/null +++ b/yaml-files/dev-info-channel.yaml @@ -0,0 +1,85 @@ + + +- type: embed + + embeds: + - title: Quilt Development Channels + color: 0x57F287 + + description: > + Welcome to the Quilt Development channels - in this category, you'll find channels representing each of Quilt's + development teams, each containing discussions relevant to their respective projects. + + + Unlike a lot of other channels here, **these channels are strictly on-topic.** Please avoid any off-topic + tangents, and don't be too surprised if you're asked to move to another channel when things stray too far + from the topic. + + - title: Understanding This Category + color: 0x5865F2 + + description: > + This channel category is set up somewhat differently to the rest of the server. Specifically, take note of the + following: + + + - <#1103979229881831444> may be used for general project-related discussions, and to ask which channel is best + for a given project or subject + + - <#1103979333627936818> contains individual development logs, split into a forum post per team - these logs + are automatically copied to <#908399987099045999> by Cozy + + - <#1104421317731688609> contains the git logs - you can look at the channel itself to see all of them, or you + can look through the threads to find git logs for specific teams + + - The forum channels set up for each team (other than <#1104037919792054282>) are curated by the development + teams they were created for - users may not create posts, but you can always ask a developer or moderator to + create a post that you feel should be there + + - title: Getting Involved + color: 0xFEE75C + + description: > + If you'd like to contribute to Quilt and its projects, we recommend the following: + + + - Head to <#1103979229881831444>, or the relevant forum post or channel, and ask whether there's anything + that needs to be done or any projects that need contributors + + - Go to the relevant project [on our GitHub](https://github.com/QuiltMC) and see whether there are any + available issues that you could handle - and remember to leave a comment if you're working on an issue + + - Listen in on our monthly developer meetings, where we often discuss the projects that need contributors + + - Take a look at the + [pending RFC pull requests](https://github.com/QuiltMC/rfcs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc) + and provide some reviews + + - Consider donating to [our OpenCollective](https://opencollective.com/quiltmc) to help with Quilt's upkeep + costs + + + Please note that **you do not need to join a team to contribute.** In fact, we encourage you to claim issues + and submit pull requests externally, especially if you don't wish to handle project management tasks. While + we are happy to accept applications from regular contributors that wish to join a team, please note that + this is only necessary if you wish to help out with our project management work - and you shouldn't apply to + join a team just for a role icon or a name on our site. + + - title: For Developers + color: 0xEB459E + + description: > + Existing members of Quilt development teams are able to create new posts (and edit existing ones) in the + forum channels in this category. This can be done using the following Cozy commands: + + + - `/forum create-post [tag]` + + - `/forum edit-post ` + + - `/forum add-tag ` + + - `/forum remove-tag ` + + + If you run into any issues, please feel free to talk to a Community Manager. From cfe62a7e6cdc633addb9c8347d8f27a5c2d44104 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sun, 7 May 2023 10:55:57 +0100 Subject: [PATCH 08/10] Devlog posting --- .../org/quiltmc/community/_Constants.kt | 10 ++ .../modes/quilt/extensions/ForumExtension.kt | 139 +++++++++++++++++- 2 files changed, 147 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/quiltmc/community/_Constants.kt b/src/main/kotlin/org/quiltmc/community/_Constants.kt index 2c690534..fc6f3176 100644 --- a/src/main/kotlin/org/quiltmc/community/_Constants.kt +++ b/src/main/kotlin/org/quiltmc/community/_Constants.kt @@ -180,3 +180,13 @@ internal val COMMUNITY_RELEASE_CHANNELS = envOrNull("COMMUNITY_RELEASE_CHANNELS" ?.split(',') ?.map { Snowflake(it.trim()) } ?: listOf() + +internal val DEVLOG_CHANNEL = Snowflake( + envOrNull("DEVLOG_CHANNEL")?.toLong() + ?: 908399987099045999 +) + +internal val DEVLOG_FORUM = Snowflake( + envOrNull("DEVLOG_FORUM")?.toLong() + ?: 1103979333627936818 +) diff --git a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt index 831d1c75..f6a8a20c 100644 --- a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt +++ b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt @@ -9,8 +9,8 @@ package org.quiltmc.community.modes.quilt.extensions -import com.kotlindiscord.kord.extensions.checks.hasRole -import com.kotlindiscord.kord.extensions.checks.or +import com.kotlindiscord.kord.extensions.DiscordRelayedException +import com.kotlindiscord.kord.extensions.checks.* import com.kotlindiscord.kord.extensions.commands.Arguments import com.kotlindiscord.kord.extensions.commands.application.slash.ephemeralSubCommand import com.kotlindiscord.kord.extensions.commands.converters.impl.channel @@ -19,34 +19,58 @@ import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalTag import com.kotlindiscord.kord.extensions.commands.converters.impl.tag import com.kotlindiscord.kord.extensions.components.forms.ModalForm import com.kotlindiscord.kord.extensions.extensions.Extension +import com.kotlindiscord.kord.extensions.extensions.ephemeralMessageCommand import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand +import com.kotlindiscord.kord.extensions.extensions.event import com.kotlindiscord.kord.extensions.modules.unsafe.annotations.UnsafeAPI import com.kotlindiscord.kord.extensions.modules.unsafe.extensions.unsafeSubCommand import com.kotlindiscord.kord.extensions.modules.unsafe.types.InitialSlashCommandResponse import com.kotlindiscord.kord.extensions.modules.unsafe.types.ackEphemeral import com.kotlindiscord.kord.extensions.types.respond +import com.kotlindiscord.kord.extensions.utils.addReaction +import com.kotlindiscord.kord.extensions.utils.ensureWebhook import com.kotlindiscord.kord.extensions.utils.extraData import dev.kord.common.annotation.KordUnsafe import dev.kord.common.entity.ChannelFlag import dev.kord.common.entity.ChannelType +import dev.kord.core.behavior.channel.asChannelOf import dev.kord.core.behavior.channel.asChannelOfOrNull import dev.kord.core.behavior.channel.createMessage import dev.kord.core.behavior.channel.threads.edit import dev.kord.core.behavior.edit +import dev.kord.core.behavior.execute import dev.kord.core.behavior.interaction.modal import dev.kord.core.behavior.interaction.response.createEphemeralFollowup +import dev.kord.core.entity.Message import dev.kord.core.entity.channel.ForumChannel +import dev.kord.core.entity.channel.NewsChannel +import dev.kord.core.entity.channel.TopGuildMessageChannel import dev.kord.core.entity.channel.thread.TextChannelThread import dev.kord.core.entity.channel.thread.ThreadChannel +import dev.kord.core.event.message.MessageCreateEvent +import io.ktor.client.* +import io.ktor.client.call.* +import io.ktor.client.request.* +import io.ktor.util.* import kotlinx.coroutines.delay +import org.koin.core.component.inject import org.quiltmc.community.* +import org.quiltmc.community.database.collections.UserFlagsCollection +import org.quiltmc.community.database.entities.UserFlags import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds +private const val TOOLCHAIN_LOGO: String = + "https://raw.githubusercontent.com/QuiltMC/art/master/brand/512png/quilt_toolchain_logo_dark.png" + +private val ICON_URL_REGEX = Regex("(?:^|\n)Icon URL:([^\n])") + class ForumExtension : Extension() { override val name: String = "forum" + private val userFlags: UserFlagsCollection by inject() + override suspend fun setup() { ephemeralSlashCommand { name = "forum" @@ -325,6 +349,117 @@ class ForumExtension : Extension() { } } } + + ephemeralMessageCommand { + name = "Publish devlog" + + check { + hasBaseModeratorRole(true) + + or { + hasRole(COMMUNITY_DEVELOPER_ROLE) + + if (passed) { + event.extraData["isDeveloper"] = true + } + } + } + + check { + val parent = topChannelFor(event) + val message = messageFor(event) + + if ( + parent?.id != DEVLOG_FORUM // Wrong forum channel + ) { + fail("This command may only be run in <#$DEVLOG_FORUM>.") + + return@check + } + + if ( + message?.asMessageOrNull()?.author?.id == kord.selfId // Cozy sent the message + ) { + fail("You may not publish a message posted by <@${kord.selfId}>.") + + return@check + } + + pass() + } + + action { + targetMessages.first().publishDevlog() + + respond { + content = "Message published." + } + } + } + + event { + check { + val parent = topChannelFor(event) + val message = messageFor(event) + val user = userFor(event) + + if ( + parent?.id != DEVLOG_FORUM || // Wrong forum channel + message?.asMessageOrNull()?.author?.id == kord.selfId || // Cozy sent the message + user == null // No user for the event + ) { + fail() + + return@check + } + + val flags = userFlags.get(user.id) ?: UserFlags(user.id) + + if (!flags.autoPublish) { // User settings set to not auto-publish + fail() + + return@check + } + + pass() + } + + action { + event.message.publishDevlog() + } + } + } + + private suspend fun Message.publishDevlog() { + val publishingChannel = kord.getChannelOf(DEVLOG_CHANNEL) + ?: throw DiscordRelayedException("Unable to get the publishing channel") + + val thread = channel.asChannelOf() + val firstMessage = thread.getFirstMessage()!! + + val webhook = ensureWebhook(publishingChannel, "Quilt Devlogs") { + HttpClient().get(TOOLCHAIN_LOGO).body() + } + + val match = ICON_URL_REGEX.find(firstMessage.content) + + val icon = if (match != null) { + match.groupValues[1] + } else { + TOOLCHAIN_LOGO + } + + val message = webhook.execute(webhook.token!!) { + this.username = thread.name + this.avatarUrl = icon + this.content = this@publishDevlog.content + } + + if (publishingChannel is NewsChannel) { + message.publish() + } + + addReaction("🚀") } inner class PostTagArgs : Arguments() { From 8b9831755d0d19a8999f1fb1d5e133ce6d0355a2 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sun, 7 May 2023 11:07:15 +0100 Subject: [PATCH 09/10] Trim icon URL from messages --- .../quiltmc/community/modes/quilt/extensions/ForumExtension.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt index f6a8a20c..595217eb 100644 --- a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt +++ b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt @@ -51,7 +51,6 @@ import dev.kord.core.event.message.MessageCreateEvent import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.request.* -import io.ktor.util.* import kotlinx.coroutines.delay import org.koin.core.component.inject import org.quiltmc.community.* @@ -447,7 +446,7 @@ class ForumExtension : Extension() { match.groupValues[1] } else { TOOLCHAIN_LOGO - } + }.trim() val message = webhook.execute(webhook.token!!) { this.username = thread.name From 48300870bcd6812af1a0601fc6ad6597cbfa1e16 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Sun, 7 May 2023 12:44:41 +0100 Subject: [PATCH 10/10] Fix icon URL regex --- .../quiltmc/community/modes/quilt/extensions/ForumExtension.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt index 595217eb..b68f4a85 100644 --- a/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt +++ b/src/main/kotlin/org/quiltmc/community/modes/quilt/extensions/ForumExtension.kt @@ -63,7 +63,7 @@ import kotlin.time.Duration.Companion.seconds private const val TOOLCHAIN_LOGO: String = "https://raw.githubusercontent.com/QuiltMC/art/master/brand/512png/quilt_toolchain_logo_dark.png" -private val ICON_URL_REGEX = Regex("(?:^|\n)Icon URL:([^\n])") +private val ICON_URL_REGEX = Regex("(?:^|\n)Icon URL:([^\n]+)") class ForumExtension : Extension() { override val name: String = "forum"