Commit 5f670ac9 authored by nanahira's avatar nanahira

fix onebot pic send problem

parent d03dc811
import { Adapter } from 'koishi'; import { Adapter, Bot } from 'koishi';
import _ from 'lodash'; import _ from 'lodash';
import { RegisterSchema, SchemaProperty } from 'schemastery-gen'; import { RegisterSchema, SchemaProperty } from 'schemastery-gen';
...@@ -44,23 +44,37 @@ export class SendTarget { ...@@ -44,23 +44,37 @@ export class SendTarget {
} }
} }
private isOneBotBot(bot?: Bot) {
return (
bot &&
(bot.platform === 'onebot' || bot['parentBot']?.platform === 'onebot')
);
}
async send(bots: Adapter.BotList, content: string) { async send(bots: Adapter.BotList, content: string) {
const bot = this.getBot(bots); const bot = this.getBot(bots);
if (!bot) { if (!bot) {
throw new Error(`bot ${this.bot} not found`); throw new Error(`bot ${this.bot} not found`);
} }
let privateContent = content;
let channelContent = content;
if (this.isOneBotBot(bot)) {
content = content.replace(/,url=base64/g, ',file=base64');
privateContent = content.replace(/,url=http/g, ',file=http'); // private should be file
channelContent = content.replace(/,file=http/g, ',url=http'); // channel should be url
}
return _.flatten( return _.flatten(
await Promise.all([ await Promise.all([
...this.users.map((userId) => ...this.users.map((userId) =>
bot.sendPrivateMessage bot.sendPrivateMessage
? bot.sendPrivateMessage(userId, content) ? bot.sendPrivateMessage(userId, privateContent)
: bot.sendMessage(`@${userId}`, content), : bot.sendMessage(`@${userId}`, privateContent),
), ),
...(this.channels?.length ...(this.channels?.length
? [ ? [
bot.broadcast( bot.broadcast(
this.channels.map((c) => c.toDesc()), this.channels.map((c) => c.toDesc()),
content, channelContent,
), ),
] ]
: []), : []),
......
This diff is collapsed.
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
"typescript": "^4.6.2" "typescript": "^4.6.2"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.7.1", "koishi": "^4.7.4",
"schemastery": "^3.4.3", "schemastery": "^3.4.3",
"schemastery-gen": "^3.1.6" "schemastery-gen": "^3.1.6"
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment