mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Set Status + Set Group Description + Better Message Tags
This commit is contained in:
@@ -326,7 +326,7 @@ export default class WAConnectionBase {
|
||||
}
|
||||
}
|
||||
generateMessageTag () {
|
||||
return `${this.referenceDate.getTime()/1000}.--${this.msgCount}`
|
||||
return `${Math.round(this.referenceDate.getTime())/1000}.--${this.msgCount}`
|
||||
}
|
||||
protected log(text, level: MessageLogLevel) {
|
||||
if (this.logLevel >= level)
|
||||
|
||||
@@ -61,6 +61,7 @@ export interface WAGroupMetadata {
|
||||
creation: number
|
||||
desc?: string
|
||||
descOwner?: string
|
||||
descId?: string
|
||||
participants: [{ id: string; isAdmin: boolean; isSuperAdmin: boolean }]
|
||||
}
|
||||
export interface WAGroupModification {
|
||||
|
||||
@@ -65,15 +65,23 @@ export function randomBytes(length) {
|
||||
return Crypto.randomBytes(length)
|
||||
}
|
||||
export const createTimeout = (timeout) => new Promise(resolve => setTimeout(resolve, timeout))
|
||||
export function promiseTimeout<T>(ms: number, promise: Promise<T>) {
|
||||
export async function promiseTimeout<T>(ms: number, promise: Promise<T>) {
|
||||
if (!ms) return promise
|
||||
// Create a promise that rejects in <ms> milliseconds
|
||||
const timeout = createTimeout (ms).then (() => { throw new BaileysError ('Timed out', promise) })
|
||||
return Promise.race([promise, timeout]) as Promise<T>
|
||||
let timeoutI
|
||||
const timeout = new Promise(
|
||||
(_, reject) => timeoutI = setTimeout(() => reject(new BaileysError ('Timed out', promise)), ms)
|
||||
)
|
||||
try {
|
||||
const content = await Promise.race([promise, timeout])
|
||||
return content as T
|
||||
} finally {
|
||||
clearTimeout (timeoutI)
|
||||
}
|
||||
}
|
||||
// whatsapp requires a message tag for every message, we just use the timestamp as one
|
||||
export function generateMessageTag(epoch?: number) {
|
||||
let tag = new Date().getTime().toString()
|
||||
let tag = Math.round(new Date().getTime()/1000).toString()
|
||||
if (epoch) tag += '.--' + epoch // attach epoch if provided
|
||||
return tag
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user