Skip to content

Commit

Permalink
update: 改进Debug信息展示逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
BingZi-233 committed Jan 9, 2024
1 parent a004981 commit c92e691
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 51 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=online.bingiz.bilibili.video
version=1.4.5
version=1.4.6
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package online.bingiz.bilibili.video.internal.handler

import online.bingiz.bilibili.video.internal.helper.debug
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
Expand All @@ -17,7 +17,7 @@ abstract class ApiHandler {
protected fun callNextHandler(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
return nextHandler?.handle(player, bvid, sessData) ?: let {
if (debugStatus) {
info("最终处理器 > 玩家: ${player.name} | 视频: $bvid | 通过")
debug("最终处理器 > 玩家: ${player.name} | 视频: $bvid | 通过")
}
true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
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.debug
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
Expand All @@ -15,27 +13,21 @@ import taboolib.common.platform.function.warning
*/
class CoinsHandler : ApiHandler() {
override fun handle(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
if (debugStatus) {
info("硬币处理器 > 玩家: ${player.name} | 视频: $bvid | 接受处理")
}
debug("硬币处理器 > 玩家: ${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 | 硬币不足")
}
debug("硬币处理器 > 玩家: ${player.name} | 视频: $bvid | 硬币不足")
return false
}
}
} else {
player.infoAsLang("NetworkRequestFailureCode", it.code())
}
}
if (debugStatus) {
info("硬币处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
}
debug("硬币处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
return callNextHandler(player, bvid, sessData)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
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.debug
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
Expand All @@ -15,27 +13,21 @@ import taboolib.common.platform.function.warning
*/
class FavouredHandler : ApiHandler() {
override fun handle(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
if (debugStatus) {
info("收藏处理器 > 玩家: ${player.name} | 视频: $bvid | 接受处理")
}
debug("收藏处理器 > 玩家: ${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 | 未收藏")
}
debug("收藏处理器 > 玩家: ${player.name} | 视频: $bvid | 未收藏")
return false
}
}
} else {
player.infoAsLang("NetworkRequestFailureCode", resultResponse.code())
}
}
if (debugStatus) {
info("收藏处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
}
debug("收藏处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
return callNextHandler(player, bvid, sessData)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ 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.debug
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
Expand All @@ -16,18 +14,14 @@ import taboolib.common.platform.function.warning
*/
class FollowingHandler : ApiHandler() {
override fun handle(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
if (debugStatus) {
info("关注处理器 > 玩家: ${player.name} | 视频: $bvid | 接受处理")
}
debug("关注处理器 > 玩家: ${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 | 未关注")
}
debug("关注处理器 > 玩家: ${player.name} | 视频: $bvid | 未关注")
return false
}
}
Expand All @@ -36,9 +30,7 @@ class FollowingHandler : ApiHandler() {
}
}
}
if (debugStatus) {
info("关注处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
}
debug("关注处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
return callNextHandler(player, bvid, sessData)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
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.debug
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
Expand All @@ -15,27 +13,21 @@ import taboolib.common.platform.function.warning
*/
class LikeHandler : ApiHandler() {
override fun handle(player: ProxyPlayer, bvid: String, sessData: String): Boolean {
if (debugStatus) {
info("点赞处理器 > 玩家: ${player.name} | 视频: $bvid | 接受处理")
}
debug("点赞处理器 > 玩家: ${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 | 未点赞")
}
debug("点赞处理器 > 玩家: ${player.name} | 视频: $bvid | 未点赞")
return false
}
}
} else {
player.infoAsLang("NetworkRequestFailureCode", it.code())
}
}
if (debugStatus) {
info("点赞处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
}
debug("点赞处理器 > 玩家: ${player.name} | 视频: $bvid | 移交处理")
return callNextHandler(player, bvid, sessData)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package online.bingiz.bilibili.video.internal.helper

import taboolib.common.platform.function.info
import taboolib.module.chat.colored

/**
* Debug
* Debug Helper
*
* @param message Message
*/
internal fun debug(message: String) {
info("&7&l[&a&ldebug&7&l] > &f&l$message".colored())
}

0 comments on commit c92e691

Please sign in to comment.