koishi-plugin-ll-mc 2.1.0 → 2.1.1
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.
- package/index.js +8 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -84,7 +84,7 @@ const Config = Schema.object({
|
|
|
84
84
|
|
|
85
85
|
exports.Config = Config
|
|
86
86
|
|
|
87
|
-
exports.inject = { required: ['database'] }
|
|
87
|
+
exports.inject = { required: ['database'], optional: ['puppeteer'] }
|
|
88
88
|
|
|
89
89
|
function apply(ctx, config) {
|
|
90
90
|
const logger = ctx.logger('ll-mc')
|
|
@@ -348,8 +348,9 @@ function apply(ctx, config) {
|
|
|
348
348
|
</body></html>`, { waitUntil: 'networkidle0' })
|
|
349
349
|
await page.waitForSelector('.title')
|
|
350
350
|
const buf = await page.screenshot({ type: 'png' })
|
|
351
|
-
|
|
352
|
-
|
|
351
|
+
// 官机适配器只支持 data:image 内联图片;h.image(Buffer) 会生成 base64:// 协议导致发送失败
|
|
352
|
+
const src = `data:image/png;base64,${buf.toString('base64')}`
|
|
353
|
+
return { src, close: () => page.close().catch(() => {}) }
|
|
353
354
|
}
|
|
354
355
|
catch (e) {
|
|
355
356
|
logger.warn('[ll-mc] 排行图片渲染失败,降级文字:', e?.message)
|
|
@@ -383,8 +384,8 @@ function apply(ctx, config) {
|
|
|
383
384
|
const isMine = x.key === `${session.guildId}:${session.userId}`
|
|
384
385
|
return { name: x.nick || x.key.split(':')[1], count: x.count, percent: Math.max(top[0].count ? Math.round(x.count / top[0].count * 100) : 0, 2), mark: isMine }
|
|
385
386
|
})
|
|
386
|
-
const
|
|
387
|
-
if (
|
|
387
|
+
const img = await renderRankImage(title, subtitle, rows)
|
|
388
|
+
if (img) { img.close(); return h.image(img.src) }
|
|
388
389
|
const lines = [`📊 ${title}`]
|
|
389
390
|
top.forEach((x, i) => {
|
|
390
391
|
const mark = x.key === `${session.guildId}:${session.userId}` ? ' ★' : ''
|
|
@@ -411,8 +412,8 @@ function apply(ctx, config) {
|
|
|
411
412
|
}
|
|
412
413
|
const title = `群${range.label}发言排行 TOP ${Math.min(n, top.length)}`
|
|
413
414
|
const subtitle = '跨群排行 · 群名来自 getGuild(需"获取群信息"权限)或 groupNameMap'
|
|
414
|
-
const
|
|
415
|
-
if (
|
|
415
|
+
const img = await renderRankImage(title, subtitle, rows)
|
|
416
|
+
if (img) { img.close(); return h.image(img.src) }
|
|
416
417
|
const lines = [`🏆 ${title}`]
|
|
417
418
|
for (let i = 0; i < top.length; i++) {
|
|
418
419
|
const x = top[i]
|