diff --git a/src/main/kotlin/net/taehui/twilight/Utility.kt b/src/main/kotlin/net/taehui/twilight/Utility.kt index 0374833..5d8c3ae 100644 --- a/src/main/kotlin/net/taehui/twilight/Utility.kt +++ b/src/main/kotlin/net/taehui/twilight/Utility.kt @@ -38,7 +38,8 @@ } fun getDefaultAvatarID(avatarID: String): String { - return PlatformIDSystem.getAvatarID(avatarID.substring(avatarID.indexOf("@") + 1)) + val platformID = avatarID.substring(avatarID.indexOf("@") + 1) + return PlatformIDSystem.getAvatarID(platformID) ?: platformID } fun getFaultText(e: Throwable): String { diff --git a/src/main/kotlin/net/taehui/twilight/qwilight/QwilightAvatar.kt b/src/main/kotlin/net/taehui/twilight/qwilight/QwilightAvatar.kt index 51f4a64..354bd82 100644 --- a/src/main/kotlin/net/taehui/twilight/qwilight/QwilightAvatar.kt +++ b/src/main/kotlin/net/taehui/twilight/qwilight/QwilightAvatar.kt @@ -877,7 +877,54 @@ IOUtils.copy(it, os) } } + + val avatarAbility = when (inputMode) { + Component.InputMode.INPUT_MODE_5_1 -> DB.getAvatarAbility5K(avatarID) + Component.InputMode.INPUT_MODE_7_1 -> DB.getAvatarAbility7K(avatarID) + Component.InputMode.INPUT_MODE_9 -> DB.getAvatarAbility9K(avatarID) + else -> 0.0 + } + val distanceAvatarAbility = avatarAbility - lastAvatarAbility + if (0 < distanceAvatarAbility) { + send(EventOuterClass.Event.EventID.ABILITY_UP, object { + val inputMode = inputMode + val ability = distanceAvatarAbility + }) + if (SiteHandler.hasAvatar(this, SiteHandler.commentSiteID)) { + SiteHandler.putSiteYell( + SiteHandler.commentSiteID, + JSON.TwilightAbilitySiteYell( + it, + avatarName, + inputMode, + distanceAvatarAbility + ) + ) + } + } + + val abilityClassText = + if (abilityClassVariety != null) AbilityClassSystem.getText( + abilityClassVariety, avatarAbility + ) else null + if (lastAbilityClassText != abilityClassText) { + send(EventOuterClass.Event.EventID.ABILITY_CLASS_UP, abilityClassText) + if (SiteHandler.hasAvatar(this, SiteHandler.commentSiteID)) { + SiteHandler.putSiteYell( + SiteHandler.commentSiteID, + JSON.TwilightAbilitySiteYell( + it, + avatarName, + inputMode, + distanceAvatarAbility + ) + ) + } + } + + PlatformSystem.setAbilityName(avatarID) } + DB.saveHandled( avatarID, targetComputing.noteID, @@ -891,6 +938,7 @@ noteModifyMode, lowestAudioMultiplier ) + if (SiteHandler.hasAvatar(this, SiteHandler.commentSiteID)) { SiteHandler.putSiteYell( SiteHandler.commentSiteID, @@ -909,13 +957,6 @@ } val titles = DB.getTitleItems(it) - val avatarAbility = when (inputMode) { - Component.InputMode.INPUT_MODE_5_1 -> DB.getAvatarAbility5K(avatarID) - Component.InputMode.INPUT_MODE_7_1 -> DB.getAvatarAbility7K(avatarID) - Component.InputMode.INPUT_MODE_9 -> DB.getAvatarAbility9K(avatarID) - else -> 0.0 - } - val avatarLevel = DB.getAvatarLevels(it)[0] val distanceTitles = titles.filter { !lastTitles.contains(it) }.toList() @@ -928,50 +969,13 @@ } } - val distanceAvatarAbility = avatarAbility - lastAvatarAbility - if (0 < distanceAvatarAbility) { - send(EventOuterClass.Event.EventID.ABILITY_UP, object { - val inputMode = inputMode - val ability = distanceAvatarAbility - }) - if (SiteHandler.hasAvatar(this, SiteHandler.commentSiteID)) { - SiteHandler.putSiteYell( - SiteHandler.commentSiteID, - JSON.TwilightAbilitySiteYell( - it, - avatarName, - inputMode, - distanceAvatarAbility - ) - ) - } - } - + val avatarLevel = DB.getAvatarLevels(it)[0] if (lastAvatarLevel < avatarLevel) { send(EventOuterClass.Event.EventID.LEVEL_UP, object { val from = lastAvatarLevel val to = avatarLevel }) } - - val abilityClassText = - if (abilityClassVariety != null) AbilityClassSystem.getText( - abilityClassVariety, avatarAbility - ) else null - if (lastAbilityClassText != abilityClassText) { - send(EventOuterClass.Event.EventID.ABILITY_CLASS_UP, abilityClassText) - if (SiteHandler.hasAvatar(this, SiteHandler.commentSiteID)) { - SiteHandler.putSiteYell( - SiteHandler.commentSiteID, - JSON.TwilightAbilitySiteYell( - it, - avatarName, - inputMode, - distanceAvatarAbility - ) - ) - } - } } } } diff --git a/src/main/kotlin/net/taehui/twilight/system/BannedIP.kt b/src/main/kotlin/net/taehui/twilight/system/BannedIP.kt index 90b1bce..39cfd9f 100644 --- a/src/main/kotlin/net/taehui/twilight/system/BannedIP.kt +++ b/src/main/kotlin/net/taehui/twilight/system/BannedIP.kt @@ -10,7 +10,7 @@ import java.util.concurrent.ConcurrentHashMap object BannedIP : Logger { - private var bannedIPStore = ConcurrentHashMap() + private val bannedIPStore = ConcurrentHashMap() private fun getJSONMapper(): ObjectMapper { val jm = ObjectMapper() diff --git a/src/main/kotlin/net/taehui/twilight/system/BannedNote.kt b/src/main/kotlin/net/taehui/twilight/system/BannedNote.kt index 95645b7..45fe6b8 100644 --- a/src/main/kotlin/net/taehui/twilight/system/BannedNote.kt +++ b/src/main/kotlin/net/taehui/twilight/system/BannedNote.kt @@ -8,7 +8,7 @@ import java.util.concurrent.ConcurrentHashMap object BannedNote : Logger { - private var bannedNoteStore = mutableMapOf() + private val bannedNoteStore = mutableMapOf() fun loadBannedNote() { try { diff --git a/src/main/kotlin/net/taehui/twilight/system/DB.kt b/src/main/kotlin/net/taehui/twilight/system/DB.kt index 812bcfa..c1f78d6 100644 --- a/src/main/kotlin/net/taehui/twilight/system/DB.kt +++ b/src/main/kotlin/net/taehui/twilight/system/DB.kt @@ -3069,7 +3069,7 @@ } } - fun getMaxAbilityName(avatarID: String): String { + fun getMaxAbilityName(avatarID: String?): String { val rawAbilities5K = getAbilities5K() val targetAbilities5K = getAbilities(rawAbilities5K).toList() val targetAbility5K = @@ -3871,7 +3871,6 @@ SELECT Avatar_ID, Avatar_Name, MAX(Band) AS Value FROM tw_comment INNER JOIN tn_avatar ON tw_comment.Avatar = tn_avatar.Avatar_ID - WHERE Is_Max = true GROUP BY Avatar_ID ORDER BY Value DESC LIMIT 50 @@ -3905,7 +3904,7 @@ yyyyMMDDFormat.format( LocalDate.now().withDayOfMonth(1) ) - }" <= tw_comment.Date AND Is_Max = true + }" <= tw_comment.Date GROUP BY Avatar_ID ORDER BY Value DESC LIMIT 50 diff --git a/src/main/kotlin/net/taehui/twilight/system/PlatformIDSystem.kt b/src/main/kotlin/net/taehui/twilight/system/PlatformIDSystem.kt index f6f85f4..4ae0ebb 100644 --- a/src/main/kotlin/net/taehui/twilight/system/PlatformIDSystem.kt +++ b/src/main/kotlin/net/taehui/twilight/system/PlatformIDSystem.kt @@ -9,9 +9,11 @@ object PlatformIDSystem : Logger { private var platformIDAvatarIDMap = ConcurrentHashMap() + private var avatarIDPlatformIDMap = ConcurrentHashMap() fun savePlatformID() { - ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(Paths.get("Platform ID.json").toFile().absoluteFile, platformIDAvatarIDMap) + ObjectMapper().writerWithDefaultPrettyPrinter() + .writeValue(Paths.get("Platform ID.json").toFile().absoluteFile, platformIDAvatarIDMap) logInfo("Saved Platform ID") } @@ -21,25 +23,40 @@ ObjectMapper().readValue(Paths.get("Platform ID.json").toFile().absoluteFile, object : TypeReference>() {}) ) + platformIDAvatarIDMap.forEach { (platformID, avatarID) -> + avatarIDPlatformIDMap[avatarID] = platformID + } logInfo("Loaded Platform ID") } catch (e: IOException) { logFault(e) } } - fun putPlatformID(platformID: String, avatarID: String) { - platformIDAvatarIDMap[if (platformID.startsWith("$")) platformID else "$$platformID"] = avatarID + fun putPlatformID(rawPlatformID: String, avatarID: String) { + val platformID = if (rawPlatformID.startsWith("$")) rawPlatformID else "$$rawPlatformID" + platformIDAvatarIDMap[platformID] = avatarID + avatarIDPlatformIDMap[avatarID] = platformID } - fun wipePlatformID(platformID: String) { - platformIDAvatarIDMap.remove(if (platformID.startsWith("$")) platformID else "$$platformID") + fun wipePlatformID(rawPlatformID: String) { + val platformID = if (rawPlatformID.startsWith("$")) rawPlatformID else "$$rawPlatformID" + val avatarID = platformIDAvatarIDMap.remove(platformID) + if (avatarID != null) { + avatarIDPlatformIDMap.remove(avatarID) + } } - fun getAvatarID(platformID: String): String { - return platformIDAvatarIDMap.getOrDefault(if (platformID.startsWith("$")) platformID else "$$platformID", platformID) + fun getAvatarID(rawPlatformID: String): String? { + val platformID = if (rawPlatformID.startsWith("$")) rawPlatformID else "$$rawPlatformID" + return platformIDAvatarIDMap[platformID] } - fun hasAvatarID(platformID: String): Boolean { - return platformIDAvatarIDMap.containsKey(if (platformID.startsWith("$")) platformID else "$$platformID") + fun getPlatformID(avatarID: String): String? { + return avatarIDPlatformIDMap[avatarID] + } + + fun hasPlatformID(rawPlatformID: String): Boolean { + val platformID = if (rawPlatformID.startsWith("$")) rawPlatformID else "$$rawPlatformID" + return platformIDAvatarIDMap.containsKey(platformID) } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt b/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt index 483c889..dcf4bb0 100644 --- a/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt +++ b/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt @@ -128,7 +128,7 @@ } fun onLogin(replyEvent: IReplyCallback, modalEvent: IModalCallback) { - if (PlatformIDSystem.hasAvatarID(replyEvent.user.id)) { + if (PlatformIDSystem.hasPlatformID(replyEvent.user.id)) { replyEvent.reply("You are already logged in").setEphemeral(true).queue() } else { modalEvent.replyModal( @@ -144,19 +144,6 @@ } } - fun onSetAbility(platformID: String): String { - val abilityName = DB.getMaxAbilityName( - PlatformIDSystem.getAvatarID(platformID) - ) - qwilightPlatform?.retrieveMemberById(platformID)?.queue { avatar -> - qwilightPlatform?.modifyMemberRoles( - avatar, - *(qwilightPlatform?.getRolesByName(abilityName, true)?.toTypedArray() ?: emptyArray()) - )?.queue() - } - return abilityName - } - override fun onButtonInteraction(event: ButtonInteractionEvent) { when (event.componentId) { "login" -> onLogin(event, event) @@ -179,17 +166,6 @@ override fun onSlashCommandInteraction(event: SlashCommandInteractionEvent) { when (event.name) { - "role" -> { - val platformID = event.user.id - if (PlatformIDSystem.hasAvatarID(platformID)) { - event.deferReply().queue() - event.hook.sendMessage("Your role is ${onSetAbility(platformID)}") - .setEphemeral(true).queue() - } else { - event.reply("You didn't log in").setEphemeral(true).queue() - } - } - "login" -> { onLogin(event, event) } @@ -219,12 +195,11 @@ JSON.TaehuiGetTotem::class.java ) - val platformID = event.user.id - PlatformIDSystem.putPlatformID(platformID, avatarID) + PlatformIDSystem.putPlatformID(event.user.id, avatarID) event.reply("You logged in as ${taehuiGetTotem.avatarName} to Qwilight Channel") .setEphemeral(true).queue() - onSetAbility(platformID) + setAbilityName(taehuiGetTotem.avatarID) } catch (e: HttpResponseException) { event.reply("Failed to log in").setEphemeral(true).queue() } @@ -372,4 +347,18 @@ fun getDrawing(avatarID: String): ByteArray? { return drawingStore[avatarID] } + + fun setAbilityName(avatarID: String) { + logFuture { + val abilityName = DB.getMaxAbilityName(avatarID) + PlatformIDSystem.getPlatformID(avatarID)?.let { + qwilightPlatform?.retrieveMemberById(it)?.queue { avatar -> + qwilightPlatform?.modifyMemberRoles( + avatar, + *(qwilightPlatform?.getRolesByName(abilityName, true)?.toTypedArray() ?: emptyArray()) + )?.queue() + } + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/system/StillSystem.kt b/src/main/kotlin/net/taehui/twilight/system/StillSystem.kt deleted file mode 100644 index bf5141c..0000000 --- a/src/main/kotlin/net/taehui/twilight/system/StillSystem.kt +++ /dev/null @@ -1,12 +0,0 @@ -package net.taehui.twilight.system - -import com.fasterxml.jackson.core.type.TypeReference -import com.fasterxml.jackson.databind.ObjectMapper -import net.taehui.twilight.system.BannedNote.logFault -import net.taehui.twilight.system.BannedNote.logInfo -import java.io.IOException -import java.nio.file.Paths -import java.util.concurrent.ConcurrentHashMap - -object StillSystem { -} \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt b/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt index 0291fb4..6782f05 100644 --- a/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt +++ b/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt @@ -186,7 +186,7 @@ val want = params.getOrDefault("want", "") if (want.isEmpty()) { send400(ctx) - }else { + } else { DB.getAvatar(want) .thenAccept { if (it != null) { @@ -350,24 +350,56 @@ } } - "/qwilight/www/hall/totalTotal" -> DB.getHallTotalTotal().thenAccept { send(ctx, it) } - "/qwilight/www/hall/atTotal" -> DB.getHallAtTotal().thenAccept { send(ctx, it) } - "/qwilight/www/hall/totalTop" -> DB.getHallTotalTop().thenAccept { send(ctx, it) } - "/qwilight/www/hall/atTop" -> DB.getHallAtTop().thenAccept { send(ctx, it) } - "/qwilight/www/hall/totalStand" -> DB.getHallTotalStand().thenAccept { send(ctx, it) } - "/qwilight/www/hall/atStand" -> DB.getHallAtStand().thenAccept { send(ctx, it) } - "/qwilight/www/hall/totalBand" -> DB.getHallTotalBand().thenAccept { send(ctx, it) } - "/qwilight/www/hall/atBand" -> DB.getHallAtBand().thenAccept { send(ctx, it) } + "/qwilight/www/hall/totalTotal" -> DB.getHallTotalTotal().thenAccept { + send(ctx, it) + } + + "/qwilight/www/hall/atTotal" -> DB.getHallAtTotal().thenAccept { + send(ctx, it) + } + + "/qwilight/www/hall/totalTop" -> DB.getHallTotalTop().thenAccept { + send(ctx, it) + } + + "/qwilight/www/hall/atTop" -> DB.getHallAtTop().thenAccept { + send(ctx, it) + } + + "/qwilight/www/hall/totalStand" -> DB.getHallTotalStand().thenAccept { + send(ctx, it) + } + + "/qwilight/www/hall/atStand" -> DB.getHallAtStand().thenAccept { + send(ctx, it) + } + + "/qwilight/www/hall/totalBand" -> DB.getHallTotalBand().thenAccept { + send(ctx, it) + } + + "/qwilight/www/hall/atBand" -> DB.getHallAtBand().thenAccept { + send(ctx, it) + } + "/qwilight/www/hall/ability/5K" -> DB.getHallAbility(Component.InputMode.INPUT_MODE_5_1) - .thenAccept { send(ctx, it) } + .thenAccept { + send(ctx, it) + } "/qwilight/www/hall/ability/7K" -> DB.getHallAbility(Component.InputMode.INPUT_MODE_7_1) - .thenAccept { send(ctx, it) } + .thenAccept { + send(ctx, it) + } "/qwilight/www/hall/ability/9K" -> DB.getHallAbility(Component.InputMode.INPUT_MODE_9) - .thenAccept { send(ctx, it) } + .thenAccept { + send(ctx, it) + } - "/qwilight/www/hall/level" -> DB.getHallLevel().thenAccept { send(ctx, it) } + "/qwilight/www/hall/level" -> DB.getHallLevel().thenAccept { + send(ctx, it) + } "/qwilight/www/etc" -> { DB.getEtc(language).thenAccept { send(ctx, it) } @@ -530,7 +562,7 @@ sendAvatarDrawing(avatarID) } } else if (avatarID.startsWith("$")) { - if (PlatformIDSystem.hasAvatarID(avatarID)) { + if (PlatformIDSystem.hasPlatformID(avatarID)) { sendAvatarDrawing(avatarID) } else { val avatarDrawing = PlatformSystem.getDrawing(avatarID)