-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0e5a41
commit ba94d13
Showing
7 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
top-post/src/main/kotlin/tw/waterballsa/utopia/TopPostListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |