Skip to content

Commit

Permalink
✨ 用表情訂閱/解除訂閱機制
Browse files Browse the repository at this point in the history
1. 重新命名Module
2. 新增訂閱者身份組Role ID
  • Loading branch information
WayneTsou85 authored and Zouwayne committed Nov 5, 2023
1 parent 60e820b commit 55eec6c
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ open class WsaDiscordProperties(properties: Properties) {
val wsaCitizenRoleId: String
val wsaAlphaRoleId: String
val wsaGaaSMemberRoleId: String
val wsaSECSubsriberMemberRoleId: String
val wsaGaaSSubscriberRoleId: String
val wsaPurefuncSubscriberRoleId: String
val wsaTTMSubscriberRoleId: String
val wsaCSLabSubscriberRoleId: String

// Message ID
val unlockEntryMessageId: String
val manageSubscriberRoleMessageId : String

// Forum ID
val flagPostGuideId: String
Expand Down Expand Up @@ -78,9 +84,15 @@ open class WsaDiscordProperties(properties: Properties) {
wsaCitizenRoleId = getProperty("wsa-citizen-role-id")
wsaAlphaRoleId = getProperty("wsa-alpha-role-id")
wsaGaaSMemberRoleId = getProperty("wsa-gaas-member-role-id")
wsaSECSubsriberMemberRoleId = getProperty("wsa-sec-subscriber-role-id")
wsaGaaSSubscriberRoleId = getProperty("wsa-gaas-subscriber-role-id")
wsaPurefuncSubscriberRoleId = getProperty("wsa-purefunc-subscriber-role-id")
wsaTTMSubscriberRoleId = getProperty("wsa-ttm-subscriber-role-id")
wsaCSLabSubscriberRoleId = getProperty("wsa-cslab-subscriber-role-id")

// Message ID
unlockEntryMessageId = getProperty("unlock-entry-message-id")
manageSubscriberRoleMessageId = getProperty("manage-subscriber-role-message-id")

// Forum ID
flagPostGuideId = getProperty("flag-post-guide-id")
Expand Down
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>manage-subscriber-role</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
6 changes: 6 additions & 0 deletions main/src/main/resources/wsa.beta.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ wsa-guest-role-id=1040635429541646407
wsa-citizen-role-id=1038661590985228298
wsa-alpha-role-id=1038661266962665472
wsa-gaas-member-role-id=1039198138403135538
wsa-sec-subscriber-role-id=1095747365215932487
wsa-gaas-subscriber-role-id=1038661611889631262
wsa-purefunc-subscriber-role-id=1095747473345097749
wsa-ttm-subscriber-role-id=1038661795507863623
wsa-cslab-subscriber-role-id=1095747425194483762

# Message ID
unlock-entry-message-id=1038667013259792455
manage-subscriber-role-message-id=1164966105555673108

# Forum ID
flag-post-guide-id=1043565056765472798
Expand Down
6 changes: 6 additions & 0 deletions main/src/main/resources/wsa.prod.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ wsa-guest-role-id=1042770137742319636
wsa-citizen-role-id=954669665588756480
wsa-alpha-role-id=977830704824066068
wsa-gaas-member-role-id=992080633419546745
wsa-sec-subscriber-role-id=1056758845264900166
wsa-gaas-subscriber-role-id=1042774972717871176
wsa-purefunc-subscriber-role-id=1038933719723020318
wsa-ttm-subscriber-role-id=1042775110630780958
wsa-cslab-subscriber-role-id=1051031301609758752

# Message ID
unlock-entry-message-id=1042776102734663740
manage-subscriber-role-message-id=

# Forum ID
flag-post-guide-id=1072845227418714193
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>${revision}</version>
</parent>

<artifactId>unsubscribe-role</artifactId>
<artifactId>manage-subscriber-role</artifactId>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package tw.waterballsa.utopia.managesubscriberole

import mu.KotlinLogging
import net.dv8tion.jda.api.entities.UserSnowflake
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent
import net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent
import org.springframework.stereotype.Component
import tw.waterballsa.utopia.commons.config.WsaDiscordProperties
import tw.waterballsa.utopia.jda.UtopiaListener

private val logger = KotlinLogging.logger {}
@Component
class ManageSubscribeRoleListener(private val wsa: WsaDiscordProperties) : UtopiaListener() {

private val emojiToSubscriberRoleIdMap = hashMapOf<String, String>()

/**
* "1️⃣":軟體英文派對訂閱者
* "2️⃣":遊戲微服務計畫訂閱者
* "3️⃣":純函式咖啡訂閱者
* "4️⃣":技術演講吐司會訂閱者
* "7️⃣":CS Lab 訂閱者
*/
init {
emojiToSubscriberRoleIdMap["1️⃣"] = wsa.wsaSECSubsriberMemberRoleId
emojiToSubscriberRoleIdMap["2️⃣"] = wsa.wsaGaaSSubscriberRoleId
emojiToSubscriberRoleIdMap["3️⃣"] = wsa.wsaPurefuncSubscriberRoleId
emojiToSubscriberRoleIdMap["4️⃣"] = wsa.wsaTTMSubscriberRoleId
emojiToSubscriberRoleIdMap["7️⃣"] = wsa.wsaCSLabSubscriberRoleId
}

/**
* 新增表情,移除對應訂閱者身份組
*/
override fun onMessageReactionAdd(event: MessageReactionAddEvent) {
with(event) {
if (messageId != wsa.manageSubscriberRoleMessageId) {
return
}
emojiToSubscriberRoleIdMap[emoji.name]?.run {
val user = UserSnowflake.fromId(userId)
val role = jda.getRoleById(this)?: return
guild.removeRoleFromMember(user, role)
.queue {
logger.info { "[Remove Role] {\"userId\":\"${user.id}\", \"roleName\":\"${role.name}\" }" }
}
}
}
}

/**
* 移除表情,新增對應訂閱者身份組
*/
override fun onMessageReactionRemove(event: MessageReactionRemoveEvent) {
with(event) {
if (messageId != wsa.manageSubscriberRoleMessageId) {
return
}
emojiToSubscriberRoleIdMap[emoji.name]?.run {
val user = UserSnowflake.fromId(userId)
val role = jda.getRoleById(this)?: return
guild.addRoleToMember(user, role)
.queue {
logger.info { "[Add Role] {\"userId\":\"${user.id}\", \"roleName\":\"${role.name}\" }" }
}
}
}
}

}
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<module>message-cherry-pick</module>
<module>weekly-messages-volume</module>
<module>utopia-test-kit</module>
<module>unsubscribe-role</module>
<module>manage-subscriber-role</module>
</modules>

<properties>
Expand Down Expand Up @@ -284,6 +284,11 @@
<artifactId>weekly-messages-volume</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>tw.waterballsa.utopia</groupId>
<artifactId>manage-subscriber-role</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down

This file was deleted.

0 comments on commit 55eec6c

Please sign in to comment.