mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
add sleep
This commit is contained in:
2
index.d.ts
vendored
2
index.d.ts
vendored
@@ -1062,7 +1062,7 @@ declare namespace WAWebJS {
|
||||
|
||||
/** Adds or removes a list of participants by ID to the group */
|
||||
export type ChangeGroupParticipants =
|
||||
(participantIds: Array<string>) => Promise<{
|
||||
(participantIds: Array<string>, sleep?: number) => Promise<{
|
||||
status: number;
|
||||
participants: Array<{
|
||||
[key: string]: {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Chat = require('./Chat');
|
||||
const Util = require('../util/Util')
|
||||
|
||||
/**
|
||||
* Group participant information
|
||||
@@ -55,70 +56,86 @@ class GroupChat extends Chat {
|
||||
|
||||
/**
|
||||
* Adds a list of participants by ID to the group
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} sleep optional, amount to sleep in milliseconds before adding the next participant
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async addParticipants(participantIds) {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
||||
async addParticipants(participantIds, sleep = null) {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds, sleep) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||
const status = [];
|
||||
for (const participantWid of participantWids) {
|
||||
status.push(await window.Store.GroupParticipants.sendAddParticipants(chatWid, participantWid));
|
||||
if (sleep) {
|
||||
await Util.sleep(sleep)
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}, this.id._serialized, participantIds);
|
||||
}, this.id._serialized, participantIds, sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a list of participants by ID to the group
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} sleep optional, amount to sleep in milliseconds before removing the next participant
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async removeParticipants(participantIds) {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
||||
async removeParticipants(participantIds, sleep = null) {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds, sleep) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||
const status = [];
|
||||
for (const participantWid of participantWids) {
|
||||
status.push(await window.Store.GroupParticipants.sendRemoveParticipants(chatWid, participantWid));
|
||||
if (sleep) {
|
||||
await Util.sleep(sleep)
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}, this.id._serialized, participantIds);
|
||||
}, this.id._serialized, participantIds, sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Promotes participants by IDs to admins
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} sleep optional, amount to sleep in milliseconds before promoting the next participant
|
||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
||||
*/
|
||||
async promoteParticipants(participantIds) {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
||||
async promoteParticipants(participantIds, sleep = null) {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds, sleep) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||
const status = [];
|
||||
for (const participantWid of participantWids) {
|
||||
status.push(await window.Store.GroupParticipants.sendPromoteParticipants(chatWid, participantWid));
|
||||
if (sleep) {
|
||||
await Util.sleep(sleep)
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}, this.id._serialized, participantIds);
|
||||
}, this.id._serialized, participantIds, sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Demotes participants by IDs to regular users
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {Array<string>} participantIds
|
||||
* @param {?number} sleep optional, amount to sleep in milliseconds before demoting the next participant
|
||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
||||
*/
|
||||
async demoteParticipants(participantIds) {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
||||
async demoteParticipants(participantIds, sleep = null) {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds, sleep) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||
const status = [];
|
||||
for (const participantWid of participantWids) {
|
||||
status.push(await window.Store.GroupParticipants.sendDemoteParticipants(chatWid, participantWid));
|
||||
if (sleep) {
|
||||
await Util.sleep(sleep)
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}, this.id._serialized, participantIds);
|
||||
}, this.id._serialized, participantIds, sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -181,6 +181,10 @@ class Util {
|
||||
static setFfmpegPath(path) {
|
||||
ffmpeg.setFfmpegPath(path);
|
||||
}
|
||||
|
||||
static sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
||||
Reference in New Issue
Block a user