@mrlingxd/koishi-plugin-adapter-onebot 0.2.3 → 0.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/lib/bot/message.js +4 -16
  2. package/package.json +1 -1
@@ -164,28 +164,16 @@ export class OneBotMessageEncoder extends MessageEncoder {
164
164
  this.text(`(${attrs.href})`);
165
165
  }
166
166
  else if (["video", "audio", "image", "img"].includes(type)) {
167
- let childrenType;
167
+ const typeMap = { video: "video", audio: "record", img: "image", image: "image" };
168
+ const childrenType = typeMap[type];
168
169
  if (type === "video" || type === "audio") {
169
170
  await this.flush();
170
171
  }
171
- if (type === "video")
172
- childrenType = "video";
173
- if (type === "audio")
174
- childrenType = "record";
175
- if (type === "img")
176
- childrenType = "image";
177
172
  attrs = { ...attrs };
178
- attrs.file = attrs.src || attrs.url;
173
+ attrs.file = attrs.src || attrs.url || attrs.file;
179
174
  delete attrs.src;
180
175
  delete attrs.url;
181
- if (attrs.cache) {
182
- attrs.cache = 1;
183
- }
184
- else {
185
- attrs.cache = 0;
186
- }
187
- // https://github.com/koishijs/koishi-plugin-adapter-onebot/issues/30
188
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
176
+ attrs.cache = attrs.cache ? 1 : 0;
189
177
  const cap = /^data:([\w/.+-]+);base64,/.exec(attrs.file);
190
178
  if (cap)
191
179
  attrs.file = "base64://" + attrs.file.slice(cap[0].length);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrlingxd/koishi-plugin-adapter-onebot",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "OneBot Adapter for Koishi",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",