Skip to content

Commit

Permalink
0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxue1272 committed Jul 6, 2023
1 parent 8d2715b commit 61e4889
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Expand Up @@ -22,7 +22,7 @@ enum class SkikoOSArch(
}

group = "io.tiangou.valobot"
version = "0.5.0"
version = "0.5.1"

val kotlinVersion = "1.8.20"
val ktorVersion = "2.2.4"
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/tiangou/ValorantBotPlugin.kt
Expand Up @@ -72,7 +72,7 @@ object ValorantBotPlugin : KotlinPlugin(
description = JvmPluginDescription(
id = "io.tiangou.valorant-bot-plugin",
name = "valorant-bot-plugin",
version = "0.5.0"
version = "0.5.1"
)
{
author("xiaoxue1272")
Expand Down
24 changes: 14 additions & 10 deletions src/main/kotlin/io/tiangou/logic/LogicProcessor.kt
Expand Up @@ -10,6 +10,7 @@ import io.tiangou.api.data.AuthRequest
import io.tiangou.api.data.AuthResponse
import io.tiangou.api.data.MultiFactorAuthRequest
import io.tiangou.logic.utils.GenerateImageType
import io.tiangou.logic.utils.StoreApiHelper
import io.tiangou.logic.utils.StoreImageHelper
import io.tiangou.other.http.actions
import io.tiangou.other.http.client
Expand Down Expand Up @@ -98,11 +99,7 @@ object LoginRiotAccountLogicProcessor : LogicProcessor<MessageEvent> {
)
when (authResponse.type) {
AuthResponse.RESPONSE -> {
flushAccessToken(authResponse.response!!.parameters.uri)
flushXRiotEntitlementsJwt(RiotApi.EntitlementsAuth.execute().entitlementsToken)
puuid = RiotApi.PlayerInfo.execute().sub
event.reply("登录成功")
userCache.isRiotAccountLogin = true
userCache.loginSuccessfulHandle(event, authResponse.response!!.parameters.uri)
}

AuthResponse.MULTI_FACTOR -> {
Expand All @@ -118,6 +115,16 @@ object LoginRiotAccountLogicProcessor : LogicProcessor<MessageEvent> {
}
}

internal suspend fun UserCache.loginSuccessfulHandle(event: MessageEvent, authUrl: String) {
StoreApiHelper.clean(this)
StoreImageHelper.clean(this)
riotClientData.flushAccessToken(authUrl)
riotClientData.flushXRiotEntitlementsJwt(RiotApi.EntitlementsAuth.execute().entitlementsToken)
riotClientData.puuid = RiotApi.PlayerInfo.execute().sub
event.reply("登录成功")
isRiotAccountLogin = true
}

@Serializable
object VerifyRiotAccountLogicProcessor : LogicProcessor<MessageEvent> {

Expand All @@ -128,11 +135,7 @@ object VerifyRiotAccountLogicProcessor : LogicProcessor<MessageEvent> {
val authResponse = RiotApi.MultiFactorAuth.execute(MultiFactorAuthRequest(event.message.toText()))
when (authResponse.type) {
AuthResponse.RESPONSE -> {
flushAccessToken(authResponse.response!!.parameters.uri)
flushXRiotEntitlementsJwt(RiotApi.EntitlementsAuth.execute().entitlementsToken)
puuid = RiotApi.PlayerInfo.execute().sub
event.reply("登录成功")
userCache.isRiotAccountLogin = true
userCache.loginSuccessfulHandle(event, authResponse.response!!.parameters.uri)
}

else -> event.reply("登录失败,请重新登录")
Expand Down Expand Up @@ -162,6 +165,7 @@ object SaveLocationShardLogicProcessor : LogicProcessor<MessageEvent> {
userCache.riotClientData.region = it.region
event.reply("设置成功")
StoreImageHelper.clean(userCache)
StoreApiHelper.clean(userCache)
return false
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/io/tiangou/logic/utils/StoreImageHelper.kt
Expand Up @@ -105,18 +105,26 @@ object StoreApiHelper {
RiotApi.Storefront.execute(StorefrontRequest(shard!!, puuid!!))
}.apply { storeFronts[userCache.riotClientData.puuid!!] = this }

suspend fun querySkinsPanelLayout(userCache: UserCache): List<String> {
internal suspend fun querySkinsPanelLayout(userCache: UserCache): List<String> {
return storeFronts[userCache.riotClientData.puuid!!]?.skinsPanelLayout?.singleItemOffers ?: invokeRiotApi(
userCache
).skinsPanelLayout.singleItemOffers
}

suspend fun queryAccessoryStore(userCache: UserCache): List<StoreFrontResponse.AccessoryStore.AccessoryStoreOffer> {
internal suspend fun queryAccessoryStore(userCache: UserCache): List<StoreFrontResponse.AccessoryStore.AccessoryStoreOffer> {
return storeFronts[userCache.riotClientData.puuid!!]?.accessoryStore?.accessoryStoreOffers ?: invokeRiotApi(
userCache
).accessoryStore.accessoryStoreOffers
}

fun clean(userCache: UserCache) {
userCache.riotClientData.puuid?.let {
synchronized(userCache) {
storeFronts.remove(it)
}
}
}

internal val storeFronts: ConcurrentHashMap<String, StoreFrontResponse> by lazy { ConcurrentHashMap() }


Expand Down

0 comments on commit 61e4889

Please sign in to comment.