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

feat: fixed audience counter permission problem #208

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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 @@ -12,7 +12,9 @@ import tw.waterballsa.utopia.commons.extensions.onStart
import tw.waterballsa.utopia.commons.extensions.toDate
import tw.waterballsa.utopia.jda.UtopiaListener
import tw.waterballsa.utopia.jda.extensions.getOptionAsPositiveInt
import java.time.LocalDateTime
import tw.waterballsa.utopia.jda.extensions.replyEphemerally
import net.dv8tion.jda.api.entities.Member
import java.time.LocalDateTime.now
import java.time.temporal.ChronoUnit
import java.util.*
import kotlin.concurrent.timerTask
Expand Down Expand Up @@ -41,17 +43,23 @@ class AudienceCounterListener(private val wsa: WsaDiscordProperties) : UtopiaLis
return
}

val recordPeriodTime =
getOptionAsPositiveInt(TIME_LENGTH)!!.toLong() // period time between startTime and endTime
val currentTime = LocalDateTime.now() // now time
val startRecordTime = currentTime.truncatedTo(ChronoUnit.MINUTES).toDate() // start time
val endRecordTime = currentTime.plusMinutes(recordPeriodTime).toDate() // end time
if (member.isAlpha()) {
val recordPeriodTime =
getOptionAsPositiveInt(TIME_LENGTH)!!.toLong()
val currentTime = now()
val startRecordTime = currentTime.truncatedTo(ChronoUnit.MINUTES).toDate()
val endRecordTime = currentTime.plusMinutes(recordPeriodTime).toDate()
Comment on lines +49 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 把 currentTimestartRecordTimeendRecordTime 封裝成一個具有領域意義類別,程式會更乾淨整潔

請參考 message-cherry-pickDateTimeRange


reply("counter start!!!").queue {
scheduledRecordHighestAudience(startRecordTime, endRecordTime)
reply("counter start!!!").queue {
scheduledRecordHighestAudience(startRecordTime, endRecordTime)
}
} else {
replyEphemerally("You should be the Alpha!")
}
}
}

private fun Member?.isAlpha(): Boolean = this?.roles?.any { it.id == wsa.wsaAlphaRoleId } ?: false
}

private fun SlashCommandInteractionEvent.scheduledRecordHighestAudience(startRecordTime: Date, endRecordTime: Date) {
Expand Down