2024-09-05 13:40:41 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2024 RTAkland
|
|
|
|
|
* Author: RTAkland
|
|
|
|
|
* Date: 2024/9/5
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2024-10-09 13:06:43 +08:00
|
|
|
package cn.rtast.fancybot.util.misc
|
2024-09-05 13:40:41 +08:00
|
|
|
|
2024-10-06 18:07:32 +08:00
|
|
|
import cn.rtast.fancybot.*
|
2024-10-09 13:06:43 +08:00
|
|
|
import cn.rtast.fancybot.util.Http
|
2024-10-24 16:55:14 +08:00
|
|
|
import cn.rtast.rob.BotInstance
|
2024-10-06 11:28:56 +08:00
|
|
|
import cn.rtast.rob.ROneBotFactory
|
2024-09-26 21:56:44 +08:00
|
|
|
import cn.rtast.rob.util.ob.OneBotListener
|
2024-10-06 11:28:56 +08:00
|
|
|
import java.io.File
|
2024-09-05 13:40:41 +08:00
|
|
|
import kotlin.random.Random
|
|
|
|
|
|
|
|
|
|
fun randomBooleanWithProbability(probability: Double): Boolean {
|
|
|
|
|
val randomValue = Random.nextInt(100)
|
|
|
|
|
return randomValue <= (probability * 100)
|
2024-09-26 21:56:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suspend fun OneBotListener.getUserName(groupId: Long, userId: Long): String {
|
2024-10-24 16:55:14 +08:00
|
|
|
val info = instance.action.getGroupMemberInfo(groupId, userId)
|
2024-09-26 21:56:44 +08:00
|
|
|
return info.card ?: info.nickname
|
2024-10-06 11:28:56 +08:00
|
|
|
}
|
|
|
|
|
|
2024-10-24 16:55:14 +08:00
|
|
|
fun initCommand() {
|
|
|
|
|
commands.forEach { ROneBotFactory.commandManager.register(it) }
|
2024-10-06 11:28:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun initFilesDir() {
|
2024-10-07 19:13:51 +08:00
|
|
|
File("$ROOT_PATH/caches/images").also { it.mkdirs() }
|
|
|
|
|
File("$ROOT_PATH/logs").also { it.mkdirs() }
|
2024-10-06 18:20:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun initSetuIndex() {
|
|
|
|
|
val file = File("$ROOT_PATH/caches/pixiv_index_v3.json")
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
file.createNewFile()
|
|
|
|
|
val fileContent = Http.get("$ASSETS_BASE_URL/files/pixiv_index_v3.json")
|
|
|
|
|
file.writeText(fileContent)
|
|
|
|
|
}
|
2024-10-15 18:58:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun initItems() {
|
|
|
|
|
items.forEach { itemManager.register(it) }
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-24 16:55:14 +08:00
|
|
|
fun initBackgroundTasks(instance: BotInstance) {
|
|
|
|
|
tasks.forEach { instance.scheduler.scheduleTask(it.value, 1000L, it.key) }
|
2024-09-05 13:40:41 +08:00
|
|
|
}
|