mirai/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo1/Main.kt

37 lines
902 B
Kotlin
Raw Normal View History

2019-10-26 17:06:40 +08:00
@file:Suppress("EXPERIMENTAL_UNSIGNED_LITERALS", "EXPERIMENTAL_API_USAGE")
package demo1
import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.login
2019-10-26 17:17:46 +08:00
import net.mamoe.mirai.network.protocol.tim.packet.login.requireSuccess
2019-10-26 17:06:40 +08:00
import java.io.File
private fun readTestAccount(): BotAccount? {
val file = File("testAccount.txt")
if (!file.exists() || !file.canRead()) {
return null
}
val lines = file.readLines()
return try {
BotAccount(lines[0].toUInt(), lines[1])
} catch (e: IndexOutOfBoundsException) {
null
}
}
@Suppress("UNUSED_VARIABLE")
suspend fun main() {
val bot = Bot(
readTestAccount() ?: BotAccount(//填写你的账号
id = 1994701121u,
password = "123456"
)
)
2019-10-26 17:17:46 +08:00
bot.login().requireSuccess()
2019-10-26 17:06:40 +08:00
bot.network.awaitDisconnection()//等到直到断开连接
}