Skip to content

Commit

Permalink
feat:top-post (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
Miii-chael authored Feb 21, 2024
1 parent e0e5a41 commit ba94d13
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ open class WsaDiscordProperties(properties: Properties) {
val wsaGuideLineChannelId: String
val wsaLongArticleRoleId: String
val wsaTopicMasterRoleId: String
val topicPondChannelId: String

init {
properties.run {
Expand Down Expand Up @@ -65,6 +66,7 @@ open class WsaDiscordProperties(properties: Properties) {
wsaGuideLineChannelId = getProperty("wsa-guideline-channel-id")
wsaLongArticleRoleId = getProperty("wsa-long-article-role-id")
wsaTopicMasterRoleId = getProperty("wsa-topic-master-role-id")
topicPondChannelId = getProperty("topic-pond-channel-id")
}
}
}
4 changes: 4 additions & 0 deletions main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
<groupId>tw.waterballsa.utopia</groupId>
<artifactId>weekly-messages-volume</artifactId>
</dependency>
<dependency>
<groupId>tw.waterballsa.utopia</groupId>
<artifactId>top-post</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
1 change: 1 addition & 0 deletions main/src/main/resources/wsa.beta.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ water-ball-lose-weight-post-id=1091190313575526400
wsa-guideline-channel-id=1042774419371720715
wsa-long-article-role-id=1163842900933742592
wsa-topic-master-role-id=1163842370018754560
topic-pond-channel-id=1165545216397295636
3 changes: 2 additions & 1 deletion main/src/main/resources/wsa.prod.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ featured-videos-channel-id=1060728666507726858
flag-post-guide-id=1072845227418714193
water-ball-journal-post-id=1072869148826292234
water-ball-lose-weight-post-id=1091190313575526400
wsa-guideline-channel-id=1042774419371720715
wsa-guideline-channel-id=1042774419371720715
topic-pond-channel-id=1137770529273683999
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<module>message-cherry-pick</module>
<module>weekly-messages-volume</module>
<module>utopia-test-kit</module>
<module>top-post</module>
</modules>

<properties>
Expand Down Expand Up @@ -288,6 +289,11 @@
<artifactId>utopia-test-kit</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>tw.waterballsa.utopia</groupId>
<artifactId>top-post</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
24 changes: 24 additions & 0 deletions top-post/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>root</artifactId>
<groupId>tw.waterballsa.utopia</groupId>
<version>${revision}</version>
</parent>

<artifactId>top-post</artifactId>

<dependencies>
<dependency>
<groupId>tw.waterballsa.utopia</groupId>
<artifactId>commons</artifactId>
</dependency>
<dependency>
<groupId>tw.waterballsa.utopia</groupId>
<artifactId>discord-impl-jda</artifactId>
</dependency>
</dependencies>
</project>
31 changes: 31 additions & 0 deletions top-post/src/main/kotlin/tw/waterballsa/utopia/TopPostListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package tw.waterballsa.utopia.toppost

import net.dv8tion.jda.api.entities.channel.unions.IThreadContainerUnion
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent
import org.springframework.stereotype.Component
import tw.waterballsa.utopia.commons.config.WsaDiscordProperties
import tw.waterballsa.utopia.jda.UtopiaListener

const val likeEmoji = "\uD83D\uDC4D"


@Component
class TopPostListener(private val wsa: WsaDiscordProperties) : UtopiaListener() {

override fun onMessageReactionAdd(event: MessageReactionAddEvent) {
with (event) {
val post = channel.asThreadChannel()
val forum = post.parentChannel
val hasPostLikeEmoji = emoji.name == likeEmoji

if (forum.isTopicPoolForum() && hasPostLikeEmoji) {
channel.sendMessage(likeEmoji).queue {
it.delete().queue()
}
}
}
}

private fun IThreadContainerUnion.isTopicPoolForum() = id == wsa.topicPondChannelId

}

0 comments on commit ba94d13

Please sign in to comment.