Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Manage subscriber role #205 #219

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,103 @@ 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 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
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")
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")
gentlemenForumCategoryId = getProperty("wsa-gentlemen-forum-category-id")

// Post ID
waterBallJournalPostId = getProperty("water-ball-journal-post-id")
waterBallLoseWeightPostId = getProperty("water-ball-lose-weight-post-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>manage-subscriber-role</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
41 changes: 30 additions & 11 deletions main/src/main/resources/wsa.beta.properties
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
# 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-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
wsa-gentlemen-forum-category-id=1038657733286694922

# Post ID
water-ball-journal-post-id=1092095104472317994
water-ball-lose-weight-post-id=1091190313575526400
35 changes: 27 additions & 8 deletions main/src/main/resources/wsa.prod.properties
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
# 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
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
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
WayneTsou85 marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions manage-subscriber-role/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>
<groupId>tw.waterballsa.utopia</groupId>
<artifactId>root</artifactId>
<version>${revision}</version>
</parent>

<artifactId>manage-subscriber-role</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package tw.waterballsa.utopia.managesubscriberole

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

abstract class AbstractManageSubscriberRole(private val wsa: WsaDiscordProperties) : UtopiaListener() {

/**
* "1️⃣":軟體英文派對訂閱者
* "2️⃣":遊戲微服務計畫訂閱者
* "3️⃣":純函式咖啡訂閱者
* "4️⃣":技術演講吐司會訂閱者
* "7️⃣":CS Lab 訂閱者
*/
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 GenericMessageReactionEvent.manageSubscriberRole(handleSubscriberRole: (user: UserSnowflake, role: Role) -> RestAction<Void>): RestAction<Role>? {
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) }
}
Original file line number Diff line number Diff line change
@@ -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) {
with(event) {
manageSubscriberRole(guild::addRoleToMember)?.queue {
logger.info { "[Add Role] {\"userId\":\"${userId}\", \"roleName\":\"${it.name}\" }" }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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) {
with(event) {
manageSubscriberRole(guild::removeRoleFromMember)?.queue {
logger.info { "[Remove Role] {\"userId\":\"${userId}\", \"roleName\":\"${it.name}\" }" }
}
}
}
}
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>manage-subscriber-role</module>
</modules>

<properties>
Expand Down Expand Up @@ -283,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>
<dependency>
<groupId>tw.waterballsa.utopia</groupId>
<artifactId>utopia-test-kit</artifactId>
Expand Down
Loading