koishi-plugin-emojiluna-plus 0.0.2 → 0.0.3

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyChatlunaIntegration = applyChatlunaIntegration;
4
+ const render_1 = require("./render");
4
5
  function applyChatlunaIntegration(ctx, config) {
5
6
  if (!config.injectVariables)
6
7
  return;
@@ -9,8 +10,7 @@ function applyChatlunaIntegration(ctx, config) {
9
10
  return;
10
11
  }
11
12
  ctx.inject(['server', 'chatluna', 'emojiluna'], async (ctx) => {
12
- const selfUrl = config.selfUrl || ctx.server.selfUrl || '';
13
- const baseUrl = selfUrl + config.backendPath;
13
+ const baseUrl = (0, render_1.resolveSelfUrl)(ctx, config) + config.backendPath;
14
14
  await ctx.emojiluna.ready;
15
15
  const escapeMarkdown = (text) => text.replace(/([\[\]\(\)])/g, '\\$1');
16
16
  const refreshPromptVariable = async () => {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.applyConsoleListeners = applyConsoleListeners;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
+ const render_1 = require("./render");
9
10
  const DIRECT_EVENTS = {
10
11
  'emojiluna/getEmojiList': 'getEmojiList',
11
12
  'emojiluna/getEmojiPage': 'getEmojiPage',
@@ -64,8 +65,8 @@ async function registerListeners(ctx, config) {
64
65
  ctx.console.addListener(event, invoke[method]);
65
66
  }
66
67
  ctx.console.addListener('emojiluna/getBaseUrl', async () => {
67
- const selfUrl = config.selfUrl || ctx.server?.selfUrl || '';
68
- return selfUrl ? `${selfUrl.replace(/\/+$/, '')}${config.backendPath}` : '';
68
+ const selfUrl = (0, render_1.resolveSelfUrl)(ctx, config);
69
+ return selfUrl ? `${selfUrl}${config.backendPath}` : '';
69
70
  });
70
71
  ctx.console.addListener('emojiluna/getUploadToken', async () => {
71
72
  return emojiluna.uploadToken;
@@ -1,6 +1,11 @@
1
1
  import { Context, h } from 'koishi';
2
2
  import { Config } from '../config';
3
3
  import { EmojiItem } from '../types';
4
+ /**
5
+ * `ctx.get` is the optional lookup: reading `ctx.server` from a scope that did not
6
+ * declare the `server` inject makes Koishi log a service warning on every access.
7
+ */
8
+ export declare function resolveSelfUrl(ctx: Context, config: Config): string;
4
9
  export declare function truncate(text: string, max?: number): string;
5
10
  export declare function emojiUrl(ctx: Context, config: Config, emoji: EmojiItem): string | null;
6
11
  export declare function emojiText(emoji: EmojiItem): string;
@@ -1,11 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveSelfUrl = resolveSelfUrl;
3
4
  exports.truncate = truncate;
4
5
  exports.emojiUrl = emojiUrl;
5
6
  exports.emojiText = emojiText;
6
7
  exports.emojiMessage = emojiMessage;
7
8
  const koishi_1 = require("koishi");
8
9
  const DEFAULT_TRUNCATE = 200;
10
+ /**
11
+ * `ctx.get` is the optional lookup: reading `ctx.server` from a scope that did not
12
+ * declare the `server` inject makes Koishi log a service warning on every access.
13
+ */
14
+ function resolveSelfUrl(ctx, config) {
15
+ const server = ctx.get('server');
16
+ return (config.selfUrl || server?.selfUrl || '').replace(/\/+$/, '');
17
+ }
9
18
  function truncate(text, max = DEFAULT_TRUNCATE) {
10
19
  if (!text)
11
20
  return '';
@@ -14,10 +23,10 @@ function truncate(text, max = DEFAULT_TRUNCATE) {
14
23
  function emojiUrl(ctx, config, emoji) {
15
24
  if (!config.backendServer)
16
25
  return null;
17
- const selfUrl = config.selfUrl || ctx.server?.selfUrl || '';
26
+ const selfUrl = resolveSelfUrl(ctx, config);
18
27
  if (!selfUrl)
19
28
  return null;
20
- return `${selfUrl.replace(/\/+$/, '')}${config.backendPath}/get/${encodeURIComponent(emoji.id)}`;
29
+ return `${selfUrl}${config.backendPath}/get/${encodeURIComponent(emoji.id)}`;
21
30
  }
22
31
  function emojiText(emoji) {
23
32
  const tags = emoji.tags.length ? ` #${emoji.tags.join(' #')}` : '';
package/lib/utils.js CHANGED
@@ -119,10 +119,14 @@ function describeImageRef(ref) {
119
119
  return ref.slice(0, 64);
120
120
  }
121
121
  async function fetchHttpBuffer(ctx, url, timeout) {
122
- const data = await ctx.http.get(url, {
122
+ const http = ctx.get('http');
123
+ if (!http?.get) {
124
+ throw new Error('未加载 http 服务,无法拉取远程图片');
125
+ }
126
+ const data = await http.get(url, {
123
127
  responseType: 'arraybuffer',
124
128
  timeout,
125
- headers: { 'User-Agent': USER_AGENT }
129
+ headers: { 'User-Agent': USER_AGENT },
126
130
  });
127
131
  return Buffer.from(data);
128
132
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-emojiluna-plus",
3
3
  "description": "Koishi 智能表情包管理插件(emojiluna fork),支持群聊/私聊自动获取表情包、AI自动分类打标、WebUI管理与HTTP API",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -3,15 +3,15 @@
3
3
  ## 📌 重要公告
4
4
  请务必阅读:
5
5
  - 本仓库是 [ChatLunaLab/emojiluna](https://github.com/ChatLunaLab/emojiluna) 的 fork,fork 基线为 `1.3.3`(commit `0a1f33d`),包名改为 `koishi-plugin-emojiluna-plus`,版本号从 `0.0.1` 重新计。
6
- - `koishi-plugin-emojiluna` 与 `koishi-plugin-emojiluna-plus` **只能启用其中一个**:两者提供同名 Koishi 服务 `emojiluna` 与控制台事件 `emojiluna/*`,同时启用会互相覆盖。包名本身不冲突,可以同时安装。
6
+ - `koishi-plugin-emojiluna` 与 `koishi-plugin-emojiluna-plus` **只能启用其中一个**:两者提供同名 Koishi 服务 `emojiluna` 与控制台事件 `emojiluna/*`,同时启用会互相覆盖。包名本身不冲突。
7
7
 
8
8
  ## 项目介绍 (Project Introduction)
9
9
 
10
10
  ### 中文
11
- 这是一个为 Koishi 机器人框架开发的**智能表情包管理插件**:自动从群聊与私聊中收集表情包,交给 ChatLuna 的视觉模型完成分类、命名与打标,并提供分类与标签管理、按名称和标签检索、文件夹批量导入、WebUI 管理界面与 HTTP 接口。相对上游,本 fork 重写了自动获取链路。
11
+ 这是一个为 Koishi 机器人框架开发的**智能表情包管理插件**:自动从群聊与私聊收集表情包,交给 ChatLuna 视觉模型完成分类、命名与打标,并提供分类标签管理、检索、文件夹批量导入、WebUI 管理界面与 HTTP 接口。相对上游,本 fork 重写了自动获取链路。
12
12
 
13
13
  ### English
14
- This is an **intelligent meme management plugin** developed for the Koishi bot framework. It automatically collects memes from group chats and private messages, utilizes ChatLuna's vision models to classify, name, and tag them, and offers features such as category and tag management, retrieval by name and tag, batch folder importing, a WebUI management interface, and an HTTP API. Compared to the upstream version, this fork features a rewritten automatic acquisition pipeline.
14
+ This is an **intelligent meme management plugin** developed for the Koishi bot framework. It automatically collects memes from group chats and private messages, utilizes the ChatLuna vision model for classification, naming, and tagging, and offers features such as tag management, search capabilities, batch folder imports, a WebUI management interface, and an HTTP API. Compared to the upstream version, this fork features a rewritten automatic acquisition pipeline.
15
15
 
16
16
  ## 项目仓库 (Repository)
17
17
  - GitHub: `https://github.com/Minecraft-1314/koishi-plugin-emojiluna-plus.git`
@@ -43,7 +43,7 @@ This is an **intelligent meme management plugin** developed for the Koishi bot f
43
43
 
44
44
  1. **生效范围**:群聊看 `collectGroup` 与 `groupScope`,私聊看 `collectDirect`。
45
45
  2. **取图**:依次尝试元素的 `url`、`src`、`file`、`path` 属性。
46
- 3. **格式**:按文件魔数校验,非图片直接拒绝,避免把错误页存成表情包。
46
+ 3. **格式**:按文件魔数校验,非图片直接拒绝。
47
47
  4. **大小与分辨率**:`minEmojiSize`、`maxEmojiSize`、`minEdgePixels`。
48
48
  5. **内容去重**:sha256 命中内存缓存或数据库即拦截。
49
49
  6. **频次**:`autoCollectMode` 为“频次达标后收集”时要求窗口内达到 `emojiFrequencyThreshold` 次。
@@ -52,6 +52,8 @@ This is an **intelligent meme management plugin** developed for the Koishi bot f
52
52
  9. **库存与限流**:`maxEmojiCount`、按会话的 `groupAutoCollectLimit`、全局 `globalDayLimit`。
53
53
  10. **入库**:写入存储目录,打上 `自动获取` 与 `群:<群号>` 或 `私聊` 标签,并按 `autoAnalyze` 排队 AI 命名打标。
54
54
 
55
+ 支持的图片来源:`http(s)://`、本地绝对路径(`C:\…\x.jpg`、`/data/x.png`)、`file://`、`data:` URI、`base64://` 内联;元素缺少这四个属性时按取图失败拦截。
56
+
55
57
  ## 配置项说明 (Configuration)
56
58
 
57
59
  ### 基础设置 (Basic Settings)
@@ -119,17 +121,17 @@ This is an **intelligent meme management plugin** developed for the Koishi bot f
119
121
  | `globalDayLimit` | number | 1000 | 全局每天自动获取上限,0 表示不限制 |
120
122
  | `groupAutoCollectLimit` | dict | `{}` | 按群覆盖每小时与每日上限,默认 20 与 100 |
121
123
  | `autoCollectCategory` | string | 其他 | 自动获取入库时的初始分类 |
122
- | `autoCollectNameTemplate` | string | `自动获取_{date}_{index}` | 自动获取入库名称模板 |
124
+ | `autoCollectNameTemplate` | string | `自动获取_{date}_{index}` | 自动获取入库名称模板,变量见下 |
123
125
  | `enableImageTypeFilter` | boolean | true | 启用 AI 图片类型过滤 |
124
126
  | `acceptedImageTypes` | string[] | 表情包、贴纸、梗图、漫画、动漫图片、宠物图片、艺术作品 | 允许自动获取入库的图片类型 |
125
127
  | `aiFilterTimeout` | number | 20000 | AI 图片类型过滤超时,单位毫秒 |
126
- | `aiFilterFallback` | string | 接受 | AI 过滤超时或模型不可用时的兜底策略,取值:接受、拒绝 |
128
+ | `aiFilterFallback` | string | 接受 | 兜底策略,取值:接受、拒绝 |
127
129
 
128
130
  ### 调试配置 (Debug Settings)
129
131
  | 配置项 (Config) | 类型 (Type) | 默认值 (Default) | 说明 (Description) |
130
132
  |----------------|-------------|-------------------|---------------------|
131
133
  | `debug` | boolean | false | 输出调试日志 |
132
- | `debugOnly` | string | 全部 | 调试日志范围,取值:全部、自动获取、AI调用、HTTP接口、服务内部 |
134
+ | `debugOnly` | string | 全部 | 取值:全部、自动获取、AI调用、HTTP接口、服务内部 |
133
135
  | `logLimit` | number | 200 | 调试日志环形缓冲条数 |
134
136
 
135
137
  ## 名称模板变量 (Name Template Variables)
@@ -144,23 +146,12 @@ This is an **intelligent meme management plugin** developed for the Koishi bot f
144
146
  | `{chat}` | 群号,私聊时为 direct |
145
147
  | `{index}` | 递增序号 |
146
148
 
147
- ## 支持的图片来源 (Supported Image Sources)
148
-
149
- | 来源 (Source) | 示例 (Example) | 处理方式 (Handling) |
150
- |---------------|----------------|---------------------|
151
- | HTTP 与 HTTPS | `https://gchat.qpic.cn/…` | 走 `ctx.http` 拉取,带 UA 与超时 |
152
- | 本地绝对路径 | `C:\Users\…\Pic\xx.jpg`、`/data/x.png` | 直接读盘,受 `allowLocalPaths` 与 `localPathRoots` 约束 |
153
- | file URI | `file:///C:/…/x.png` | 解析为本地路径后读取 |
154
- | data URI | `data:image/png;base64,…` | 就地解码 |
155
- | Koishi 内联 | `base64://…` | 就地解码 |
156
- | 缺失属性 | 元素没有 `url`、`src`、`file`、`path` | 拦截并记为取图失败 |
157
-
158
149
  ## 项目贡献者 (Contributors)
159
150
 
160
151
  | 贡献者 (Contributor) | 贡献内容 (Contribution) |
161
152
  |----------------------|-------------------------|
162
153
  | ChatLunaLab | 上游 emojiluna 全部原始功能 (Original upstream work) |
163
- | Minecraft-1314 | fork 改造 |
154
+ | Minecraft-1314 | fork 改造 (Fork) |
164
155
 
165
156
  (欢迎通过 Issues 或 PR 加入贡献者列表)
166
157