1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-25 04:50:26 +08:00

Rename tryLogin to login

This commit is contained in:
Him188 2019-10-03 19:32:58 +08:00
parent db77227d35
commit 71a1a40957
5 changed files with 12 additions and 7 deletions
mirai-console/src/main/java/net/mamoe/mirai
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai
mirai-demos/mirai-demo-1/src/main/java/demo1

View File

@ -145,8 +145,8 @@ object MiraiServer {
getLogger().info("Initializing [Bot] " + section.getString("account"));
try {
Bot bot = new Bot(section);
var state = bot.network.tryLogin$mirai_core().of();
//bot.network.tryLogin$mirai_core().whenComplete((state, e) -> {
var state = bot.network.login$mirai_core().of();
//bot.network.login$mirai_core().whenComplete((state, e) -> {
if (state == LoginState.SUCCESS) {
Bot.instances.add(bot);
getLogger().green(" Login Succeed");
@ -175,7 +175,7 @@ object MiraiServer {
val strings = it.split("----").dropLastWhile { it.isEmpty() }.toTypedArray()
val bot = Bot(BotAccount(strings[0].toLong(), strings[1]), Console())
if (runBlocking { bot.network.tryLogin(200) } === LoginState.SUCCESS) {
if (runBlocking { bot.network.login(200) } === LoginState.SUCCESS) {
bot.green("Login succeed")
return bot
}

View File

@ -27,7 +27,7 @@ val Bot.qqs: ContactList<QQ> get() = this.contacts.qqs
//NetworkHandler
suspend fun Bot.sendPacket(packet: ClientPacket) = this.network.socket.sendPacket(packet)
suspend fun Bot.login(touchingTimeoutMillis: Long = 200): LoginState = this.network.tryLogin()
suspend fun Bot.login(touchingTimeoutMillis: Long = 200): LoginState = this.network.login()
//BotAccount

View File

@ -58,7 +58,7 @@ interface BotNetworkHandler {
*
* @param touchingTimeoutMillis 连接每个服务器的 timeout
*/
suspend fun tryLogin(touchingTimeoutMillis: Long = 200): LoginState
suspend fun login(touchingTimeoutMillis: Long = 200): LoginState
/**
* 添加一个临时包处理器

View File

@ -48,7 +48,7 @@ internal class TIMBotNetworkHandler(private val bot: Bot) : BotNetworkHandler {
temporaryPacketHandlers.add(temporaryPacketHandler)
}
override suspend fun tryLogin(touchingTimeoutMillis: Long): LoginState {
override suspend fun login(touchingTimeoutMillis: Long): LoginState {
return loginInternal(touchingTimeoutMillis, LinkedList(TIMProtocol.SERVER_IP))
}

View File

@ -13,6 +13,8 @@ import net.mamoe.mirai.message.defaults.PlainText
import net.mamoe.mirai.network.protocol.tim.packet.login.LoginState
import net.mamoe.mirai.utils.BotAccount
import net.mamoe.mirai.utils.Console
import net.mamoe.mirai.utils.MiraiLogger
import kotlin.system.exitProcess
/**
* @author Him188moe
@ -24,7 +26,10 @@ suspend fun main() {
), Console())
bot.login().let {
check(it == LoginState.SUCCESS) { "Login failed: " + it.name }
if(it != LoginState.SUCCESS) {
MiraiLogger.error("Login failed: " + it.name)
exitProcess(0)
}
}