dsh-live2dwaifu 0.7.0 → 0.7.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.
Files changed (2) hide show
  1. package/lib/index.js +43 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -59,12 +59,12 @@ function pickOwnMeme(mood) {
59
59
  }
60
60
 
61
61
  /** 按模式挑一张配图,返回可直接用的 URL */
62
- function pickImage(mode, mood) {
62
+ function pickImage(mode, mood, label) {
63
63
  const m = MEMES_MODES.includes(mode) ? mode : 'off';
64
64
  if (m === 'off') return null;
65
65
  const pool = [];
66
66
  if (m === 'own' || m === 'both') {
67
- const f = pickOwnMeme(mood);
67
+ const f = (label && pickOwnMemeByLabel(label)) || pickOwnMeme(mood);
68
68
  if (f) pool.push('/dsh-live2d/ownmeme/' + encodeURIComponent(f));
69
69
  }
70
70
  if (m === 'external' || m === 'both') {
@@ -118,7 +118,30 @@ function splitChoices(raw) {
118
118
  return { text: raw.slice(0, m.index).trim(), choices };
119
119
  }
120
120
 
121
- /** 粗判情绪,配图用 */
121
+ /** 先摘「||图:名字」,再摘「||选项1|选项2」 */
122
+ function splitMeta(raw) {
123
+ let text = String(raw || '');
124
+ let imageLabel = '';
125
+ const imgMatch = /\|\|\s*图\s*[::]\s*([^\n|]+)\s*$/m.exec(text);
126
+ if (imgMatch) {
127
+ imageLabel = imgMatch[1].trim().replace(/^["“「『']+|["”」』']+$/g, '');
128
+ text = (text.slice(0, imgMatch.index) + text.slice(imgMatch.index + imgMatch[0].length)).trim();
129
+ }
130
+ const parsed = splitChoices(text);
131
+ return { text: parsed.text, choices: parsed.choices, imageLabel };
132
+ }
133
+
134
+ /** 按名字取自带那张 */
135
+ function pickOwnMemeByLabel(label) {
136
+ const items = readOwnMemes();
137
+ if (!items.length || !label) return null;
138
+ const key = String(label).trim();
139
+ const hit =
140
+ items.find((it) => it.label === key) ||
141
+ items.find((it) => String(it.file).replace(/\.\w+$/, '') === key) ||
142
+ items.find((it) => key && String(it.label).includes(key));
143
+ return hit ? hit.file : null;
144
+ }
122
145
  function guessMood(text) {
123
146
  const s = String(text || '');
124
147
  if (/[气烦讨厌]/.test(s)) return '生气';
@@ -472,6 +495,14 @@ async function handle(req, res, ctx) {
472
495
  '他说:' + text,
473
496
  '回他一句。只输出这句话本身:一到三句,短,口语,像发消息。不要解释,不要加引号,不要旁白,不要括号里的动作。',
474
497
  st.choices ? '如果你想让他挑,可以在最后另起一行写 ||选项一|选项二,最多三项。' : '',
498
+ st.memesMode === 'own' || st.memesMode === 'both'
499
+ ? '如果你想附一张贴图,就在最后另起一行写 ||图:名字。能挑的名字有:' +
500
+ readOwnMemes()
501
+ .map((it) => it.label)
502
+ .filter(Boolean)
503
+ .join('、') +
504
+ '。不想配就别写。'
505
+ : '',
475
506
  ]
476
507
  .filter(Boolean)
477
508
  .join('\n\n');
@@ -483,7 +514,7 @@ async function handle(req, res, ctx) {
483
514
  return sendJson(res, 502, { error: '生成失败:' + (e instanceof Error ? e.message : String(e)) });
484
515
  }
485
516
  LAST_ACTIVE.at = Date.now();
486
- const parsed = splitChoices(reply || '');
517
+ const parsed = splitMeta(reply || '');
487
518
  let line = parsed.text;
488
519
  let choices = st.choices ? parsed.choices : [];
489
520
  if (line.length > 240) line = line.slice(0, 240);
@@ -492,7 +523,14 @@ async function handle(req, res, ctx) {
492
523
  }
493
524
  if (!line && !choices.length) return sendJson(res, 200, { ok: true, reply: '', id });
494
525
  const moodNow = guessMood(line);
495
- const image = st.memesMode !== 'off' && Math.random() < 0.35 ? pickImage(st.memesMode, moodNow) : null;
526
+ const image =
527
+ st.memesMode === 'off'
528
+ ? null
529
+ : parsed.imageLabel
530
+ ? pickImage(st.memesMode, moodNow, parsed.imageLabel)
531
+ : Math.random() < 0.35
532
+ ? pickImage(st.memesMode, moodNow)
533
+ : null;
496
534
 
497
535
  writeChat(id, hist.concat([
498
536
  { role: 'user', text, at: Date.now() },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-live2dwaifu",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "给 DSH 网页右下角请一个 Live2D 角色:会眨眼、会呼吸、视线跟着鼠标、点她有反应、说话时嘴动、心情变了眉毛跟着动。模型不用内置——谁装谁放自己的文件夹;支持自定义 .exp3.json 表情和 .motion3.json 动作,卡片能拖能缩,背景可换。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",