Skip to content

Commit

Permalink
动态、直播文字模板分离 #26
Browse files Browse the repository at this point in the history
  • Loading branch information
Colter23 committed Jan 8, 2022
1 parent 2c4e88d commit fd710ad
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ font: Microsoft Yahei
# 直播@全体(目前只能全体控制,如果需要对单独的群设置请去开issue)
liveAtAll: false

# 图片推送模式文字模板
# 图片模式下动态/视频推送文字模板
# 配置项:
# {name} : 名字
# {uid} : UID
Expand All @@ -83,6 +83,9 @@ liveAtAll: false
# 2.0.4版本之前的模板为 {name}@{uid}@{type}\n{time}\n{link}
pushTemplate: "{name}@{type}\n{link}"

# 图片模式下直播推送文字模板, 如果为空则与上方动态推送模板保持一致
livePushTemplate: ""

# cookie !!必填!!
# cookie请包在双引号内
# 如何获取见下文 获取Cookie
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "top.colter"
version = "2.0.8"
version = "2.0.9"

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ object DynamicTasker : CoroutineScope by PluginMain.childScope("DynamicTasker")
list.sendMessage { di.build(it, color) }
//lastDynamic = di.timestamp
}
delay(1000L)
//delay(1000L)
}
}
}.onSuccess {
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/top/colter/mirai/plugin/bilibili/Live.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ suspend fun LiveInfo.buildTextLive(contact: Contact): Message {
suspend fun LiveInfo.buildImageLive(contact: Contact): Message {
val link = "https://live.bilibili.com/${roomId}"
val file = buildLiveImageMessage(title, cover, uname, face, "#d3edfa", "live/${uid}/${liveTime}.png")
val msg = BiliPluginConfig.pushTemplate.replace("{name}", uname).replace("{uid}",uid.toString())
val template = BiliPluginConfig.livePushTemplate.ifEmpty {
BiliPluginConfig.pushTemplate
}
val msg = template.replace("{name}", uname).replace("{uid}",uid.toString())
.replace("{type}","直播").replace("{time}",time).replace("{link}",link)
return (file.uploadAsImage(contact) + msg)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object PluginMain : KotlinPlugin(
JvmPluginDescription(
id = "top.colter.bilibili-dynamic-mirai-plugin",
name = "BilibiliDynamic",
version = "2.0.8"
version = "2.0.9"
) {
author("Colter")
info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ object BiliPluginConfig : ReadOnlyPluginConfig("BiliPluginConfig") {
@ValueDescription("直播@全体")
val liveAtAll: Boolean by value(false)

@ValueDescription("推送文字模板, 参数请看readme")
@ValueDescription("动态/视频推送文字模板, 参数请看readme")
val pushTemplate: String by value("{name}@{type}\n{link}")

@ValueDescription("直播推送文字模板, 如不配置则与上面的动态推送模板一致")
val livePushTemplate: String by value("")

//@Suppress(stringSerialization = DOUBLE_QUOTATION)
@ValueDescription("cookie, 请使用双引号")
val cookie: String by value("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,16 @@ object ImgUtils : CoroutineScope by PluginMain.childScope("ImageTasker"){
val emojis = e.emoji.htmlHexadecimal.split(";").filter{it.isNotEmpty()}.toList()
val emoji = emojis.joinToString("-")
if (!emojiMap.containsKey(emoji)) {
val emojiImg = try {
ImageIO.read(URL("https://twemoji.maxcdn.com/36x36/$emoji.png"))
}catch (ex: Exception){
return@parseFromUnicode e.emoji.unicode
}
val emojiBi = BufferedImage(30, 30, BufferedImage.TYPE_INT_ARGB)
val emojiG2 = emojiBi.createGraphics()
emojiG2.setRenderingHints(renderingHints)
emojiG2.drawImage(emojiImg,0,0,30,30,null)

try {
emojiG2.drawImage(ImageIO.read(URL("https://twemoji.maxcdn.com/36x36/$emoji.png")),0,0,30,30,null)
}catch (ex: Exception){
return@parseFromUnicode e.emoji.unicode
}
emojiMap["[$emoji]"] = emojiBi
emojiG2.dispose()
}
Expand Down

0 comments on commit fd710ad

Please sign in to comment.