mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 02:20:14 +08:00
45 lines
1.0 KiB
Kotlin
45 lines
1.0 KiB
Kotlin
@file:Suppress("EXPERIMENTAL_UNSIGNED_LITERALS", "EXPERIMENTAL_API_USAGE")
|
|
|
|
package demo.gentleman
|
|
|
|
import net.mamoe.mirai.Bot
|
|
import net.mamoe.mirai.BotAccount
|
|
import net.mamoe.mirai.event.events.FriendMessageEvent
|
|
import net.mamoe.mirai.event.subscribeAlways
|
|
import net.mamoe.mirai.login
|
|
import net.mamoe.mirai.network.protocol.tim.packet.login.requireSuccess
|
|
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"
|
|
)
|
|
)
|
|
|
|
bot.login().requireSuccess()
|
|
|
|
bot.subscribeAlways<FriendMessageEvent> {
|
|
|
|
}
|
|
|
|
|
|
|
|
bot.network.awaitDisconnection()//等到直到断开连接
|
|
} |