Skip to content

Commit

Permalink
fix: async send login qr
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Nov 13, 2021
1 parent f1875ea commit 452eef5
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.cssxsh.mirai.plugin.command

import kotlinx.coroutines.*
import net.mamoe.mirai.console.command.*
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
Expand All @@ -15,16 +16,18 @@ object WeiboLoginCommand : SimpleCommand(
) {
@Handler
suspend fun CommandSenderOnMessage<*>.hendle() = sendMessage { contact ->
runCatching {
client.qrcode { qrcode ->
logger.info("qrcode: $qrcode")
val image = try {
client.download(qrcode).toExternalResource().use { it.uploadAsImage(contact) }
} catch (e: Throwable) {
"$qrcode ".toPlainText()
}
client.runCatching {
qrcode { url ->
logger.info("qrcode: $url")
launch {
val image = try {
client.download(url).toExternalResource().use { it.uploadAsImage(contact) }
} catch (e: Throwable) {
"$url ".toPlainText()
}

sendMessage(image + "请使用微博客户端扫码")
sendMessage(image + "请使用微博客户端扫码")
}
}
}.onFailure {
logger.warning(it)
Expand All @@ -35,9 +38,11 @@ object WeiboLoginCommand : SimpleCommand(

@Handler
suspend fun ConsoleCommandSender.hendle() {
runCatching {
client.qrcode { qrcode ->
sendMessage("$qrcode 请使用微博客户端扫码")
client.runCatching {
qrcode { url ->
launch {
sendMessage("$url 请使用微博客户端扫码")
}
}
}.onFailure {
logger.warning(it)
Expand Down

0 comments on commit 452eef5

Please sign in to comment.