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

create tracking channel message count feature module #151

Closed
wants to merge 5 commits into from
Closed

create tracking channel message count feature module #151

wants to merge 5 commits into from

Conversation

wow890209
Copy link
Collaborator

#149

Why need this change? / Root cause:

  • 依照buffer需求新增的機器人功能

Changes made:

Test Scope / Change impact:

@wow890209 wow890209 requested review from Wally5077 and Mirai1129 June 29, 2023 13:03
@wow890209 wow890209 self-assigned this Jun 29, 2023
@wow890209 wow890209 linked an issue Jun 29, 2023 that may be closed by this pull request
Copy link
Collaborator

@Wally5077 Wally5077 left a comment

Choose a reason for hiding this comment

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

Review done.

Copy link
Collaborator

@Wally5077 Wally5077 left a comment

Choose a reason for hiding this comment

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

Review done.

Comment on lines 45 to 46
private val TAIPEI_ZONE_ID: ZoneId = ZoneId.of("Asia/Taipei")
private val DATE_FORMAT: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")
Copy link
Collaborator

Choose a reason for hiding this comment

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

這兩個屬性有必要自己宣告型別嗎?

Comment on lines 72 to 74
with(event) {
incrementMessageCount(message)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

只有一行就直接 incrementMessageCount(event.message)

Comment on lines 77 to 79
private fun incrementMessageCount(message: Message) {
commentCountRepository.incrementCountByQuery(Query(message.toDate(), message.author.id, message.channel.id))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

這邊 message 使用那麼多次就可以搭配 Scope Function 了

Comment on lines 89 to 96
if (tag != BUFFER_COMMAND_TAG) {
return
}

if (member.isAlphaMember().not()) {
reply("你沒有權限").queue()
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

組成一個 when



companion object {
private val jsonMapper = ObjectMapper()
Copy link
Collaborator

Choose a reason for hiding this comment

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

這邊依賴注入

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Collaborator

@Wally5077 Wally5077 left a comment

Choose a reason for hiding this comment

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

Review done.

Comment on lines +83 to +85
tag != BUFFER_COMMAND_TAG -> {
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

不用 lambda 展開,直接 return

Comment on lines +93 to +95
if (member.isAlphaMember()) {

}
Copy link
Collaborator

Choose a reason for hiding this comment

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

這是多餘的,前面有防呆了

Comment on lines +122 to +124
val year = getOption(YEAR)?.asInt ?: return Query.IGNORE
val month = getOption(MONTH)?.asInt ?: return Query.IGNORE
val day = getOption(DAY)?.asInt ?: return Query.IGNORE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Query.IGNORE 是個一眼就無法明白的寫法,Query.IGNORE 想要做什麼?


private fun getDate(year: Int, month: Int, day: Int): String {
return try {
LocalDate.of(year, month, day)?.format(DATE_FORMAT) ?: return Query.IGNORE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q:沒必要去 format 成字串吧?

while (true) {
val history = getHistoryBefore(messageIterator, 100).complete().retrievedHistory.filterNotNull()
messages.addAll(history)
history.ifEmpty { return messages }
Copy link
Collaborator

Choose a reason for hiding this comment

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

這是 while 條件式,那 while 外就應該宣告一個變數裝它

private fun TextChannel.getAllMessages(): List<Message> {
val messages = mutableListOf<Message>(retrieveMessageById(latestMessageId).complete())

var messageIterator = latestMessageId
Copy link
Collaborator

Choose a reason for hiding this comment

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

messageIterator -> latestMessageId

@wow890209 wow890209 closed this by deleting the head repository Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[任務] 全自動化紀錄頻道留言數
3 participants