Skip to content

Commit 8792d88

Browse files
committed
uupdate
1 parent f47c915 commit 8792d88

File tree

15 files changed

+148
-65
lines changed

15 files changed

+148
-65
lines changed

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ v3数据文件名 `BiliData.yml`
182182
| `pushInterval` | 单位毫秒 | QQ中连续发送消息的间隔 |
183183

184184
#### ImageConfig
185-
| 配置项 | 取值 | 说明 |
186-
|------------------|-----------------------------------------------------------|--------------------------------------------|
187-
| `quality` | `800w` / `1000w` / `1200w` / `1500w` (图片宽度) | 图片质量(分辨率) |
188-
| `theme` | `v3` (新版绘图主题) / `v3RainbowOutline` (彩虹边框) / `v2` (旧版绘图主题) | 绘图主题 (目前两套其实都差不多,鸡肋功能) |
189-
| `font` | 字体名 / 字体文件名(不用加后缀) | 绘图字体 目前仅支持单字体 字体放到插件数据路径下 `font` 文件夹中 |
190-
| `defaultColor` | HEX颜色值 (#d3edfa;#fde8ed) | 默认绘图主题色 支持多个值自定义渐变 中间用分号`;`号分隔 单个值会自动生成渐变色 |
191-
| `cardOrnament` | `FanCard` (粉丝卡片) / `QrCode` (动态链接二维码) / `None` (无) | 卡片装饰 |
192-
| `colorGenerator` | [ColorGenerator](#ColorGenerator) | 渐变色生成器配置 (用于图片背景) 仅当主题色为单个值时会自动生成 |
193-
| `badgeEnable` | `true` / `false` | 卡片顶部的标签 |
185+
| 配置项 | 取值 | 说明 |
186+
|------------------|-----------------------------------------------------------|----------------------------------------------------|
187+
| `quality` | `800w` / `1000w` / `1200w` / `1500w` (图片宽度) | 图片质量(分辨率) |
188+
| `theme` | `v3` (新版绘图主题) / `v3RainbowOutline` (彩虹边框) / `v2` (旧版绘图主题) | 绘图主题 (目前两套其实都差不多,鸡肋功能) |
189+
| `font` | 字体名 / 字体文件名(不用加后缀) | 绘图字体 目前仅支持单字体 字体放到插件数据路径下 `font` 文件夹中 -> [字体](#字体) |
190+
| `defaultColor` | HEX颜色值 (#d3edfa;#fde8ed) | 默认绘图主题色 支持多个值自定义渐变 中间用分号`;`号分隔 单个值会自动生成渐变色 |
191+
| `cardOrnament` | `FanCard` (粉丝卡片) / `QrCode` (动态链接二维码) / `None` (无) | 卡片装饰 |
192+
| `colorGenerator` | [ColorGenerator](#ColorGenerator) | 渐变色生成器配置 (用于图片背景) 仅当主题色为单个值时会自动生成 |
193+
| `badgeEnable` | `true` / `false` | 卡片顶部的标签 |
194194

195195
##### ColorGenerator
196196
| 配置项 | 取值 | 说明 |
@@ -810,6 +810,13 @@ v2:
810810
通过对群设置权限来控制是否开启直播@全体
811811
`/perm add g123456789 top.colter.bilibili-dynamic-mirai-plugin:live.atall`
812812

813+
### 字体
814+
815+
[HarmonyOS Sans](https://developer.harmonyos.com/cn/docs/design/des-resources/general-0000001157315901)
816+
817+
选择下载 52.2MB 的字体压缩包文件, 请使用压缩包内 `HarmonyOS_Sans_SC` 目录下的字体, 此目录下的字体为简体中文
818+
里面不同文件代表不同的粗细, 建议使用 `Medium`
819+
813820
### 手动获取 Cookie
814821
<details>
815822
<summary>点击展开</summary>

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "top.colter"
10-
version = "3.0.0-M3"
10+
version = "3.0.0-M4"
1111

1212
repositories {
1313
mavenLocal()

font/HarmonyOS_Sans_SC_Medium.ttf

-7.85 MB
Binary file not shown.

font/思源黑体.ttf

-8.13 MB
Binary file not shown.

src/main/kotlin/top/colter/mirai/plugin/bilibili/BiliBiliDynamic.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object BiliBiliDynamic : KotlinPlugin(
2121
JvmPluginDescription(
2222
id = "top.colter.bilibili-dynamic-mirai-plugin",
2323
name = "BiliBili Dynamic",
24-
version = "3.0.0-M3",
24+
version = "3.0.0-M4",
2525
) {
2626
author("Colter")
2727
}

src/main/kotlin/top/colter/mirai/plugin/bilibili/command/DynamicCommand.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import top.colter.mirai.plugin.bilibili.BiliBiliDynamic
99
import top.colter.mirai.plugin.bilibili.FilterMode
1010
import top.colter.mirai.plugin.bilibili.FilterType
1111
import top.colter.mirai.plugin.bilibili.api.getDynamicDetail
12+
import top.colter.mirai.plugin.bilibili.api.getLive
1213
import top.colter.mirai.plugin.bilibili.data.DynamicDetail
14+
import top.colter.mirai.plugin.bilibili.data.LiveDetail
1315
import top.colter.mirai.plugin.bilibili.tasker.BiliDataTasker
1416
import top.colter.mirai.plugin.bilibili.utils.biliClient
1517
import top.colter.mirai.plugin.bilibili.utils.delegate
@@ -115,6 +117,14 @@ object DynamicCommand : CompositeCommand(
115117
detail?.let { d -> BiliBiliDynamic.dynamicChannel.send(DynamicDetail(d, subject.delegate)) }
116118
}
117119

120+
@SubCommand("live", "直播")
121+
suspend fun CommandSenderOnMessage<*>.live() {
122+
val subject = Contact()
123+
val detail = biliClient.getLive(1, 1)
124+
if (detail != null) subject.sendMessage("请稍等") else subject.sendMessage("当前没有人在直播")
125+
detail?.let { d -> BiliBiliDynamic.liveChannel.send(LiveDetail(d.rooms.first(), subject.delegate)) }
126+
}
127+
118128
}
119129

120130
fun CommandSender.Contact(): Contact = subject ?: throw CommandArgumentParserException("无法从当前环境获取联系人")

src/main/kotlin/top/colter/mirai/plugin/bilibili/data/Dynamic.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,17 @@ data class ModuleFold(
12301230
@SerialName("statement")
12311231
val statement: String,
12321232
@SerialName("users")
1233-
val users: List<String>,
1233+
val users: List<BaseUser>,
1234+
)
1235+
1236+
@Serializable
1237+
data class BaseUser(
1238+
@SerialName("mid")
1239+
val mid: Long,
1240+
@SerialName("name")
1241+
val name: String,
1242+
@SerialName("face")
1243+
val face: String,
12341244
)
12351245

12361246
/**

src/main/kotlin/top/colter/mirai/plugin/bilibili/draw/DynamicDraw.kt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,34 @@ val cardContentRect: Rect by lazy {
6161
val mainTypeface: Typeface by lazy {
6262
val mainFont = imageConfig.font.split(";").first().split(".").first()
6363
try {
64-
matchFamily(mainFont).matchStyle(FontStyle.NORMAL)!!
64+
if (mainFont.isBlank()){
65+
logger.warning("配置文件未配置字体, 尝试加载 font 目录下的字体")
66+
val f = FontUtils.defaultFont
67+
if (f == null){
68+
throw Exception()
69+
}else {
70+
logger.info("成功加载 ${f.familyName} 字体")
71+
return@lazy f
72+
}
73+
}else {
74+
matchFamily(mainFont).matchStyle(FontStyle.NORMAL)!!
75+
}
6576
} catch (e: Exception) {
66-
logger.error("加载主字体 $mainFont 失败")
67-
matchFamily("Source Han Sans").matchStyle(FontStyle.NORMAL)!!
77+
logger.warning("加载主字体 $mainFont 失败, 尝试加载默认字体")
78+
loadSysDefaultFont()
79+
}
80+
}
81+
82+
fun loadSysDefaultFont(): Typeface {
83+
val defaultList = listOf("HarmonyOS Sans SC", "Source Han Sans", "SimHei", "sans-serif")
84+
defaultList.forEach {
85+
try {
86+
val f = matchFamily(it).matchStyle(FontStyle.NORMAL)!!
87+
logger.info("加载默认字体 $it 成功")
88+
return f
89+
} catch (_: Exception) { }
6890
}
91+
throw Exception("无法加载默认字体, 请自行配置字体或准备字体文件")
6992
}
7093

7194
val font: Font by lazy {

src/main/kotlin/top/colter/mirai/plugin/bilibili/draw/DynamicMajorDraw.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,8 @@ suspend fun ModuleDynamic.Major.Article.drawGeneral(): Image {
566566
clipRRect(coverRRect, true)
567567
covers.forEach {
568568
val img = getOrDownloadImage(it, CacheType.IMAGES)
569-
val src = Rect.makeXYWH(0f, 0f, img.width.toFloat(), img.height.toFloat())
570-
val tar = Rect.makeXYWH(imgX, articleCardRect.top, imgW, articleCoverHeight)
571-
drawImageRect(img, src, tar, Paint())
569+
val tar = RRect.makeXYWH(imgX, articleCardRect.top, imgW, articleCoverHeight, 0f)
570+
drawImageClip(img, tar, Paint())
572571
imgX += articleCardRect.width / 3 + 2
573572
}
574573
restore()

src/main/kotlin/top/colter/mirai/plugin/bilibili/draw/DynamicModuleDraw.kt

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import top.colter.mirai.plugin.bilibili.utils.FontUtils
1313
import top.colter.mirai.plugin.bilibili.utils.formatTime
1414
import top.colter.mirai.plugin.bilibili.utils.getOrDownloadImage
1515
import top.colter.mirai.plugin.bilibili.utils.translate.trans
16+
import kotlin.math.abs
1617
import kotlin.math.ceil
1718

1819

@@ -455,14 +456,14 @@ suspend fun ModuleAuthor.drawGeneral(time: String, link: String, themeColor: Int
455456
y += quality.subTitleFontSize + space * 0.5f
456457
drawTextLine(textLineTime, x, y, Paint().apply { color = theme.subTitleColor })
457458

458-
drawOrnament(BiliConfig.imageConfig.cardOrnament, decorate, link, themeColor, null)
459+
drawOrnament(decorate, link, themeColor)
459460
}
460461
}.makeImageSnapshot()
461462
}
462463

463-
suspend fun Canvas.drawOrnament(cardOrnament: String, decorate: ModuleAuthor.Decorate?, link: String?, qrCodeColor: Int?, label: String?) {
464+
suspend fun Canvas.drawOrnament(decorate: ModuleAuthor.Decorate?, link: String?, qrCodeColor: Int?) {
464465

465-
when (cardOrnament) {
466+
when (BiliConfig.imageConfig.cardOrnament) {
466467
"FanCard" -> {
467468
if (decorate != null) {
468469
val fanImg = getOrDownloadImage(decorate.cardUrl, CacheType.USER)
@@ -475,10 +476,10 @@ suspend fun Canvas.drawOrnament(cardOrnament: String, decorate: ModuleAuthor.Dec
475476

476477
val cardWidth = fanImg.width * cardHeight / fanImg.height
477478

478-
val y = ((quality.faceSize - cardHeight) / 2) + quality.cardPadding
479+
val y = ((quality.faceSize - cardHeight + quality.contentSpace) / 2)
479480
val tarFRect = Rect.makeXYWH(
480-
cardContentRect.right - cardWidth - 20f,
481-
y,
481+
cardContentRect.right - cardWidth - abs(y),
482+
y + quality.cardPadding,
482483
cardWidth,
483484
cardHeight
484485
)
@@ -506,12 +507,12 @@ suspend fun Canvas.drawOrnament(cardOrnament: String, decorate: ModuleAuthor.Dec
506507

507508
"QrCode" -> {
508509
val qrCodeImg = qrCode(link!!, quality.ornamentHeight.toInt(), qrCodeColor!!)
509-
val y = ((quality.faceSize - quality.ornamentHeight) / 2) + quality.cardPadding
510+
val y = ((quality.faceSize - qrCodeImg.height + quality.contentSpace) / 2)
510511
val tarFRect = Rect.makeXYWH(
511-
cardContentRect.right - quality.ornamentHeight - 20f,
512-
y,
513-
quality.ornamentHeight,
514-
quality.ornamentHeight
512+
cardContentRect.right - qrCodeImg.width - abs(y),
513+
y + quality.cardPadding,
514+
qrCodeImg.width.toFloat(),
515+
qrCodeImg.height.toFloat()
515516
)
516517
val srcFRect = Rect(0f, 0f, qrCodeImg.width.toFloat(), qrCodeImg.height.toFloat())
517518
drawImageRect(
@@ -523,21 +524,5 @@ suspend fun Canvas.drawOrnament(cardOrnament: String, decorate: ModuleAuthor.Dec
523524
true
524525
)
525526
}
526-
527-
"Label" -> {
528-
val labelTextLine = TextLine.make(label, font.makeWithSize(quality.subTitleFontSize))
529-
val y = ((quality.faceSize - quality.ornamentHeight) / 2) + quality.cardPadding
530-
drawLabelCard(
531-
labelTextLine,
532-
cardContentRect.right - labelTextLine.width - quality.badgePadding * 4,
533-
y,
534-
Paint().apply {
535-
color = theme.subLeftBadge.fontColor
536-
},
537-
Paint().apply {
538-
color = theme.subLeftBadge.bgColor
539-
}
540-
)
541-
}
542527
}
543528
}

0 commit comments

Comments
 (0)