feat: add weekday select
This commit is contained in:
1 file changed
+19
-8
@@ -12,19 +12,30 @@ import cn.rtast.fancybot.entity.FKXQS
|
|||||||
import cn.rtast.fancybot.util.Http
|
import cn.rtast.fancybot.util.Http
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.util.BaseCommand
|
import cn.rtast.rob.util.BaseCommand
|
||||||
import cn.rtast.rob.util.ob.MessageChain
|
|
||||||
import cn.rtast.rob.util.ob.OneBotListener
|
import cn.rtast.rob.util.ob.OneBotListener
|
||||||
|
import java.time.DayOfWeek
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.ZoneId
|
||||||
|
|
||||||
@CommandDescription("今天是疯狂星期四!")
|
@CommandDescription("今天是疯狂星期四!")
|
||||||
class FKXQSCommand : BaseCommand() {
|
class FKXQSCommand : BaseCommand() {
|
||||||
override val commandNames = listOf("/fkxqs", "/fk", "/疯狂星期四")
|
override val commandNames = listOf("/fkxqs", "/kfc")
|
||||||
|
|
||||||
|
private fun isThursday(): Boolean {
|
||||||
|
val dateTime = LocalDateTime.ofInstant(
|
||||||
|
Instant.now(),
|
||||||
|
ZoneId.of("Asia/Shanghai")
|
||||||
|
)
|
||||||
|
return dateTime.dayOfWeek == DayOfWeek.THURSDAY
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
val response = Http.get<FKXQS>("https://api.shadiao.pro/kfc").data.text
|
if (!isThursday()) {
|
||||||
val msg = MessageChain.Builder()
|
message.reply("很可惜今天并不是星期四~")
|
||||||
.addAt(message.sender.userId)
|
return
|
||||||
.addText(response)
|
}
|
||||||
.build()
|
message.reply(Http.get<FKXQS>("https://api.shadiao.pro/kfc").data.text)
|
||||||
listener.sendGroupMessage(message.groupId, msg)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user