From 6c52b01cd775aa470ff2bc745b8415e68f8a4238 Mon Sep 17 00:00:00 2001
From: BingZi-233
Date: Mon, 8 Jan 2024 15:49:19 +0800
Subject: [PATCH] =?UTF-8?q?update:=20=E9=87=8D=E6=9E=84=E9=93=BE=E5=BC=8F?=
=?UTF-8?q?=E7=BB=84=E8=A3=85=E6=A8=A1=E5=BC=8F=E4=B8=94=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?debug=E6=A8=A1=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 16 +++++++++
gradle.properties | 2 +-
.../video/internal/command/MainCommand.kt | 6 ++--
.../video/internal/config/SettingConfig.kt | 3 ++
.../video/internal/engine/NetworkEngine.kt | 9 ++---
.../internal/expand/PlaceholderExpand.kt | 11 ++++++-
.../video/internal/handler/ApiHandler.kt | 9 ++++-
.../video/internal/handler/ApiType.kt | 33 +++++++++++++++++++
.../video/internal/handler/CoinsHandler.kt | 12 +++++++
.../video/internal/handler/FavouredHandler.kt | 12 +++++++
.../internal/handler/FollowingHandler.kt | 12 +++++++
.../video/internal/handler/LikeHandler.kt | 12 +++++++
.../video/internal/helper/StatusHelper.kt | 4 +++
src/main/resources/setting.yml | 3 ++
14 files changed, 133 insertions(+), 11 deletions(-)
create mode 100644 src/main/kotlin/online/bingiz/bilibili/video/internal/handler/ApiType.kt
create mode 100644 src/main/kotlin/online/bingiz/bilibili/video/internal/helper/StatusHelper.kt
diff --git a/README.md b/README.md
index b17db0f..32ed2c5 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
## WIKI
@@ -114,3 +126,7 @@ BV1Qs411d7pD:
7. **接受条款:** 使用本软件即代表您同意并接受本免责声明的所有条款和条件。
如有任何疑问或异议,请立即停止使用本软件并与作者联系。
+
+## 相关平台
+
+![](https://sq.bingzi.online/api/project_badges/quality_gate?project=BilibiliVideo&token=sqb_dbb7c6fff0406277e807aea516f1f87bea5c3550)
diff --git a/gradle.properties b/gradle.properties
index 15138ce..9282254 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,2 +1,2 @@
group=online.bingiz.bilibili.video
-version=1.4.3
+version=1.4.4
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/command/MainCommand.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/command/MainCommand.kt
index d7a395b..4b96bad 100644
--- a/src/main/kotlin/online/bingiz/bilibili/video/internal/command/MainCommand.kt
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/command/MainCommand.kt
@@ -12,6 +12,7 @@ import taboolib.common.platform.ProxyPlayer
import taboolib.common.platform.command.*
import taboolib.common.platform.function.getProxyPlayer
import taboolib.common.platform.function.submit
+import taboolib.module.chat.colored
import taboolib.module.lang.sendInfoMessage
import taboolib.platform.util.bukkitPlugin
@@ -127,8 +128,9 @@ object MainCommand {
@CommandBody(permission = "BilibiliVideo.command.version", permissionDefault = PermissionDefault.OP)
val version = subCommand {
execute { sender, _, _ ->
- sender.sendInfoMessage("插件版本: ${bukkitPlugin.description.version}")
- sender.sendInfoMessage("插件作者: ${bukkitPlugin.description.authors.joinToString(", ")}")
+ sender.sendInfoMessage("&a&l插件名称 > ${bukkitPlugin.description.name}".colored())
+ sender.sendInfoMessage("&a&l插件版本 > ${bukkitPlugin.description.version}".colored())
+ sender.sendInfoMessage("&a&l插件作者 > ${bukkitPlugin.description.authors.joinToString(", ")}".colored())
}
}
}
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/config/SettingConfig.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/config/SettingConfig.kt
index 4a5265b..8e1961f 100644
--- a/src/main/kotlin/online/bingiz/bilibili/video/internal/config/SettingConfig.kt
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/config/SettingConfig.kt
@@ -1,6 +1,7 @@
package online.bingiz.bilibili.video.internal.config
import online.bingiz.bilibili.video.internal.cache.baffleCache
+import online.bingiz.bilibili.video.internal.helper.debugStatus
import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common5.Baffle
@@ -36,5 +37,7 @@ object SettingConfig {
baffleCache = Baffle.of(cooldown, TimeUnit.SECONDS)
// 变更是否需要关注
needFollow = config.getBoolean("needFollow")
+ // 调试模式是否开启
+ debugStatus = config.getBoolean("debug")
}
}
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt
index 9fff40b..c100628 100644
--- a/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt
@@ -7,10 +7,7 @@ import online.bingiz.bilibili.video.internal.database.Database.Companion.setData
import online.bingiz.bilibili.video.internal.engine.drive.BilibiliApiDrive
import online.bingiz.bilibili.video.internal.engine.drive.BilibiliPassportDrive
import online.bingiz.bilibili.video.internal.entity.*
-import online.bingiz.bilibili.video.internal.handler.CoinsHandler
-import online.bingiz.bilibili.video.internal.handler.FavouredHandler
-import online.bingiz.bilibili.video.internal.handler.FollowingHandler
-import online.bingiz.bilibili.video.internal.handler.LikeHandler
+import online.bingiz.bilibili.video.internal.handler.ApiType
import online.bingiz.bilibili.video.internal.helper.*
import org.bukkit.Bukkit
import retrofit2.Call
@@ -58,9 +55,9 @@ object NetworkEngine {
/**
* Show action
- * Show模式动作
+ * Show模式动作处理链
*/
- private val showAction = FollowingHandler().setNextHandler(LikeHandler().setNextHandler(CoinsHandler().setNextHandler(FavouredHandler())))
+ private val showAction = ApiType.buildHandler(ApiType.COINS, ApiType.LIKE, ApiType.FAVOURED, ApiType.FOLLOWING)
/**
* Generate bilibili QRCode url
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/expand/PlaceholderExpand.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/expand/PlaceholderExpand.kt
index 72e183a..46a6558 100644
--- a/src/main/kotlin/online/bingiz/bilibili/video/internal/expand/PlaceholderExpand.kt
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/expand/PlaceholderExpand.kt
@@ -1,5 +1,7 @@
package online.bingiz.bilibili.video.internal.expand
+import online.bingiz.bilibili.video.internal.cache.midCache
+import online.bingiz.bilibili.video.internal.cache.unameCache
import org.bukkit.entity.Player
import taboolib.platform.compat.PlaceholderExpansion
@@ -14,6 +16,13 @@ object PlaceholderExpand : PlaceholderExpansion {
get() = "BilibiliVideo"
override fun onPlaceholderRequest(player: Player?, args: String): String {
- return "N/A"
+ if (player == null) {
+ return "N/A"
+ }
+ return when (args) {
+ "uid" -> midCache[player.uniqueId] ?: "N/A-缓存"
+ "uname" -> unameCache[player.uniqueId] ?: "N/A-缓存"
+ else -> "N/A-未知参数"
+ }
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/ApiHandler.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/ApiHandler.kt
index c3f6c5e..b1d5af1 100644
--- a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/ApiHandler.kt
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/ApiHandler.kt
@@ -1,6 +1,8 @@
package online.bingiz.bilibili.video.internal.handler
+import online.bingiz.bilibili.video.internal.helper.debugStatus
import taboolib.common.platform.ProxyPlayer
+import taboolib.common.platform.function.info
abstract class ApiHandler {
private var nextHandler: ApiHandler? = null
@@ -13,6 +15,11 @@ abstract class ApiHandler {
abstract fun handle(player: ProxyPlayer, bvid: String, sessData: String): Boolean
protected fun callNextHandler(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
- return nextHandler?.handle(player, bvid, sessData) ?: true
+ return nextHandler?.handle(player, bvid, sessData) ?: let {
+ if (debugStatus) {
+ info("最终处理器 > 玩家: ${player.name} | 视频: $bvid | 通过")
+ }
+ true
+ }
}
}
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/ApiType.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/ApiType.kt
new file mode 100644
index 0000000..6f43460
--- /dev/null
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/ApiType.kt
@@ -0,0 +1,33 @@
+package online.bingiz.bilibili.video.internal.handler
+
+/**
+ * Api type
+ *
+ *
+ * @constructor Create empty Api type
+ */
+enum class ApiType(val apiHandler: ApiHandler) {
+ COINS(CoinsHandler()),
+ FAVOURED(FavouredHandler()),
+ FOLLOWING(FollowingHandler()),
+ LIKE(LikeHandler());
+
+ companion object {
+ /**
+ * Build handler
+ * 构建处理器依据指定顺序
+ *
+ * @param apiType
+ * @return
+ */
+ fun buildHandler(vararg apiType: ApiType): ApiHandler {
+ requireNotNull(apiType) {
+ error("至少需要一个 ApiType 来生成处理程序")
+ }
+ for (i in 0 until apiType.size - 1) {
+ apiType[i].apiHandler.setNextHandler(apiType[i + 1].apiHandler)
+ }
+ return apiType[0].apiHandler
+ }
+ }
+}
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/CoinsHandler.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/CoinsHandler.kt
index e947230..1bacbc9 100644
--- a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/CoinsHandler.kt
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/CoinsHandler.kt
@@ -1,8 +1,11 @@
package online.bingiz.bilibili.video.internal.handler
import online.bingiz.bilibili.video.internal.engine.NetworkEngine
+import online.bingiz.bilibili.video.internal.helper.debugStatus
import online.bingiz.bilibili.video.internal.helper.infoAsLang
import taboolib.common.platform.ProxyPlayer
+import taboolib.common.platform.function.info
+import taboolib.common.platform.function.warning
/**
* Coins handler
@@ -12,11 +15,17 @@ import taboolib.common.platform.ProxyPlayer
*/
class CoinsHandler : ApiHandler() {
override fun handle(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
+ if (debugStatus) {
+ info("硬币处理器 > 玩家: ${player.name} | 视频: $bvid | 接受处理")
+ }
NetworkEngine.bilibiliAPI.hasCoins(bvid, sessData).execute().let {
if (it.isSuccessful) {
it.body()?.data?.multiply?.let { count ->
if (count < 1) {
player.infoAsLang("GetTripleStatusFailureNotCoins")
+ if (debugStatus) {
+ warning("硬币处理器 > 玩家: ${player.name} | 视频: $bvid | 硬币不足")
+ }
return false
}
}
@@ -24,6 +33,9 @@ class CoinsHandler : ApiHandler() {
player.infoAsLang("NetworkRequestFailureCode", it.code())
}
}
+ if (debugStatus) {
+ info("硬币处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
+ }
return callNextHandler(player, bvid, sessData)
}
}
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/FavouredHandler.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/FavouredHandler.kt
index e7b29dd..ca579f7 100644
--- a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/FavouredHandler.kt
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/FavouredHandler.kt
@@ -1,8 +1,11 @@
package online.bingiz.bilibili.video.internal.handler
import online.bingiz.bilibili.video.internal.engine.NetworkEngine
+import online.bingiz.bilibili.video.internal.helper.debugStatus
import online.bingiz.bilibili.video.internal.helper.infoAsLang
import taboolib.common.platform.ProxyPlayer
+import taboolib.common.platform.function.info
+import taboolib.common.platform.function.warning
/**
* Favoured handler
@@ -12,11 +15,17 @@ import taboolib.common.platform.ProxyPlayer
*/
class FavouredHandler : ApiHandler() {
override fun handle(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
+ if (debugStatus) {
+ info("收藏处理器 > 玩家: ${player.name} | 视频: $bvid | 接受处理")
+ }
NetworkEngine.bilibiliAPI.hasFavoured(bvid, sessData).execute().let { resultResponse ->
if (resultResponse.isSuccessful) {
resultResponse.body()?.data?.let {
if (it.favoured.not()) {
player.infoAsLang("GetTripleStatusFailureNotFavoured")
+ if (debugStatus) {
+ warning("收藏处理器 > 玩家: ${player.name} | 视频: $bvid | 未收藏")
+ }
return false
}
}
@@ -24,6 +33,9 @@ class FavouredHandler : ApiHandler() {
player.infoAsLang("NetworkRequestFailureCode", resultResponse.code())
}
}
+ if (debugStatus) {
+ info("收藏处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
+ }
return callNextHandler(player, bvid, sessData)
}
}
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/FollowingHandler.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/FollowingHandler.kt
index bec7839..58ed10a 100644
--- a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/FollowingHandler.kt
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/FollowingHandler.kt
@@ -2,8 +2,11 @@ package online.bingiz.bilibili.video.internal.handler
import online.bingiz.bilibili.video.internal.config.SettingConfig
import online.bingiz.bilibili.video.internal.engine.NetworkEngine
+import online.bingiz.bilibili.video.internal.helper.debugStatus
import online.bingiz.bilibili.video.internal.helper.infoAsLang
import taboolib.common.platform.ProxyPlayer
+import taboolib.common.platform.function.info
+import taboolib.common.platform.function.warning
/**
* Following handler
@@ -13,12 +16,18 @@ import taboolib.common.platform.ProxyPlayer
*/
class FollowingHandler : ApiHandler() {
override fun handle(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
+ if (debugStatus) {
+ info("关注处理器 > 玩家: ${player.name} | 视频: $bvid | 接受处理")
+ }
if (SettingConfig.needFollow) {
NetworkEngine.bilibiliAPI.hasFollowing(bvid, sessData).execute().let { resultResponse ->
if (resultResponse.isSuccessful) {
resultResponse.body()?.data?.let {
if (it.card.following.not()) {
player.infoAsLang("GetTripleStatusFailureNotFollowing")
+ if (debugStatus) {
+ warning("关注处理器 > 玩家: ${player.name} | 视频: $bvid | 未关注")
+ }
return false
}
}
@@ -27,6 +36,9 @@ class FollowingHandler : ApiHandler() {
}
}
}
+ if (debugStatus) {
+ info("关注处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
+ }
return callNextHandler(player, bvid, sessData)
}
}
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/LikeHandler.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/LikeHandler.kt
index c8caf57..77986f5 100644
--- a/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/LikeHandler.kt
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/handler/LikeHandler.kt
@@ -1,8 +1,11 @@
package online.bingiz.bilibili.video.internal.handler
import online.bingiz.bilibili.video.internal.engine.NetworkEngine
+import online.bingiz.bilibili.video.internal.helper.debugStatus
import online.bingiz.bilibili.video.internal.helper.infoAsLang
import taboolib.common.platform.ProxyPlayer
+import taboolib.common.platform.function.info
+import taboolib.common.platform.function.warning
/**
* Like handler
@@ -12,11 +15,17 @@ import taboolib.common.platform.ProxyPlayer
*/
class LikeHandler : ApiHandler() {
override fun handle(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
+ if (debugStatus) {
+ info("点赞处理器 > 玩家: ${player.name} | 视频: $bvid | 接受处理")
+ }
NetworkEngine.bilibiliAPI.hasLike(bvid, sessData).execute().let {
if (it.isSuccessful) {
it.body()?.data?.let { count ->
if (count < 1) {
player.infoAsLang("GetTripleStatusFailureNotLike")
+ if (debugStatus) {
+ warning("点赞处理器 > 玩家: ${player.name} | 视频: $bvid | 未点赞")
+ }
return false
}
}
@@ -24,6 +33,9 @@ class LikeHandler : ApiHandler() {
player.infoAsLang("NetworkRequestFailureCode", it.code())
}
}
+ if (debugStatus) {
+ info("点赞处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
+ }
return callNextHandler(player, bvid, sessData)
}
}
diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/helper/StatusHelper.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/helper/StatusHelper.kt
new file mode 100644
index 0000000..697100a
--- /dev/null
+++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/helper/StatusHelper.kt
@@ -0,0 +1,4 @@
+package online.bingiz.bilibili.video.internal.helper
+
+
+var debugStatus: Boolean = false
diff --git a/src/main/resources/setting.yml b/src/main/resources/setting.yml
index eb96d17..46c5f5f 100644
--- a/src/main/resources/setting.yml
+++ b/src/main/resources/setting.yml
@@ -7,3 +7,6 @@ cooldown: 60
# 是否需要关注
# * 本项为实验项目,可能存在不稳定的情况
needFollow: false
+
+# 调试模式,用于诊断一些问题
+debug: false