lint: 0 warnings left

This commit is contained in:
Rajeh Taher
2024-10-14 05:15:10 +03:00
parent 61a0ff3178
commit 18ac07df8e
32 changed files with 652 additions and 1006 deletions

View File

@@ -5,7 +5,7 @@ import { platform, release } from 'os'
import { Logger } from 'pino'
import { proto } from '../../WAProto'
import { version as baileysVersion } from '../Defaults/baileys-version.json'
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, DisconnectReason, WACallUpdateType, WAVersion } from '../Types'
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, DisconnectReason, WACallUpdateType, WAVersion } from '../Types'
import { BinaryNode, getAllBinaryNodeChildren, jidDecode } from '../WABinary'
const PLATFORM_MAP = {
@@ -33,6 +33,7 @@ export const getPlatformId = (browser: string) => {
}
export const BufferJSON = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
replacer: (k, value: any) => {
if(Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') }
@@ -40,6 +41,8 @@ export const BufferJSON = {
return value
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reviver: (_, value: any) => {
if(typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
const val = value.data || value.value
@@ -52,7 +55,7 @@ export const BufferJSON = {
export const getKeyAuthor = (
key: proto.IMessageKey | undefined | null,
meId: string = 'me'
meId = 'me'
) => (
(key?.fromMe ? meId : key?.participant || key?.remoteJid) || ''
)
@@ -102,14 +105,14 @@ export const encodeBigEndian = (e: number, t = 4) => {
return a
}
export const toNumber = (t: Long | number | null | undefined): number => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : (t as any).low) : t)
export const toNumber = (t: Long | number | null | undefined): number => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : (t as Long).low) : t || 0)
/** unix timestamp of a date in seconds */
export const unixTimestampSeconds = (date: Date = new Date()) => Math.floor(date.getTime() / 1000)
export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>
export const debouncedTimeout = (intervalMs: number = 1000, task?: () => void) => {
export const debouncedTimeout = (intervalMs = 1000, task?: () => void) => {
let timeout: NodeJS.Timeout | undefined
return {
start: (newIntervalMs?: number, newTask?: () => void) => {
@@ -184,9 +187,9 @@ export const generateMessageIDV2 = (userId?: string): string => {
const data = Buffer.alloc(8 + 20 + 16)
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
if (userId) {
if(userId) {
const id = jidDecode(userId)
if (id?.user) {
if(id?.user) {
data.write(id.user, 8)
data.write('@c.us', 8 + id.user.length)
}
@@ -205,7 +208,7 @@ export const generateMessageID = () => '3EB0' + randomBytes(18).toString('hex').
export function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T) {
return async(check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => {
let listener: (item: BaileysEventMap[T]) => void
let closeListener: any
let closeListener: (state: Partial<ConnectionState>) => void
await (
promiseTimeout<void>(
timeoutMs,
@@ -256,7 +259,7 @@ export const printQRIfNecessaryListener = (ev: BaileysEventEmitter, logger: Logg
* utility that fetches latest baileys version from the master branch.
* Use to ensure your WA connection is always on the latest version
*/
export const fetchLatestBaileysVersion = async(options: AxiosRequestConfig<any> = { }) => {
export const fetchLatestBaileysVersion = async(options: AxiosRequestConfig<{}> = { }) => {
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json'
try {
const result = await axios.get<{ version: WAVersion }>(
@@ -283,7 +286,7 @@ export const fetchLatestBaileysVersion = async(options: AxiosRequestConfig<any>
* A utility that fetches the latest web version of whatsapp.
* Use to ensure your WA connection is always on the latest version
*/
export const fetchLatestWaWebVersion = async(options: AxiosRequestConfig<any>) => {
export const fetchLatestWaWebVersion = async(options: AxiosRequestConfig<{}>) => {
try {
const result = await axios.get(
'https://web.whatsapp.com/check-update?version=1&platform=web',
@@ -393,6 +396,7 @@ export const getCodeFromWSError = (error: Error) => {
statusCode = code
}
} else if(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(error as any)?.code?.startsWith('E')
|| error?.message?.includes('timed out')
) { // handle ETIMEOUT, ENOTFOUND etc
@@ -410,7 +414,8 @@ export const isWABusinessPlatform = (platform: string) => {
return platform === 'smbi' || platform === 'smba'
}
export function trimUndefined(obj: any) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function trimUndefined(obj: {[_: string]: any}) {
for(const key in obj) {
if(typeof obj[key] === 'undefined') {
delete obj[key]
@@ -427,8 +432,8 @@ export function bytesToCrockford(buffer: Buffer): string {
let bitCount = 0
const crockford: string[] = []
for(let i = 0; i < buffer.length; i++) {
value = (value << 8) | (buffer[i] & 0xff)
for(const element of buffer) {
value = (value << 8) | (element & 0xff)
bitCount += 8
while(bitCount >= 5) {