mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-17 02:03:18 +08:00
feat: add native result-file delivery
This commit is contained in:
parent
2803bbcbab
commit
d472dd5a75
65 changed files with 10205 additions and 255 deletions
|
|
@ -112,7 +112,7 @@ export function normalizeDiscordMessage(message, botId, { fetchImpl = fetch } =
|
|||
};
|
||||
}
|
||||
|
||||
class DiscordBotClient {
|
||||
export class DiscordBotClient {
|
||||
#api;
|
||||
#signal;
|
||||
|
||||
|
|
@ -123,22 +123,32 @@ class DiscordBotClient {
|
|||
|
||||
async sendText(target, text) {
|
||||
const chunks = splitMessageText(text, 1_900);
|
||||
let result = null;
|
||||
const providerMessageIds = [];
|
||||
for (const [index, chunk] of chunks.entries()) {
|
||||
result = await this.#api.createMessage({
|
||||
const result = await this.#api.createMessage({
|
||||
channelId: target.channelId,
|
||||
content: chunk,
|
||||
replyToMessageId: index === 0 ? target.replyToMessageId : undefined,
|
||||
signal: this.#signal,
|
||||
});
|
||||
if (typeof result?.id === 'string' && result.id) providerMessageIds.push(result.id);
|
||||
}
|
||||
return result;
|
||||
return { providerMessageIds };
|
||||
}
|
||||
|
||||
sendTyping(target) {
|
||||
return this.#api.sendTyping({ channelId: target.channelId, signal: this.#signal });
|
||||
}
|
||||
|
||||
sendFile(target, file) {
|
||||
return this.#api.createFileMessage({
|
||||
channelId: target.channelId,
|
||||
file,
|
||||
replyToMessageId: target.replyToMessageId,
|
||||
signal: this.#signal,
|
||||
});
|
||||
}
|
||||
|
||||
async openStream(target) {
|
||||
const stream = createEditableMessageStream({
|
||||
limit: 1_900,
|
||||
|
|
@ -162,6 +172,7 @@ class DiscordBotClient {
|
|||
content,
|
||||
signal: this.#signal,
|
||||
}),
|
||||
messageIdForResult: (message) => message?.id,
|
||||
});
|
||||
return stream.start();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue