alemonjs-aichat 1.0.6 → 1.0.7

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.
@@ -18,6 +18,7 @@ const regular$11 = /(\/|#)(开启|启用|关闭|禁用)好感度$/i;
18
18
  const regular$13 = /(\/|#)(开启|关闭)聊天$/i;
19
19
  const regular$14 = /(\/|#)(开启|关闭)语音回复$/i;
20
20
  const regular$15 = /(\/|#)(开启|关闭)工具$/i;
21
+ const regular$16 = /(\/|#)切换图床(.*)$/i;
21
22
  const test = /(\/|#)测试$/i;
22
23
  const regular = Regular.or(regular$1, regular$2, regular$3, regular$4, regular$5, regular$6, regular$7, regular$8, regular$10, regular$11, regular$13, regular$14);
23
24
  var res = onResponse(selects, async (e, next) => {
@@ -205,6 +206,23 @@ var res = onResponse(selects, async (e, next) => {
205
206
  message.send(format(Text(`已${enable ? "开启" : "关闭"}工具功能 !\n请注意当前模型是否支持工具调用。`)));
206
207
  return;
207
208
  }
209
+ // 设置图床
210
+ if (regular$16.test(e.msg)) {
211
+ const match = e.msg.match(regular$16);
212
+ if (!match) {
213
+ message.send(format(Text("格式错误,请按照 格式:/切换图床 <图床名称> 进行设置")));
214
+ return;
215
+ }
216
+ const [, , bedName] = match;
217
+ const validBeds = ["R2", "又拍云"];
218
+ if (!validBeds.includes(bedName.trim())) {
219
+ message.send(format(Text(`无效的图床名称!可用图床有:${validBeds.join("、")}。`)));
220
+ return;
221
+ }
222
+ await redis.set(`chat:image:bed`, bedName.trim());
223
+ message.send(format(Text(`已切换图床至 ${bedName.trim()} !`)));
224
+ return;
225
+ }
208
226
  // 无匹配则继续下一个响应器
209
227
  next();
210
228
  });
package/lib/s3.js CHANGED
@@ -2,33 +2,8 @@ import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
2
2
  import fs from 'fs/promises';
3
3
  import path from 'path';
4
4
  import mime from 'mime-types';
5
+ import { redis } from './redis.js';
5
6
 
6
- // ======== 配置 ========
7
- // 请替换成你真实的 R2 API Token 凭证
8
- // const R2_CONFIG = {
9
- // accessKeyId: "f8f0d360d3156a1667c527c5ea4b18d7", // ← 必须替换!从 R2 API Tokens 获取
10
- // secretAccessKey:
11
- // "365f44cf6079054ad99923dd32966d0aba4e4d2d24726cadcd0102a7c2e7bc08", // ← 确认这是 Secret Access Key
12
- // bucket: "images",
13
- // publicDomain: "https://r2img.ccxk.top", // ← 改成你的公共域名(推荐)
14
- // endpoint: "https://b24a196dc2ee578845bb555d53812508.r2.cloudflarestorage.com", // R2 固定格式
15
- // };
16
- const R2_CONFIG = {
17
- accessKeyId: "pCLV51yDLbntzsfUkgBSjo5fJSor3nr5", // ← 必须替换!从 R2 API Tokens 获取
18
- secretAccessKey: "5672e62135be31808f1afbd35862839e", // ← 确认这是 Secret Access Key
19
- bucket: "schub-image",
20
- publicDomain: "https://s3img.suancaixianyu.cn", // ← 改成你的公共域名(推荐)
21
- endpoint: "https://s3.api.upyun.com", // R2 固定格式
22
- };
23
- const s3Client = new S3Client({
24
- region: "auto", // R2 固定用 auto
25
- endpoint: R2_CONFIG.endpoint,
26
- credentials: {
27
- accessKeyId: R2_CONFIG.accessKeyId,
28
- secretAccessKey: R2_CONFIG.secretAccessKey,
29
- },
30
- maxAttempts: 3, // 自动重试
31
- });
32
7
  /**
33
8
  * 上传图片到 Cloudflare R2,返回公共访问 URL
34
9
  * @param {string} source - 支持三种格式:
@@ -41,6 +16,31 @@ const s3Client = new S3Client({
41
16
  const uploadImageToR2 = async (source, key) => {
42
17
  let buffer;
43
18
  let contentType = "image/jpeg"; // 默认
19
+ const config = (await redis.get(`chat:image:bed`)) || "R2";
20
+ const R2_CONFIG = config == "R2"
21
+ ? {
22
+ accessKeyId: "f8f0d360d3156a1667c527c5ea4b18d7", // ← 必须替换!从 R2 API Tokens 获取
23
+ secretAccessKey: "365f44cf6079054ad99923dd32966d0aba4e4d2d24726cadcd0102a7c2e7bc08", // ← 确认这是 Secret Access Key
24
+ bucket: "images",
25
+ publicDomain: "https://r2img.ccxk.top", // ← 改成你的公共域名(推荐)
26
+ endpoint: "https://b24a196dc2ee578845bb555d53812508.r2.cloudflarestorage.com", // R2 固定格式
27
+ }
28
+ : {
29
+ accessKeyId: "pCLV51yDLbntzsfUkgBSjo5fJSor3nr5", // ← 必须替换!从 R2 API Tokens 获取
30
+ secretAccessKey: "5672e62135be31808f1afbd35862839e", // ← 确认这是 Secret Access Key
31
+ bucket: "schub-image",
32
+ publicDomain: "https://s3img.suancaixianyu.cn", // ← 改成你的公共域名(推荐)
33
+ endpoint: "https://s3.api.upyun.com", // R2 固定格式
34
+ };
35
+ const s3Client = new S3Client({
36
+ region: "auto", // R2 固定用 auto
37
+ endpoint: R2_CONFIG.endpoint,
38
+ credentials: {
39
+ accessKeyId: R2_CONFIG.accessKeyId,
40
+ secretAccessKey: R2_CONFIG.secretAccessKey,
41
+ },
42
+ maxAttempts: 3, // 自动重试
43
+ });
44
44
  // 1. 处理不同来源 → 统一得到 Buffer + contentType + fileName
45
45
  if (source.startsWith("http://") || source.startsWith("https://")) {
46
46
  // 远程 URL
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs-aichat",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "alemonjs-aichat",
5
5
  "author": "suancaixianyu",
6
6
  "license": "MIT",
@@ -12,7 +12,8 @@
12
12
  "review": "npx alemonc start",
13
13
  "start": "npx pm2 startOrRestart pm2.config.cjs",
14
14
  "stop": "npx pm2 stop pm2.config.cjs",
15
- "delete": "npx pm2 delete pm2.config.cjs"
15
+ "delete": "npx pm2 delete pm2.config.cjs",
16
+ "update": "npm publish"
16
17
  },
17
18
  "devDependencies": {
18
19
  "@alemonjs/bubble": "^2.1.0-alpha.12",