Files
FancyBot/src/main/kotlin/cn/rtast/fancybot/util/Misc.kt
T

45 lines
1.2 KiB
Kotlin
Raw Normal View History

2024-09-05 13:40:41 +08:00
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/9/5
*/
package cn.rtast.fancybot.util
2024-10-06 18:07:32 +08:00
import cn.rtast.fancybot.*
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 {
val info = this.getGroupMemberInfo(groupId, userId)
return info.card ?: info.nickname
2024-10-06 11:28:56 +08:00
}
fun initCommandAndItem(rob: ROneBotFactory) {
val commandManager = rob.commandManager
commands.forEach { commandManager.register(it) }
items.forEach { itemManager.register(it) }
tasks.forEach { rob.scheduler.scheduleTask(it.value, 1000L, it.key) }
}
fun initFilesDir() {
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-09-05 13:40:41 +08:00
}