Commit c1ea2edb authored by nanahira's avatar nanahira

update behavior of broadcast

parent 00e20f8a
...@@ -339,7 +339,11 @@ export class WeComBot extends Bot<BotConfig> { ...@@ -339,7 +339,11 @@ export class WeComBot extends Bot<BotConfig> {
return this.sendPrivateMessage(channelId, content); return this.sendPrivateMessage(channelId, content);
} }
async sendPrivateMessage(userId, content) { async sendPrivateMessage(
userId: string,
content: string,
extraUsers: string[] = [],
) {
const session = await this.session({ const session = await this.session({
content, content,
subtype: 'private', subtype: 'private',
...@@ -347,6 +351,7 @@ export class WeComBot extends Bot<BotConfig> { ...@@ -347,6 +351,7 @@ export class WeComBot extends Bot<BotConfig> {
channelId: userId, channelId: userId,
}); });
if (!session?.content) return []; if (!session?.content) return [];
const userIds = [userId, ...extraUsers];
const chain = segment.parse(session.content); const chain = segment.parse(session.content);
const messageIds: string[] = []; const messageIds: string[] = [];
let isMarkdown = false; let isMarkdown = false;
...@@ -361,8 +366,8 @@ export class WeComBot extends Bot<BotConfig> { ...@@ -361,8 +366,8 @@ export class WeComBot extends Bot<BotConfig> {
const content = data.content.trim(); const content = data.content.trim();
messageIds.push( messageIds.push(
isMarkdown isMarkdown
? await this.sendMarkdownMessage(content, [userId]) ? await this.sendMarkdownMessage(content, userIds)
: await this.sendTextMessage(content, [userId]), : await this.sendTextMessage(content, userIds),
); );
break; break;
case 'image': case 'image':
...@@ -381,7 +386,7 @@ export class WeComBot extends Bot<BotConfig> { ...@@ -381,7 +386,7 @@ export class WeComBot extends Bot<BotConfig> {
break; break;
} }
messageIds.push( messageIds.push(
await this.sendMediaMessage(type, filename, buffer, [userId]), await this.sendMediaMessage(type, filename, buffer, userIds),
); );
break; break;
default: default:
...@@ -396,6 +401,16 @@ export class WeComBot extends Bot<BotConfig> { ...@@ -396,6 +401,16 @@ export class WeComBot extends Bot<BotConfig> {
return messageIds; return messageIds;
} }
async broadcast(
channels: (string | [string, string])[],
content: string,
delay = this.app.options.delay.broadcast,
) {
const userIds = channels.map((c) => (typeof c === 'string' ? c : c[0]));
if (!userIds.length) return [];
return this.sendPrivateMessage(userIds[0], content, userIds.slice(1));
}
async deleteMessage(channelId: string, messageId: string) { async deleteMessage(channelId: string, messageId: string) {
const token = await this.getToken(); const token = await this.getToken();
if (!token) { if (!token) {
......
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