From 9a7e9a3e209f43ec7ea4814773192ce1e968505e Mon Sep 17 00:00:00 2001 From: Wayne Tsou Date: Wed, 15 Nov 2023 22:56:03 +0800 Subject: [PATCH 1/6] =?UTF-8?q?:recycle:=20=E7=94=A8=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E8=A8=82=E9=96=B1/=E8=A7=A3=E9=99=A4=E8=A8=82=E9=96=B1?= =?UTF-8?q?=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新最新版本 --- .../commons/config/WsaDiscordProperties.kt | 87 ++++++++++++------- main/src/main/resources/wsa.beta.properties | 35 +++++--- main/src/main/resources/wsa.prod.properties | 29 +++++-- 3 files changed, 103 insertions(+), 48 deletions(-) diff --git a/commons/src/main/kotlin/tw/waterballsa/utopia/commons/config/WsaDiscordProperties.kt b/commons/src/main/kotlin/tw/waterballsa/utopia/commons/config/WsaDiscordProperties.kt index f658779e..125cb542 100644 --- a/commons/src/main/kotlin/tw/waterballsa/utopia/commons/config/WsaDiscordProperties.kt +++ b/commons/src/main/kotlin/tw/waterballsa/utopia/commons/config/WsaDiscordProperties.kt @@ -9,62 +9,91 @@ const val ENV_PROD = "prod" open class WsaDiscordProperties(properties: Properties) { - val engineerLifeChannelId: String - val careerAdvancementTopicChannelId: String - val knowledgeKingChannelId: String + + // Database Name + val mongoDatabase: String + + // Guild ID val guildId: String - val unlockEntryMessageId: String - val selfIntroChannelId: String - val wsaGuestRoleId: String - val wsaCitizenRoleId: String - val gentlemenForumCategoryId: String + + // Channel ID val wsaGentlemenBroadcastChannelId: String val wsaPartyChannelId: String val wsaGaaSConversationChannelId: String - val wsaGaaSMemberRoleId: String - val wsaAlphaRoleId: String - val discussionAreaChannelId: String + val knowledgeKingChannelId: String + val careerAdvancementTopicChannelId: String + val engineerLifeChannelId: String val unlockEntryChannelId: String + val selfIntroChannelId: String + val discussionAreaChannelId: String val flagPostChannelId: String - val mongoDatabase: String val resumeCheckChannelId: String val featuredVideosChannelId: String - val flagPostGuideId: String - val waterBallJournalPostId: String - val waterBallLoseWeightPostId: String val wsaGuideLineChannelId: String + + // Role ID + val wsaGuestRoleId: String + val wsaCitizenRoleId: String + val wsaAlphaRoleId: String + val wsaGaaSMemberRoleId: String val wsaLongArticleRoleId: String val wsaTopicMasterRoleId: String + // Message ID + val unlockEntryMessageId: String + + // Forum ID + val flagPostGuideId: String + val gentlemenForumCategoryId: String + + // Post ID + val waterBallJournalPostId: String + val waterBallLoseWeightPostId: String + init { properties.run { logger.info { properties } + + // Database Name + mongoDatabase = getProperty("mongo-database") + + // Guild ID guildId = getProperty("guild-id") - unlockEntryMessageId = getProperty("unlock-entry-message-id") - selfIntroChannelId = getProperty("self-intro-channel-id") - wsaGuestRoleId = getProperty("wsa-guest-role-id") - wsaCitizenRoleId = getProperty("wsa-citizen-role-id") - gentlemenForumCategoryId = getProperty("wsa-gentlemen-forum-category-id") + + // Channel ID wsaGentlemenBroadcastChannelId = getProperty("wsa-gentlemen-broadcast-channel-id") wsaPartyChannelId = getProperty("wsa-party-channel-id") wsaGaaSConversationChannelId = getProperty("wsa-gaas-conversation-channel-id") - wsaGaaSMemberRoleId = getProperty("wsa-gaas-member-role-id") - wsaAlphaRoleId = getProperty("wsa-alpha-role-id") knowledgeKingChannelId = getProperty("knowledge-king-channel-id") - discussionAreaChannelId = getProperty("wsa-discussion-area-channel-id") - unlockEntryChannelId = getProperty("unlock-entry-channel-id") - flagPostChannelId = getProperty("wsa-flag-post-channel-id") careerAdvancementTopicChannelId = getProperty("career-advancement-topic-channel-id") engineerLifeChannelId = getProperty("engineer-life-channel-id") - mongoDatabase = getProperty("mongo-database") + unlockEntryChannelId = getProperty("unlock-entry-channel-id") + selfIntroChannelId = getProperty("self-intro-channel-id") + discussionAreaChannelId = getProperty("wsa-discussion-area-channel-id") + flagPostChannelId = getProperty("wsa-flag-post-channel-id") resumeCheckChannelId = getProperty("resume-check-channel-id") featuredVideosChannelId = getProperty("featured-videos-channel-id") - flagPostGuideId = getProperty("flag-post-guide-id") - waterBallJournalPostId = getProperty("water-ball-journal-post-id") - waterBallLoseWeightPostId = getProperty("water-ball-lose-weight-post-id") wsaGuideLineChannelId = getProperty("wsa-guideline-channel-id") + + // Role ID + wsaGuestRoleId = getProperty("wsa-guest-role-id") + wsaCitizenRoleId = getProperty("wsa-citizen-role-id") + wsaAlphaRoleId = getProperty("wsa-alpha-role-id") + wsaGaaSMemberRoleId = getProperty("wsa-gaas-member-role-id") wsaLongArticleRoleId = getProperty("wsa-long-article-role-id") wsaTopicMasterRoleId = getProperty("wsa-topic-master-role-id") + + // Message ID + unlockEntryMessageId = getProperty("unlock-entry-message-id") + + // Forum ID + flagPostGuideId = getProperty("flag-post-guide-id") + gentlemenForumCategoryId = getProperty("wsa-gentlemen-forum-category-id") + + // Post ID + waterBallJournalPostId = getProperty("water-ball-journal-post-id") + waterBallLoseWeightPostId = getProperty("water-ball-lose-weight-post-id") } } } + diff --git a/main/src/main/resources/wsa.beta.properties b/main/src/main/resources/wsa.beta.properties index 8b72f892..333f403f 100644 --- a/main/src/main/resources/wsa.beta.properties +++ b/main/src/main/resources/wsa.beta.properties @@ -1,26 +1,39 @@ +# Database Name +mongo-database=utopia-beta + +# Guild ID guild-id=1038654765896310804 -wsa-guest-role-id=1040635429541646407 -wsa-citizen-role-id=1038661590985228298 -wsa-gentlemen-forum-category-id=1038657733286694922 + +# Channel ID wsa-gentlemen-broadcast-channel-id=1091990496756383744 wsa-party-channel-id=1040672621609619596 wsa-gaas-conversation-channel-id=1039197324062240820 -wsa-gaas-member-role-id=1039198138403135538 -wsa-alpha-role-id=1038661266962665472 knowledge-king-channel-id=1039363776497061930 career-advancement-topic-channel-id=1038665145687212114 engineer-life-channel-id=1117318113965379584 -unlock-entry-message-id=1038667013259792455 unlock-entry-channel-id=1038657171480649748 self-intro-channel-id=1039196068455399474 wsa-discussion-area-channel-id=1038657903437037590 wsa-flag-post-channel-id=1043565056765472798 -mongo-database=utopia-beta resume-check-channel-id=1081319049012727949 featured-videos-channel-id=1129663992323919902 -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=1038756191968432180 + +# Role ID +wsa-guest-role-id=1040635429541646407 +wsa-citizen-role-id=1038661590985228298 +wsa-alpha-role-id=1038661266962665472 +wsa-gaas-member-role-id=1039198138403135538 wsa-long-article-role-id=1163842900933742592 wsa-topic-master-role-id=1163842370018754560 + +# Message ID +unlock-entry-message-id=1038667013259792455 + +# Forum ID +flag-post-guide-id=1043565056765472798 +wsa-gentlemen-forum-category-id=1038657733286694922 + +# Post ID +water-ball-journal-post-id=1092095104472317994 +water-ball-lose-weight-post-id=1091190313575526400 diff --git a/main/src/main/resources/wsa.prod.properties b/main/src/main/resources/wsa.prod.properties index 9ac2e1a3..a20f0cce 100644 --- a/main/src/main/resources/wsa.prod.properties +++ b/main/src/main/resources/wsa.prod.properties @@ -1,24 +1,37 @@ +# Database Name +mongo-database=utopia + +# Guild ID guild-id=937992003415838761 -wsa-guest-role-id=1042770137742319636 -wsa-citizen-role-id=954669665588756480 -wsa-gentlemen-forum-category-id=937992003998855171 + +# Channel ID wsa-gentlemen-broadcast-channel-id=1091990658111242300 wsa-party-channel-id=992631653954502716 wsa-gaas-conversation-channel-id=975351568398442507 -wsa-gaas-member-role-id=992080633419546745 -wsa-alpha-role-id=977830704824066068 knowledge-king-channel-id=1107218161075494912 career-advancement-topic-channel-id=999291233648267304 engineer-life-channel-id=1120934992877469696 -unlock-entry-message-id=1042776102734663740 unlock-entry-channel-id=1042774291118305385 self-intro-channel-id=937992281837961257 wsa-discussion-area-channel-id=953564228290216036 wsa-flag-post-channel-id=1067781868709220432 -mongo-database=utopia resume-check-channel-id=1090518713435967528 featured-videos-channel-id=1060728666507726858 +wsa-guideline-channel-id=1042774419371720715 + +# Role ID +wsa-guest-role-id=1042770137742319636 +wsa-citizen-role-id=954669665588756480 +wsa-alpha-role-id=977830704824066068 +wsa-gaas-member-role-id=992080633419546745 + +# Message ID +unlock-entry-message-id=1042776102734663740 + +# Forum ID flag-post-guide-id=1072845227418714193 +wsa-gentlemen-forum-category-id=937992003998855171 + +# Post ID water-ball-journal-post-id=1072869148826292234 water-ball-lose-weight-post-id=1091190313575526400 -wsa-guideline-channel-id=1042774419371720715 \ No newline at end of file From 15a9f9a01718da732468dfbadbff934055c4ae2e Mon Sep 17 00:00:00 2001 From: Wayne Tsou Date: Sun, 8 Oct 2023 16:41:21 +0800 Subject: [PATCH 2/6] =?UTF-8?q?:sparkles:=20=E7=94=A8=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E8=A7=A3=E8=A8=82=E9=96=B1=E5=88=B6=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + unsubscribe-role/pom.xml | 25 +++++++++++++++ .../UnsubscribeRoleListener.kt | 31 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 unsubscribe-role/pom.xml create mode 100644 unsubscribe-role/src/main/kotlin/tw/waterballsa/utopia/unsubscriberole/UnsubscribeRoleListener.kt diff --git a/pom.xml b/pom.xml index 4ac7999b..421dacb0 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ message-cherry-pick weekly-messages-volume utopia-test-kit + unsubscribe-role diff --git a/unsubscribe-role/pom.xml b/unsubscribe-role/pom.xml new file mode 100644 index 00000000..91c3002f --- /dev/null +++ b/unsubscribe-role/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + tw.waterballsa.utopia + root + ${revision} + + + unsubscribe-role + + + + tw.waterballsa.utopia + commons + + + tw.waterballsa.utopia + discord-impl-jda + + + + diff --git a/unsubscribe-role/src/main/kotlin/tw/waterballsa/utopia/unsubscriberole/UnsubscribeRoleListener.kt b/unsubscribe-role/src/main/kotlin/tw/waterballsa/utopia/unsubscriberole/UnsubscribeRoleListener.kt new file mode 100644 index 00000000..1dd49bb5 --- /dev/null +++ b/unsubscribe-role/src/main/kotlin/tw/waterballsa/utopia/unsubscriberole/UnsubscribeRoleListener.kt @@ -0,0 +1,31 @@ +package tw.waterballsa.utopia.unsubscriberole + +import net.dv8tion.jda.api.events.emoji.EmojiAddedEvent +import org.springframework.stereotype.Component +import tw.waterballsa.utopia.commons.config.WsaDiscordProperties +import tw.waterballsa.utopia.jda.UtopiaListener + + +@Component +class UnsubscribeRoleListener(val wsa: WsaDiscordProperties): UtopiaListener() { + + private val emojiIdToRoleId = hashMapOf() + + /** + * prod beta + * "1️⃣":軟體英文派對訂閱者 1056758845264900166 1095747365215932487 + * "2️⃣":遊戲微服務計畫訂閱者 1042774972717871176 1038661611889631262 + * "3️⃣":純函式咖啡訂閱者 1038933719723020318 1095747473345097749 + * "4️⃣":技術演講吐司會訂閱者 1042775110630780958 1038661795507863623 + * "7️⃣":CS Lab 訂閱者 1051031301609758752 1095747425194483762 + */ + init { + emojiIdToRoleId[wsa.wsaGaaSMemberRoleId] = "2️⃣" + } + + override fun onEmojiAdded(event: EmojiAddedEvent) { + super.onEmojiAdded(event) + } + + +} From 3be97f4483de71e389bc68b1a53d2522117869c3 Mon Sep 17 00:00:00 2001 From: Wayne Tsou Date: Wed, 15 Nov 2023 22:59:20 +0800 Subject: [PATCH 3/6] =?UTF-8?q?:recycle:=20=E7=94=A8=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E8=A8=82=E9=96=B1/=E8=A7=A3=E9=99=A4=E8=A8=82=E9=96=B1?= =?UTF-8?q?=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新最新版本 --- .../commons/config/WsaDiscordProperties.kt | 12 ++++ main/pom.xml | 4 ++ main/src/main/resources/wsa.beta.properties | 6 ++ main/src/main/resources/wsa.prod.properties | 6 ++ .../pom.xml | 2 +- .../ManageSubscribeRoleListener.kt | 70 +++++++++++++++++++ pom.xml | 7 +- .../UnsubscribeRoleListener.kt | 31 -------- 8 files changed, 105 insertions(+), 33 deletions(-) rename {unsubscribe-role => manage-subscriber-role}/pom.xml (93%) create mode 100644 manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/ManageSubscribeRoleListener.kt delete mode 100644 unsubscribe-role/src/main/kotlin/tw/waterballsa/utopia/unsubscriberole/UnsubscribeRoleListener.kt diff --git a/commons/src/main/kotlin/tw/waterballsa/utopia/commons/config/WsaDiscordProperties.kt b/commons/src/main/kotlin/tw/waterballsa/utopia/commons/config/WsaDiscordProperties.kt index 125cb542..adf6bcd8 100644 --- a/commons/src/main/kotlin/tw/waterballsa/utopia/commons/config/WsaDiscordProperties.kt +++ b/commons/src/main/kotlin/tw/waterballsa/utopia/commons/config/WsaDiscordProperties.kt @@ -36,11 +36,17 @@ 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 val wsaLongArticleRoleId: String val wsaTopicMasterRoleId: String // Message ID val unlockEntryMessageId: String + val manageSubscriberRoleMessageId : String // Forum ID val flagPostGuideId: String @@ -80,11 +86,17 @@ 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") wsaLongArticleRoleId = getProperty("wsa-long-article-role-id") wsaTopicMasterRoleId = getProperty("wsa-topic-master-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") diff --git a/main/pom.xml b/main/pom.xml index 3bc583af..de18067f 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -109,6 +109,10 @@ tw.waterballsa.utopia weekly-messages-volume + + tw.waterballsa.utopia + manage-subscriber-role + diff --git a/main/src/main/resources/wsa.beta.properties b/main/src/main/resources/wsa.beta.properties index 333f403f..8b99fdcd 100644 --- a/main/src/main/resources/wsa.beta.properties +++ b/main/src/main/resources/wsa.beta.properties @@ -24,11 +24,17 @@ 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 wsa-long-article-role-id=1163842900933742592 wsa-topic-master-role-id=1163842370018754560 # Message ID unlock-entry-message-id=1038667013259792455 +manage-subscriber-role-message-id=1164966105555673108 # Forum ID flag-post-guide-id=1043565056765472798 diff --git a/main/src/main/resources/wsa.prod.properties b/main/src/main/resources/wsa.prod.properties index a20f0cce..43b3b229 100644 --- a/main/src/main/resources/wsa.prod.properties +++ b/main/src/main/resources/wsa.prod.properties @@ -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 diff --git a/unsubscribe-role/pom.xml b/manage-subscriber-role/pom.xml similarity index 93% rename from unsubscribe-role/pom.xml rename to manage-subscriber-role/pom.xml index 91c3002f..b3f58b00 100644 --- a/unsubscribe-role/pom.xml +++ b/manage-subscriber-role/pom.xml @@ -9,7 +9,7 @@ ${revision} - unsubscribe-role + manage-subscriber-role diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/ManageSubscribeRoleListener.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/ManageSubscribeRoleListener.kt new file mode 100644 index 00000000..d59dd71a --- /dev/null +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/ManageSubscribeRoleListener.kt @@ -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() + + /** + * "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}\" }" } + } + } + } + } + +} diff --git a/pom.xml b/pom.xml index 421dacb0..734a84fe 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ message-cherry-pick weekly-messages-volume utopia-test-kit - unsubscribe-role + manage-subscriber-role @@ -284,6 +284,11 @@ weekly-messages-volume ${revision} + + tw.waterballsa.utopia + manage-subscriber-role + ${revision} + tw.waterballsa.utopia utopia-test-kit diff --git a/unsubscribe-role/src/main/kotlin/tw/waterballsa/utopia/unsubscriberole/UnsubscribeRoleListener.kt b/unsubscribe-role/src/main/kotlin/tw/waterballsa/utopia/unsubscriberole/UnsubscribeRoleListener.kt deleted file mode 100644 index 1dd49bb5..00000000 --- a/unsubscribe-role/src/main/kotlin/tw/waterballsa/utopia/unsubscriberole/UnsubscribeRoleListener.kt +++ /dev/null @@ -1,31 +0,0 @@ -package tw.waterballsa.utopia.unsubscriberole - -import net.dv8tion.jda.api.events.emoji.EmojiAddedEvent -import org.springframework.stereotype.Component -import tw.waterballsa.utopia.commons.config.WsaDiscordProperties -import tw.waterballsa.utopia.jda.UtopiaListener - - -@Component -class UnsubscribeRoleListener(val wsa: WsaDiscordProperties): UtopiaListener() { - - private val emojiIdToRoleId = hashMapOf() - - /** - * prod beta - * "1️⃣":軟體英文派對訂閱者 1056758845264900166 1095747365215932487 - * "2️⃣":遊戲微服務計畫訂閱者 1042774972717871176 1038661611889631262 - * "3️⃣":純函式咖啡訂閱者 1038933719723020318 1095747473345097749 - * "4️⃣":技術演講吐司會訂閱者 1042775110630780958 1038661795507863623 - * "7️⃣":CS Lab 訂閱者 1051031301609758752 1095747425194483762 - */ - init { - emojiIdToRoleId[wsa.wsaGaaSMemberRoleId] = "2️⃣" - } - - override fun onEmojiAdded(event: EmojiAddedEvent) { - super.onEmojiAdded(event) - } - - -} From 6aac6117fb0034772496c53a54946b08ac3f1913 Mon Sep 17 00:00:00 2001 From: Wayne Tsou Date: Sun, 5 Nov 2023 15:43:53 +0800 Subject: [PATCH 4/6] =?UTF-8?q?:recycle:=20=E7=94=A8=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E8=A8=82=E9=96=B1/=E8=A7=A3=E9=99=A4=E8=A8=82=E9=96=B1?= =?UTF-8?q?=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractManageSubscriberRole.kt | 45 ++++++++++++ .../AddSubscriberRoleListener.kt | 23 ++++++ .../ManageSubscribeRoleListener.kt | 70 ------------------- .../RemoveSubscriberRoleListener.kt | 24 +++++++ 4 files changed, 92 insertions(+), 70 deletions(-) create mode 100644 manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt create mode 100644 manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt delete mode 100644 manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/ManageSubscribeRoleListener.kt create mode 100644 manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt new file mode 100644 index 00000000..2527664c --- /dev/null +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt @@ -0,0 +1,45 @@ +package tw.waterballsa.utopia.managesubscriberole + +import net.dv8tion.jda.api.entities.Guild +import net.dv8tion.jda.api.entities.Role +import net.dv8tion.jda.api.entities.UserSnowflake +import net.dv8tion.jda.api.events.message.react.GenericMessageReactionEvent +import tw.waterballsa.utopia.commons.config.WsaDiscordProperties +import tw.waterballsa.utopia.jda.UtopiaListener + +abstract class AbstractManageSubscriberRole(private val wsa: WsaDiscordProperties): UtopiaListener() { + + private val emojiToSubscriberRoleIdMap = hashMapOf() + + /** + * "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 + } + + /** + * 管理訂閱者身份組 + */ + protected fun manageSubscriberRole(event: T, + handleSubscriberRole: (guild: Guild, userSnowflake: UserSnowflake, role: Role) -> Unit) { + with(event) { + if (messageId != wsa.manageSubscriberRoleMessageId) { + return + } + emojiToSubscriberRoleIdMap[emoji.name]?.run { + val user = UserSnowflake.fromId(userId) + val role = jda.getRoleById(this)?: return + handleSubscriberRole(guild, user, role) + } + } + } +} diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt new file mode 100644 index 00000000..a7c57cb4 --- /dev/null +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt @@ -0,0 +1,23 @@ +package tw.waterballsa.utopia.managesubscriberole + +import mu.KotlinLogging +import net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent +import org.springframework.stereotype.Component +import tw.waterballsa.utopia.commons.config.WsaDiscordProperties + +private val logger = KotlinLogging.logger {} +@Component +class AddSubscriberRoleListener(wsa : WsaDiscordProperties) : AbstractManageSubscriberRole(wsa) { + + /** + * 移除表情時,新增對應訂閱者身份組 + */ + override fun onMessageReactionRemove(event: MessageReactionRemoveEvent) { + manageSubscriberRole(event) { guild, user, role -> + guild.addRoleToMember(user, role) + .queue { + logger.info { "[Add Role] {\"userId\":\"${user.id}\", \"roleName\":\"${role.name}\" }" } + } + } + } +} diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/ManageSubscribeRoleListener.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/ManageSubscribeRoleListener.kt deleted file mode 100644 index d59dd71a..00000000 --- a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/ManageSubscribeRoleListener.kt +++ /dev/null @@ -1,70 +0,0 @@ -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() - - /** - * "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}\" }" } - } - } - } - } - -} diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt new file mode 100644 index 00000000..12890147 --- /dev/null +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt @@ -0,0 +1,24 @@ +package tw.waterballsa.utopia.managesubscriberole + +import mu.KotlinLogging +import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent +import org.springframework.stereotype.Component +import tw.waterballsa.utopia.commons.config.WsaDiscordProperties + +private val logger = KotlinLogging.logger {} + +@Component +class RemoveSubscriberRoleListener(wsa : WsaDiscordProperties) : AbstractManageSubscriberRole(wsa) { + + /** + * 新增表情,移除對應訂閱者身份組 + */ + override fun onMessageReactionAdd(event: MessageReactionAddEvent) { + manageSubscriberRole(event) { guild, user, role -> + guild.removeRoleFromMember(user, role) + .queue { + logger.info { "[Remove Role] {\"userId\":\"${user.id}\", \"roleName\":\"${role.name}\" }" } + } + } + } +} From 57faa4d0e5653e540f1e23b9b031291dab63e9eb Mon Sep 17 00:00:00 2001 From: Wayne Tsou Date: Sun, 12 Nov 2023 16:26:36 +0800 Subject: [PATCH 5/6] =?UTF-8?q?:recycle:=20=E7=94=A8=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E8=A8=82=E9=96=B1/=E8=A7=A3=E9=99=A4=E8=A8=82=E9=96=B1?= =?UTF-8?q?=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修正命名 2. 調整Logging方式 3. 調整管理訂閱者身份組的實作方式 --- .../AbstractManageSubscriberRole.kt | 34 +++++++++---------- .../AddSubscriberRoleListener.kt | 5 +-- .../RemoveSubscriberRoleListener.kt | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt index 2527664c..1450d345 100644 --- a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt @@ -2,14 +2,13 @@ package tw.waterballsa.utopia.managesubscriberole import net.dv8tion.jda.api.entities.Guild import net.dv8tion.jda.api.entities.Role +import net.dv8tion.jda.api.entities.User import net.dv8tion.jda.api.entities.UserSnowflake import net.dv8tion.jda.api.events.message.react.GenericMessageReactionEvent import tw.waterballsa.utopia.commons.config.WsaDiscordProperties import tw.waterballsa.utopia.jda.UtopiaListener -abstract class AbstractManageSubscriberRole(private val wsa: WsaDiscordProperties): UtopiaListener() { - - private val emojiToSubscriberRoleIdMap = hashMapOf() +abstract class AbstractManageSubscriberRole(private val wsa: WsaDiscordProperties) : UtopiaListener() { /** * "1️⃣":軟體英文派對訂閱者 @@ -18,28 +17,29 @@ abstract class AbstractManageSubscriberRole(private val wsa: WsaDiscordPropertie * "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 - } + private val emojiToSubscriberRoleId = hashMapOf( + "1️⃣" to wsa.wsaSECSubsriberMemberRoleId, + "2️⃣" to wsa.wsaGaaSSubscriberRoleId, + "3️⃣" to wsa.wsaPurefuncSubscriberRoleId, + "4️⃣" to wsa.wsaTTMSubscriberRoleId, + "7️⃣" to wsa.wsaCSLabSubscriberRoleId + ) /** * 管理訂閱者身份組 */ - protected fun manageSubscriberRole(event: T, - handleSubscriberRole: (guild: Guild, userSnowflake: UserSnowflake, role: Role) -> Unit) { + protected fun manageSubscriberRole(event: T, + handleSubscriberRole: (guild: Guild, userSnowflake: UserSnowflake, role: Role) -> Unit) { with(event) { if (messageId != wsa.manageSubscriberRoleMessageId) { return } - emojiToSubscriberRoleIdMap[emoji.name]?.run { - val user = UserSnowflake.fromId(userId) - val role = jda.getRoleById(this)?: return - handleSubscriberRole(guild, user, role) - } + val user = User.fromId(userId) + val role = role ?: return + handleSubscriberRole(guild, user, role) } } + + private val GenericMessageReactionEvent.role: Role? + get() = emojiToSubscriberRoleId[emoji.name]?.let { jda.getRoleById(it) } } diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt index a7c57cb4..2fcda786 100644 --- a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt @@ -6,8 +6,9 @@ import org.springframework.stereotype.Component import tw.waterballsa.utopia.commons.config.WsaDiscordProperties private val logger = KotlinLogging.logger {} + @Component -class AddSubscriberRoleListener(wsa : WsaDiscordProperties) : AbstractManageSubscriberRole(wsa) { +class AddSubscriberRoleListener(wsa: WsaDiscordProperties) : AbstractManageSubscriberRole(wsa) { /** * 移除表情時,新增對應訂閱者身份組 @@ -16,7 +17,7 @@ class AddSubscriberRoleListener(wsa : WsaDiscordProperties) : AbstractManageSubs manageSubscriberRole(event) { guild, user, role -> guild.addRoleToMember(user, role) .queue { - logger.info { "[Add Role] {\"userId\":\"${user.id}\", \"roleName\":\"${role.name}\" }" } + logger.info { """[Add Role] {"userId":"${user.id}", "roleName":"${role.name}" }""" } } } } diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt index 12890147..8b32f5c6 100644 --- a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt @@ -17,7 +17,7 @@ class RemoveSubscriberRoleListener(wsa : WsaDiscordProperties) : AbstractManageS manageSubscriberRole(event) { guild, user, role -> guild.removeRoleFromMember(user, role) .queue { - logger.info { "[Remove Role] {\"userId\":\"${user.id}\", \"roleName\":\"${role.name}\" }" } + logger.info { """[Remove Role] {"userId":"${user.id}", "roleName":"${role.name}" }""" } } } } From 0fa393047aa52f80f296f9b1331bba2df6ba96aa Mon Sep 17 00:00:00 2001 From: Wayne Tsou Date: Sun, 24 Dec 2023 15:38:22 +0800 Subject: [PATCH 6/6] :recycle: Adjust manage subscriber role feature --- .../AbstractManageSubscriberRole.kt | 18 ++++++++---------- .../AddSubscriberRoleListener.kt | 9 ++++----- .../RemoveSubscriberRoleListener.kt | 11 +++++------ 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt index 1450d345..c36f4b9e 100644 --- a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AbstractManageSubscriberRole.kt @@ -1,10 +1,10 @@ package tw.waterballsa.utopia.managesubscriberole -import net.dv8tion.jda.api.entities.Guild import net.dv8tion.jda.api.entities.Role import net.dv8tion.jda.api.entities.User import net.dv8tion.jda.api.entities.UserSnowflake import net.dv8tion.jda.api.events.message.react.GenericMessageReactionEvent +import net.dv8tion.jda.api.requests.RestAction import tw.waterballsa.utopia.commons.config.WsaDiscordProperties import tw.waterballsa.utopia.jda.UtopiaListener @@ -28,18 +28,16 @@ abstract class AbstractManageSubscriberRole(private val wsa: WsaDiscordPropertie /** * 管理訂閱者身份組 */ - protected fun manageSubscriberRole(event: T, - handleSubscriberRole: (guild: Guild, userSnowflake: UserSnowflake, role: Role) -> Unit) { - with(event) { - if (messageId != wsa.manageSubscriberRoleMessageId) { - return - } - val user = User.fromId(userId) - val role = role ?: return - handleSubscriberRole(guild, user, role) + protected fun GenericMessageReactionEvent.manageSubscriberRole(handleSubscriberRole: (user: UserSnowflake, role: Role) -> RestAction): RestAction? { + if (messageId != wsa.manageSubscriberRoleMessageId) { + return null } + val user = User.fromId(userId) + val role = role ?: return null + return handleSubscriberRole(user, role).map { role } } + private val GenericMessageReactionEvent.role: Role? get() = emojiToSubscriberRoleId[emoji.name]?.let { jda.getRoleById(it) } } diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt index 2fcda786..980a585f 100644 --- a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/AddSubscriberRoleListener.kt @@ -14,11 +14,10 @@ class AddSubscriberRoleListener(wsa: WsaDiscordProperties) : AbstractManageSubsc * 移除表情時,新增對應訂閱者身份組 */ override fun onMessageReactionRemove(event: MessageReactionRemoveEvent) { - manageSubscriberRole(event) { guild, user, role -> - guild.addRoleToMember(user, role) - .queue { - logger.info { """[Add Role] {"userId":"${user.id}", "roleName":"${role.name}" }""" } - } + with(event) { + manageSubscriberRole(guild::addRoleToMember)?.queue { + logger.info { "[Add Role] {\"userId\":\"${userId}\", \"roleName\":\"${it.name}\" }" } + } } } } diff --git a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt index 8b32f5c6..9eb05d67 100644 --- a/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt +++ b/manage-subscriber-role/src/main/kotlin/tw/waterballsa/utopia/managesubscriberole/RemoveSubscriberRoleListener.kt @@ -8,17 +8,16 @@ import tw.waterballsa.utopia.commons.config.WsaDiscordProperties private val logger = KotlinLogging.logger {} @Component -class RemoveSubscriberRoleListener(wsa : WsaDiscordProperties) : AbstractManageSubscriberRole(wsa) { +class RemoveSubscriberRoleListener(wsa: WsaDiscordProperties) : AbstractManageSubscriberRole(wsa) { /** * 新增表情,移除對應訂閱者身份組 */ override fun onMessageReactionAdd(event: MessageReactionAddEvent) { - manageSubscriberRole(event) { guild, user, role -> - guild.removeRoleFromMember(user, role) - .queue { - logger.info { """[Remove Role] {"userId":"${user.id}", "roleName":"${role.name}" }""" } - } + with(event) { + manageSubscriberRole(guild::removeRoleFromMember)?.queue { + logger.info { "[Remove Role] {\"userId\":\"${userId}\", \"roleName\":\"${it.name}\" }" } + } } } }