Skip to content

Commit

Permalink
optimize oci
Browse files Browse the repository at this point in the history
  • Loading branch information
kukume committed Jul 10, 2024
1 parent ba1b942 commit f3d85ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/main/kotlin/me/kuku/telegram/context/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private val callbackAfter by lazy {
}

@Suppress("ConstPropertyName")
private data class History(var message: Message?, var data: String): Serializable {
private data class History(var message: Message?, var data: String, var text: String? = null): Serializable {
companion object {
private const val serialVersionUID = 1L
}
Expand Down Expand Up @@ -118,13 +118,13 @@ class TelegramContext(override val bot: TelegramBot, val update: Update): Contex
arrayListOf()
}
val lastButton = message.replyMarkup().inlineKeyboard().last().last()
val lastCallbackData = lastButton.callbackData()
if (lastCallbackData == data && lastButton.text() == "返回" && history.find { it.data == lastCallbackData } == null) {
val lastCallbackData = lastButton.callbackData
if (lastCallbackData == data && lastButton.text == "返回" && history.find { it.data == lastCallbackData } == null) {
errorAnswerCallbackQuery("该返回按钮不可用,缓存已过期")
}
if (history.isEmpty() || (history.lastOrNull() != null && history.last().data != data)) {
if (history.lastOrNull() == null) {
history.addLast(History(message, "return_${UUID.randomUUID()}"))
history.addLast(History(message, "return_${UUID.randomUUID()}", message.text()))
} else {
history.last().message = message
}
Expand Down Expand Up @@ -218,7 +218,7 @@ class MonitorReturn(
val first = list?.first()
if (first?.data == data) {
val message = first.message!!
val editMessageText = EditMessageText(tgId, mes, message.text())
val editMessageText = EditMessageText(tgId, mes, first.text)
.replyMarkup(message.replyMarkup())
telegramBot.asyncExecute(editMessageText)
} else {
Expand Down
20 changes: 13 additions & 7 deletions src/main/kotlin/me/kuku/telegram/extension/OciExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.oracle.bmc.core.model.PortRange
import com.oracle.bmc.model.BmcException
import com.pengrad.telegrambot.model.request.InlineKeyboardButton
import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup
import com.pengrad.telegrambot.request.GetFile
import kotlinx.coroutines.delay
import me.kuku.telegram.context.*
import me.kuku.telegram.entity.OciEntity
Expand Down Expand Up @@ -67,14 +68,19 @@ class OciExtension(

fun TelegramSubscribe.oci() {
callback("addOci") {
editMessageText("请发送租户id")
val tenantId = nextMessage().text()
editMessageText("请发送用户id")
val userid = nextMessage().text()
editMessageText("请发送租户id,该id应以ocid1.tenancy.oc1开头")
val tenantId = nextMessage(maxTime = 1000 * 60).text()
editMessageText("请发送用户id,该id应以ocid1.user.oc1开头")
val userid = nextMessage(maxTime = 1000 * 60).text()
editMessageText("请发送api密钥配置文件中的fingerprint")
val fingerprint = nextMessage().text()
editMessageText("请发送创建api密钥下载的私钥信息,请复制全部内容并发送")
val privateKey = nextMessage().text()
val fingerprint = nextMessage(maxTime = 1000 * 60).text()
editMessageText("请发送创建api密钥下载的私钥信息,请复制全部内容发送或者发送该私钥文件")
val privateKeyMessage = nextMessage(maxTime = 1000 * 60)
val privateKey = if (privateKeyMessage.document() != null) {
val fileId = privateKeyMessage.document().fileId()
val fileResponse = bot.asyncExecute(GetFile(fileId))
String(fileResponse.file().byteArray())
} else privateKeyMessage.text()
bindCache.put(tgId, OciEntity().also {
it.tenantId = tenantId
it.userid = userid
Expand Down

0 comments on commit f3d85ce

Please sign in to comment.