Skip to content

Commit

Permalink
Forums: Handle tag restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed May 6, 2023
1 parent 471b12d commit 8723043
Showing 1 changed file with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 " +
Expand Down Expand Up @@ -172,16 +181,16 @@ 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
}

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."
}

Expand All @@ -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
Expand Down Expand Up @@ -248,15 +257,15 @@ 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
}

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
Expand All @@ -268,7 +277,7 @@ class ForumExtension : Extension() {
}

respond {
content = "Thread tags updated."
content = "Post tags updated."
}
}
}
Expand All @@ -283,15 +292,23 @@ 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
}

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
Expand All @@ -303,7 +320,7 @@ class ForumExtension : Extension() {
}

respond {
content = "Thread tags updated."
content = "Post tags updated."
}
}
}
Expand Down

0 comments on commit 8723043

Please sign in to comment.