koishi-plugin-bns-rate 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +12 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -28,7 +28,7 @@ const Config = Schema.object({
28
28
  .description('💬 用 QQ官方 Markdown 卡片回复(仅官方QQ机器人「群/私聊」生效;频道机器人、OneBot 等其它平台自动回退纯文本,发送失败也会回退)'),
29
29
  title: Schema.string()
30
30
  .default('神石比例实时播报')
31
- .description('卡片顶部标题(# 一级标题)'),
31
+ .description('卡片顶部标题(# 一级标题)。留空则不输出标题——若横幅图上已经有标题文字,把这里清空即可'),
32
32
 
33
33
  bannerUrl: Schema.string()
34
34
  .default('')
@@ -176,15 +176,20 @@ function formatText(rates, timestamp, opts = {}) {
176
176
  }
177
177
 
178
178
  // QQ官方 Markdown 卡片源码
179
+ // 按"块"拼装、块之间用空行分隔:任何一块留空/关闭就整块不输出,
180
+ // 这样不会出现空标题(`# `)、也不会在开头/结尾留下多余空行
179
181
  function buildCardMarkdown(rates, timestamp, config) {
180
182
  const time = formatTime(timestamp, false)
181
- const lines = [`# ${config.title}`]
183
+ const blocks = []
184
+
185
+ const title = String(config.title || '').trim()
186
+ if (title) blocks.push(`# ${title}`)
182
187
 
183
188
  const banner = String(config.bannerUrl || '').trim()
184
189
  if (banner) {
185
190
  const w = Math.max(0, Math.round(Number(config.bannerWidth) || 0))
186
191
  const ht = Math.max(0, Math.round(Number(config.bannerHeight) || 0))
187
- lines.push('', `![${config.bannerAlt} #${w}px #${ht}px](${banner})`)
192
+ blocks.push(`![${String(config.bannerAlt || '').trim()} #${w}px #${ht}px](${banner})`)
188
193
  }
189
194
 
190
195
  const intro = fillTemplate(config.intro, {
@@ -192,14 +197,14 @@ function buildCardMarkdown(rates, timestamp, config) {
192
197
  time,
193
198
  date: time.split(' ')[0],
194
199
  }).trim()
195
- if (intro) lines.push('', intro)
200
+ if (intro) blocks.push(intro)
196
201
 
197
- lines.push('', ...buildRateBlock(rates, config))
202
+ blocks.push(buildRateBlock(rates, config).join('\n'))
198
203
 
199
204
  const footer = String(config.footer || '').trim()
200
- if (config.button && footer) lines.push('', footer)
205
+ if (config.button && footer) blocks.push(footer)
201
206
 
202
- return lines.join('\n')
207
+ return blocks.join('\n\n').trim()
203
208
  }
204
209
 
205
210
  // 报价区排版。box 省略时取 config.ratesBox
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-bns-rate",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Fetch BNS Classic Divine Stone exchange rate from dd373.com, with QQ official Markdown card support",
5
5
  "main": "index.js",
6
6
  "files": [