@imjxsx/wapi 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <h1>⚡ @imjxsx/wapi (v1.2.0)</h1>
2
+ <h1>⚡ @imjxsx/wapi (v1.3.2)</h1>
3
3
  <p>Framework for developing bots for the WhatsApp application: fast, secure, and elegant, powered by Baileys and developed 100% in TypeScript</p>
4
4
  </div>
5
5
 
package/dist/core/bot.js CHANGED
@@ -1,2 +1,2 @@
1
- import M from"@imjxsx/logger";import A from"node:events";import{Boom as l}from"@hapi/boom";import{makeWASocket as k}from"baileys";import{Context as g}from"./context/context.js";import{decode as y,isGroup as w,isLid as d,isPn as m,normalize as v,toError as o}from"../utils/index.js";import b from"node:os";import{contacts as p,groups as c}from"../cache/index.js";import{Autolinker as B}from"autolinker";import{load as E}from"cheerio";class N extends A{uuid;ws=null;auth;account;status="close";logger;ping=0;prefix="!/";middlewares=[];commands=new Map;constructor(r,e,s,t){super(),this.uuid=r,this.auth=e,this.account=s,this.logger=t??new M({name:`Bot ${this.uuid}`,colorize:process.env.NODE_ENV!=="production",level:process.env.NODE_ENV!=="production"?"TRACE":"INFO"})}use(...r){this.middlewares.push(...r)}command(r,...e){if(!r)throw new Error("The command name must be at least 1 character long.");this.commands.set(r,e)}async login(r){try{const e=await this.auth.init();this.ws=k({auth:e,browser:[b.platform(),"Firefox",b.release()],logger:this.logger.child({name:`WASocket ${this.uuid} `}),qrTimeout:6e4,markOnlineOnConnect:!0,syncFullHistory:!1,shouldSyncHistoryMessage:()=>!1,generateHighQualityLinkPreview:!0,linkPreviewImageThumbnailWidth:1980,shouldIgnoreJid:s=>!w(s)&&!m(s)&&!d(s),cachedGroupMetadata:async s=>c.get(s),version:[2,3e3,1027934701]}),this.ws.ev.on("creds.update",async()=>{try{await this.auth.save()}catch(s){this.emit("error",o(s))}}),this.ws.ev.on("connection.update",async s=>{try{if(s.qr)if(r==="otp"){if(!m(this.account.pn)){await this.disconnect(new l("The OTP code cannot be generated because a number was not provided.",{statusCode:400}));return}const t=await this.ws?.requestPairingCode(y(this.account.pn).jid);if(!t){await this.disconnect(new l(`An OTP code could not be generated for '@${y(this.account.pn).jid}'`,{statusCode:400}));return}this.emit("otp",t)}else this.emit("qr",s.qr);if(s.connection==="close"){this.ws?.ev.removeAllListeners(void 0);const t=new l(s.lastDisconnect?.error).output;switch(this.emit("close",`${t.payload.error} ${t.payload.statusCode}: ${t.payload.message}`),t.payload.statusCode){case 400:case 401:case 403:case 404:case 405:{await this.auth.remove(),this.ws=null,this.removeAllListeners(),this.status="close";break}case 503:{await new Promise(i=>setTimeout(i,3e4)),this.status="reconnecting",await this.login(r);break}case 515:{this.status="reconnecting",await this.login(r);break}default:{if(t.payload.message==="Intentional disconnection."){this.ws=null,this.removeAllListeners(),this.status="close";break}await new Promise(i=>setTimeout(i,5e3)),this.status="reconnecting",await this.login(r)}}return}else if(s.connection==="open"){const t=v(this.ws?.user?.lid),i=v(this.ws?.user?.id),n=this.ws?.user?.verifiedName??this.ws?.user?.name??"";if(!m(i)||!d(t)){await this.disconnect(new l("Restart required.",{statusCode:515}));return}this.account={jid:t,pn:i,name:n},p.set(t,{jid:t,pn:i,name:n}),this.status="open",this.emit("open",this.account);return}}catch(t){this.emit("error",o(t))}}),this.ws.ev.on("messages.upsert",async s=>{try{if(s.type!=="notify"||!s.messages.length)return;for(const t of s.messages){const i=new g(this,t);if(w(i.chat.jid)&&!c.has(i.chat.jid)){const a=await this.groupMetadata(i.chat.jid);a&&c.set(i.chat.jid,a)}d(i.from.jid)&&m(i.from.pn)&&p.set(i.from.jid,{jid:i.from.jid,pn:i.from.pn,name:i.from.name});const n=[...this.middlewares,...this.commands.get(i.commandName)??[]];if(n.length){let a=-1;const u=async h=>{if(h<=a)throw new Error("next() called multiple times.");a=h;const f=n[h];f&&await f(i,async()=>{await u(h+1)})};await u(0)}}}catch(t){this.emit("error",o(t))}}),this.ws.ev.on("contacts.update",s=>{try{for(const t of s){if(!d(t.id)||!p.has(t.id))continue;const i=t.verifiedName??t.notify,n=p.get(t.id);i&&n.name!==i&&(n.name=i)}}catch(t){this.emit("error",o(t))}}),this.ws.ev.on("groups.update",async s=>{try{for(const t of s){if(!w(t.id))continue;c.delete(t.id);const i=await this.groupMetadata(t.id);i&&c.set(t.id,i)}}catch(t){this.emit("error",o(t))}})}catch(e){this.emit("error",o(e))}}async disconnect(r){try{r??=new Error("Intentional disconnection."),this.ws?.end(r)}catch(e){this.emit("error",o(e))}}async logout(r){try{await this.ws?.logout(r?.message)}catch(e){this.emit("error",o(e))}}parseMentions(r,e){try{const s=new Set;for(const t of r.matchAll(/@(\d{7,})/g))t[1]&&s.add(`${t[1]}@${e}`);return Array.from(s.values())}catch(s){return this.emit("error",o(s)),[]}}parseLinks(r){try{const e=new Set,s=B.link(r,{urls:{schemeMatches:!0,ipV4Matches:!1,tldMatches:!0},email:!0,phone:!0,mention:!1,hashtag:!1,stripPrefix:!1,stripTrailingSlash:!1}),t=E(s);return t("a").each((i,n)=>{const a=t(n).attr("href");a&&e.add(a)}),Array.from(e.values())}catch(e){return this.emit("error",o(e)),[]}}async sendMessage(r,e,s){try{if(!this.ws?.ws.isOpen)throw new Error("The WASocket connection is not open.");const t=performance.now(),i="text"in e&&e.text?e.text:"caption"in e&&e.caption?e.caption:"",n=this.parseMentions(i,s?.addressing==="lid"?"lid":"s.whatsapp.net"),a=await this.ws.sendMessage(r,{...e,mentions:"mentions"in e&&e.mentions?e.mentions.concat(...n):n},s);if(!a)return null;const u=performance.now();return this.ping=u-t,new g(this,a)}catch(t){return this.emit("error",o(t)),null}}async groupMetadata(r){try{if(!this.ws?.ws.isOpen)throw new Error("The WASocket connection is not open.");return c.get(r)??await this.ws.groupMetadata(r)}catch(e){return this.emit("error",o(e)),null}}async profilePictureUrl(r){try{if(!this.ws?.ws.isOpen)throw new Error("The WASocket connection is not open.");return await this.ws.profilePictureUrl(r,"image")??"https://i.pinimg.com/736x/62/01/0d/62010d848b790a2336d1542fcda51789.jpg"}catch(e){return this.emit("error",o(e)),"https://i.pinimg.com/736x/62/01/0d/62010d848b790a2336d1542fcda51789.jpg"}}}export{N as Bot};
1
+ import M from"@imjxsx/logger";import A from"node:events";import{Boom as l}from"@hapi/boom";import{makeWASocket as k}from"baileys";import{Context as g}from"./context/context.js";import{decode as y,isGroup as w,isLid as m,isPn as d,normalize as v,toError as o}from"../utils/index.js";import b from"node:os";import{contacts as p,groups as c}from"../cache/index.js";import{Autolinker as B}from"autolinker";import{load as E}from"cheerio";class N extends A{uuid;ws=null;auth;account;status="close";logger;ping=0;prefix="!/";middlewares=[];commands=new Map;constructor(r,s,e,t){super(),this.uuid=r,this.auth=s,this.account=e,this.logger=t??new M({name:`Bot ${this.uuid}`,colorize:process.env.NODE_ENV!=="production",level:process.env.NODE_ENV!=="production"?"TRACE":"INFO"})}use(...r){this.middlewares.push(...r)}command(r,...s){if(!r)throw new Error("The command name must be at least 1 character long.");this.commands.set(r,s)}async login(r){try{const s=await this.auth.init();this.ws=k({auth:s,browser:[b.platform(),"Firefox",b.release()],logger:this.logger.child({name:`WASocket ${this.uuid} `}),qrTimeout:6e4,markOnlineOnConnect:!0,syncFullHistory:!1,shouldSyncHistoryMessage:()=>!1,generateHighQualityLinkPreview:!0,linkPreviewImageThumbnailWidth:1980,shouldIgnoreJid:e=>!w(e)&&!d(e)&&!m(e),cachedGroupMetadata:async e=>c.get(e),version:[2,3e3,1027934701]}),this.ws.ev.on("creds.update",async()=>{try{await this.auth.save()}catch(e){this.emit("error",o(e))}}),this.ws.ev.on("connection.update",async e=>{try{if(e.qr)if(r==="otp"){if(!d(this.account.pn)){await this.disconnect(new l("The OTP code cannot be generated because a number was not provided.",{statusCode:400}));return}const t=await this.ws?.requestPairingCode(y(this.account.pn).jid);if(!t){await this.disconnect(new l(`An OTP code could not be generated for '@${y(this.account.pn).jid}'`,{statusCode:400}));return}this.emit("otp",t)}else this.emit("qr",e.qr);if(e.connection==="close"){this.ws?.ev.removeAllListeners(void 0);const t=new l(e.lastDisconnect?.error).output;switch(this.emit("close",`${t.payload.error} ${t.payload.statusCode}: ${t.payload.message}`),t.payload.statusCode){case 400:case 401:case 403:case 404:case 405:{await this.auth.remove(),this.ws=null,this.removeAllListeners(),this.status="close";break}case 503:{await new Promise(i=>setTimeout(i,3e4)),this.status="reconnecting",await this.login(r);break}case 515:{this.status="reconnecting",await this.login(r);break}default:{if(e.lastDisconnect?.error?.message==="Intentional disconnection."){this.ws=null,this.removeAllListeners(),this.status="close";break}await new Promise(i=>setTimeout(i,5e3)),this.status="reconnecting",await this.login(r)}}return}else if(e.connection==="open"){const t=v(this.ws?.user?.lid),i=v(this.ws?.user?.id),n=this.ws?.user?.verifiedName??this.ws?.user?.name??"";if(!d(i)||!m(t)){await this.disconnect(new l("Restart required.",{statusCode:515}));return}this.account={jid:t,pn:i,name:n},p.set(t,{jid:t,pn:i,name:n}),this.status="open",this.emit("open",this.account);return}}catch(t){this.emit("error",o(t))}}),this.ws.ev.on("messages.upsert",async e=>{try{if(e.type!=="notify"||!e.messages.length)return;for(const t of e.messages){const i=new g(this,t);if(w(i.chat.jid)&&!c.has(i.chat.jid)){const a=await this.groupMetadata(i.chat.jid);a&&c.set(i.chat.jid,a)}m(i.from.jid)&&d(i.from.pn)&&p.set(i.from.jid,{jid:i.from.jid,pn:i.from.pn,name:i.from.name});const n=[...this.middlewares,...this.commands.get(i.commandName)??[]];if(n.length){let a=-1;const u=async h=>{if(h<=a)throw new Error("next() called multiple times.");a=h;const f=n[h];f&&await f(i,async()=>{await u(h+1)})};await u(0)}}}catch(t){this.emit("error",o(t))}}),this.ws.ev.on("contacts.update",e=>{try{for(const t of e){if(!m(t.id)||!p.has(t.id))continue;const i=t.verifiedName??t.notify,n=p.get(t.id);i&&n.name!==i&&(n.name=i)}}catch(t){this.emit("error",o(t))}}),this.ws.ev.on("groups.update",async e=>{try{for(const t of e){if(!w(t.id))continue;c.delete(t.id);const i=await this.groupMetadata(t.id);i&&c.set(t.id,i)}}catch(t){this.emit("error",o(t))}})}catch(s){this.emit("error",o(s))}}async disconnect(r){try{r??=new Error("Intentional disconnection."),this.ws?.end(r)}catch(s){this.emit("error",o(s))}}async logout(r){try{await this.ws?.logout(r?.message)}catch(s){this.emit("error",o(s))}}parseMentions(r,s){try{const e=new Set;for(const t of r.matchAll(/@(\d{7,})/g))t[1]&&e.add(`${t[1]}@${s}`);return Array.from(e.values())}catch(e){return this.emit("error",o(e)),[]}}parseLinks(r){try{const s=new Set,e=B.link(r,{urls:{schemeMatches:!0,ipV4Matches:!1,tldMatches:!0},email:!0,phone:!0,mention:!1,hashtag:!1,stripPrefix:!1,stripTrailingSlash:!1}),t=E(e);return t("a").each((i,n)=>{const a=t(n).attr("href");a&&s.add(a)}),Array.from(s.values())}catch(s){return this.emit("error",o(s)),[]}}async sendMessage(r,s,e){try{if(!this.ws?.ws.isOpen)throw new Error("The WASocket connection is not open.");const t=performance.now(),i="text"in s&&s.text?s.text:"caption"in s&&s.caption?s.caption:"",n=this.parseMentions(i,e?.addressing==="lid"?"lid":"s.whatsapp.net"),a=await this.ws.sendMessage(r,{...s,mentions:"mentions"in s&&s.mentions?s.mentions.concat(...n):n},e);if(!a)return null;const u=performance.now();return this.ping=u-t,new g(this,a)}catch(t){return this.emit("error",o(t)),null}}async groupMetadata(r){try{if(!this.ws?.ws.isOpen)throw new Error("The WASocket connection is not open.");return c.get(r)??await this.ws.groupMetadata(r)}catch(s){return this.emit("error",o(s)),null}}async profilePictureUrl(r){try{if(!this.ws?.ws.isOpen)throw new Error("The WASocket connection is not open.");return await this.ws.profilePictureUrl(r,"image")??"https://i.pinimg.com/736x/62/01/0d/62010d848b790a2336d1542fcda51789.jpg"}catch(s){return this.emit("error",o(s)),"https://i.pinimg.com/736x/62/01/0d/62010d848b790a2336d1542fcda51789.jpg"}}}export{N as Bot};
2
2
  //# sourceMappingURL=bot.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/core/bot.ts"],
4
- "sourcesContent": ["import Logger from \"@imjxsx/logger\";\nimport type { UUID } from \"node:crypto\";\nimport EventEmitter from \"node:events\";\nimport { Boom } from \"@hapi/boom\";\nimport type { BotStatus, BotWASocket, IBotAccount, IBotAuth, IBotEventMap, IBotSendMessageOptions, MiddlewareFn } from \"../types/index.js\";\nimport { BaileysEventMap, makeWASocket, type AnyMessageContent, type GroupMetadata, type JidServer } from \"baileys\";\nimport { Context } from \"./context/context.js\";\nimport { decode, isGroup, isLid, isPn, normalize, toError } from \"../utils/index.js\";\nimport os from \"node:os\";\nimport { contacts, groups } from \"../cache/index.js\";\nimport { Autolinker } from \"autolinker\";\nimport { load } from \"cheerio\";\n\nexport class Bot extends EventEmitter<IBotEventMap> {\n public uuid: UUID;\n public ws: BotWASocket | null = null;\n public auth: IBotAuth;\n public account: IBotAccount;\n public status: BotStatus = \"close\";\n public logger: Logger;\n public ping = 0;\n public prefix = \"!/\";\n /** @private */\n private middlewares: MiddlewareFn[] = [];\n /** @private */\n private commands = new Map<string, MiddlewareFn[]>();\n constructor(uuid: UUID, auth: IBotAuth, account: IBotAccount, logger?: Logger) {\n super();\n this.uuid = uuid;\n this.auth = auth;\n this.account = account;\n this.logger = logger ?? new Logger({\n name: `Bot ${this.uuid}`,\n colorize: process.env[\"NODE_ENV\"] !== \"production\",\n level: process.env[\"NODE_ENV\"] !== \"production\" ? \"TRACE\" : \"INFO\",\n });\n }\n public use(...middlewares: MiddlewareFn[]): void {\n this.middlewares.push(...middlewares);\n }\n public command(name: string, ...middlewares: MiddlewareFn[]): void {\n if (!name) {\n throw new Error(\"The command name must be at least 1 character long.\");\n }\n this.commands.set(name, middlewares);\n }\n public async login(method: \"qr\" | \"otp\"): Promise<void> {\n try {\n const auth = await this.auth.init();\n this.ws = makeWASocket({\n auth,\n browser: [os.platform(), \"Firefox\", os.release()],\n logger: this.logger.child({ name: `WASocket ${this.uuid} ` }),\n qrTimeout: 60_000,\n markOnlineOnConnect: true,\n syncFullHistory: false,\n shouldSyncHistoryMessage: () => (false),\n generateHighQualityLinkPreview: true,\n linkPreviewImageThumbnailWidth: 1_980,\n shouldIgnoreJid: (jid) => {\n if (!isGroup(jid) && !isPn(jid) && !isLid(jid)) {\n return true;\n }\n return false;\n },\n cachedGroupMetadata: async (jid) => {\n return groups.get(jid);\n },\n version: [2, 3_000, 1_027_934_701],\n });\n this.ws.ev.on(\"creds.update\", async () => {\n try {\n await this.auth.save();\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n this.ws.ev.on(\"connection.update\", async (update) => {\n try {\n if (update.qr) {\n if (method === \"otp\") {\n if (!isPn(this.account.pn)) {\n await this.disconnect(new Boom(\"The OTP code cannot be generated because a number was not provided.\", { statusCode: 400 }));\n return;\n }\n const otp = await this.ws?.requestPairingCode(decode(this.account.pn).jid);\n if (!otp) {\n await this.disconnect(new Boom(`An OTP code could not be generated for '@${decode(this.account.pn).jid}'`, { statusCode: 400 }));\n return;\n }\n this.emit(\"otp\", otp);\n }\n else {\n this.emit(\"qr\", update.qr);\n }\n }\n if (update.connection === \"close\") {\n this.ws?.ev.removeAllListeners(undefined as unknown as keyof BaileysEventMap);\n const output = new Boom(update.lastDisconnect?.error).output;\n this.emit(\"close\", `${output.payload.error} ${output.payload.statusCode}: ${output.payload.message}`);\n switch (output.payload.statusCode) {\n case 400:\n case 401:\n case 403:\n case 404:\n case 405: {\n await this.auth.remove();\n this.ws = null;\n this.removeAllListeners();\n this.status = \"close\";\n break;\n }\n case 503: {\n await new Promise((resolve) => (setTimeout(resolve, 30_000)));\n this.status = \"reconnecting\";\n await this.login(method);\n break;\n }\n case 515: {\n this.status = \"reconnecting\";\n await this.login(method);\n break;\n }\n default: {\n if (output.payload.message === \"Intentional disconnection.\") {\n this.ws = null;\n this.removeAllListeners();\n this.status = \"close\";\n break;\n }\n await new Promise((resolve) => (setTimeout(resolve, 5_000)));\n this.status = \"reconnecting\";\n await this.login(method);\n }\n }\n return;\n }\n else if (update.connection === \"open\") {\n const jid = normalize(this.ws?.user?.lid);\n const pn = normalize(this.ws?.user?.id);\n const name = this.ws?.user?.verifiedName ?? this.ws?.user?.name ?? \"\";\n if (!isPn(pn) || !isLid(jid)) {\n await this.disconnect(new Boom(\"Restart required.\", { statusCode: 515 }));\n return;\n }\n this.account = { jid, pn, name };\n contacts.set(jid, { jid, pn, name });\n this.status = \"open\";\n this.emit(\"open\", this.account);\n return;\n }\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n this.ws.ev.on(\"messages.upsert\", async (upsert) => {\n try {\n if (upsert.type !== \"notify\" || !upsert.messages.length) {\n return;\n }\n for (const message of upsert.messages) {\n const ctx = new Context(this, message);\n if (isGroup(ctx.chat.jid)) {\n if (!groups.has(ctx.chat.jid)) {\n const metadata = await this.groupMetadata(ctx.chat.jid);\n if (metadata) {\n groups.set(ctx.chat.jid, metadata);\n }\n }\n }\n if (isLid(ctx.from.jid) && isPn(ctx.from.pn)) {\n contacts.set(ctx.from.jid, { jid: ctx.from.jid, pn: ctx.from.pn, name: ctx.from.name });\n }\n const middlewares = [\n ...this.middlewares,\n ...(this.commands.get(ctx.commandName) ?? []),\n ];\n if (middlewares.length) {\n let index = -1;\n const runner = async (i: number): Promise<void> => {\n if (i <= index) {\n throw new Error(\"next() called multiple times.\");\n }\n index = i;\n const fn = middlewares[i];\n if (!fn) {\n return;\n }\n await fn(ctx, async () => {\n await runner(i + 1);\n });\n };\n await runner(0);\n }\n }\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n this.ws.ev.on(\"contacts.update\", (updates) => {\n try {\n for (const update of updates) {\n if (!isLid(update.id) || !contacts.has(update.id)) {\n continue;\n }\n const name = update.verifiedName ?? update.notify;\n const contact = contacts.get(update.id)!;\n if (name && contact.name !== name) {\n contact.name = name;\n }\n }\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n this.ws.ev.on(\"groups.update\", async (updates) => {\n try {\n for (const update of updates) {\n if (!isGroup(update.id)) {\n continue;\n }\n groups.delete(update.id);\n const metadata = await this.groupMetadata(update.id);\n if (metadata) {\n groups.set(update.id, metadata);\n }\n }\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n }\n public async disconnect(reason?: Error): Promise<void> {\n try {\n reason ??= new Error(\"Intentional disconnection.\");\n this.ws?.end(reason);\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n }\n public async logout(reason?: Boom): Promise<void> {\n try {\n await this.ws?.logout(reason?.message);\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n }\n public parseMentions(text: string, server: JidServer): string[] {\n try {\n const mentions = new Set<string>();\n for (const match of text.matchAll(/@(\\d{7,})/g)) {\n if (!match[1]) {\n continue;\n }\n mentions.add(`${match[1]}@${server}`);\n }\n return Array.from(mentions.values());\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return [];\n }\n }\n public parseLinks(text: string): string[] {\n try {\n const links = new Set<string>();\n const html = Autolinker.link(text, {\n urls: {\n schemeMatches: true,\n ipV4Matches: false,\n tldMatches: true,\n },\n email: true,\n phone: true,\n mention: false,\n hashtag: false,\n stripPrefix: false,\n stripTrailingSlash: false,\n });\n const $ = load(html);\n $(\"a\").each((_, el) => {\n const link = $(el).attr(\"href\");\n if (!link) {\n return;\n }\n links.add(link);\n });\n return Array.from(links.values());\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return [];\n }\n }\n public async sendMessage(jid: string, content: AnyMessageContent, options?: IBotSendMessageOptions): Promise<Context | null> {\n try {\n if (!this.ws?.ws.isOpen) {\n throw new Error(\"The WASocket connection is not open.\");\n }\n const before = performance.now();\n const text = \"text\" in content && content.text ? content.text : \"caption\" in content && content.caption ? content.caption : \"\";\n const mentions = this.parseMentions(text, options?.addressing === \"lid\" ? \"lid\" : \"s.whatsapp.net\");\n const message = await this.ws.sendMessage(jid, {\n ...content,\n mentions: \"mentions\" in content && content.mentions ? content.mentions.concat(...mentions) : mentions,\n }, options);\n if (!message) {\n return null;\n }\n const after = performance.now();\n this.ping = after - before;\n return new Context(this, message);\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return null;\n }\n }\n public async groupMetadata(jid: string): Promise<GroupMetadata | null> {\n try {\n if (!this.ws?.ws.isOpen) {\n throw new Error(\"The WASocket connection is not open.\");\n }\n return groups.get(jid) ?? await this.ws.groupMetadata(jid);\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return null;\n }\n }\n public async profilePictureUrl(jid: string): Promise<string> {\n try {\n if (!this.ws?.ws.isOpen) {\n throw new Error(\"The WASocket connection is not open.\");\n }\n return await this.ws.profilePictureUrl(jid, \"image\") ?? \"https://i.pinimg.com/736x/62/01/0d/62010d848b790a2336d1542fcda51789.jpg\";\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return \"https://i.pinimg.com/736x/62/01/0d/62010d848b790a2336d1542fcda51789.jpg\";\n }\n }\n}"],
5
- "mappings": "AAAA,OAAOA,MAAY,iBAEnB,OAAOC,MAAkB,cACzB,OAAS,QAAAC,MAAY,aAErB,OAA0B,gBAAAC,MAAgF,UAC1G,OAAS,WAAAC,MAAe,uBACxB,OAAS,UAAAC,EAAQ,WAAAC,EAAS,SAAAC,EAAO,QAAAC,EAAM,aAAAC,EAAW,WAAAC,MAAe,oBACjE,OAAOC,MAAQ,UACf,OAAS,YAAAC,EAAU,UAAAC,MAAc,oBACjC,OAAS,cAAAC,MAAkB,aAC3B,OAAS,QAAAC,MAAY,UAEd,MAAMC,UAAYf,CAA2B,CAC3C,KACA,GAAyB,KACzB,KACA,QACA,OAAoB,QACpB,OACA,KAAO,EACP,OAAS,KAER,YAA8B,CAAC,EAE/B,SAAW,IAAI,IACvB,YAAYgB,EAAYC,EAAgBC,EAAsBC,EAAiB,CAC7E,MAAM,EACN,KAAK,KAAOH,EACZ,KAAK,KAAOC,EACZ,KAAK,QAAU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EventEmitter", "Boom", "makeWASocket", "Context", "decode", "isGroup", "isLid", "isPn", "normalize", "toError", "os", "contacts", "groups", "Autolinker", "load", "Bot", "uuid", "auth", "account", "logger", "middlewares", "name", "method", "jid", "e", "update", "otp", "output", "resolve", "pn", "upsert", "message", "ctx", "metadata", "index", "runner", "i", "fn", "updates", "contact", "reason", "text", "server", "mentions", "match", "links", "html", "$", "_", "el", "link", "content", "options", "before", "after"]
4
+ "sourcesContent": ["import Logger from \"@imjxsx/logger\";\nimport type { UUID } from \"node:crypto\";\nimport EventEmitter from \"node:events\";\nimport { Boom } from \"@hapi/boom\";\nimport type { BotStatus, BotWASocket, IBotAccount, IBotAuth, IBotEventMap, IBotSendMessageOptions, MiddlewareFn } from \"../types/index.js\";\nimport { BaileysEventMap, makeWASocket, type AnyMessageContent, type GroupMetadata, type JidServer } from \"baileys\";\nimport { Context } from \"./context/context.js\";\nimport { decode, isGroup, isLid, isPn, normalize, toError } from \"../utils/index.js\";\nimport os from \"node:os\";\nimport { contacts, groups } from \"../cache/index.js\";\nimport { Autolinker } from \"autolinker\";\nimport { load } from \"cheerio\";\n\nexport class Bot extends EventEmitter<IBotEventMap> {\n public uuid: UUID;\n public ws: BotWASocket | null = null;\n public auth: IBotAuth;\n public account: IBotAccount;\n public status: BotStatus = \"close\";\n public logger: Logger;\n public ping = 0;\n public prefix = \"!/\";\n /** @private */\n private middlewares: MiddlewareFn[] = [];\n /** @private */\n private commands = new Map<string, MiddlewareFn[]>();\n constructor(uuid: UUID, auth: IBotAuth, account: IBotAccount, logger?: Logger) {\n super();\n this.uuid = uuid;\n this.auth = auth;\n this.account = account;\n this.logger = logger ?? new Logger({\n name: `Bot ${this.uuid}`,\n colorize: process.env[\"NODE_ENV\"] !== \"production\",\n level: process.env[\"NODE_ENV\"] !== \"production\" ? \"TRACE\" : \"INFO\",\n });\n }\n public use(...middlewares: MiddlewareFn[]): void {\n this.middlewares.push(...middlewares);\n }\n public command(name: string, ...middlewares: MiddlewareFn[]): void {\n if (!name) {\n throw new Error(\"The command name must be at least 1 character long.\");\n }\n this.commands.set(name, middlewares);\n }\n public async login(method: \"qr\" | \"otp\"): Promise<void> {\n try {\n const auth = await this.auth.init();\n this.ws = makeWASocket({\n auth,\n browser: [os.platform(), \"Firefox\", os.release()],\n logger: this.logger.child({ name: `WASocket ${this.uuid} ` }),\n qrTimeout: 60_000,\n markOnlineOnConnect: true,\n syncFullHistory: false,\n shouldSyncHistoryMessage: () => (false),\n generateHighQualityLinkPreview: true,\n linkPreviewImageThumbnailWidth: 1_980,\n shouldIgnoreJid: (jid) => {\n if (!isGroup(jid) && !isPn(jid) && !isLid(jid)) {\n return true;\n }\n return false;\n },\n cachedGroupMetadata: async (jid) => {\n return groups.get(jid);\n },\n version: [2, 3_000, 1_027_934_701],\n });\n this.ws.ev.on(\"creds.update\", async () => {\n try {\n await this.auth.save();\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n this.ws.ev.on(\"connection.update\", async (update) => {\n try {\n if (update.qr) {\n if (method === \"otp\") {\n if (!isPn(this.account.pn)) {\n await this.disconnect(new Boom(\"The OTP code cannot be generated because a number was not provided.\", { statusCode: 400 }));\n return;\n }\n const otp = await this.ws?.requestPairingCode(decode(this.account.pn).jid);\n if (!otp) {\n await this.disconnect(new Boom(`An OTP code could not be generated for '@${decode(this.account.pn).jid}'`, { statusCode: 400 }));\n return;\n }\n this.emit(\"otp\", otp);\n }\n else {\n this.emit(\"qr\", update.qr);\n }\n }\n if (update.connection === \"close\") {\n this.ws?.ev.removeAllListeners(undefined as unknown as keyof BaileysEventMap);\n const output = new Boom(update.lastDisconnect?.error).output;\n this.emit(\"close\", `${output.payload.error} ${output.payload.statusCode}: ${output.payload.message}`);\n switch (output.payload.statusCode) {\n case 400:\n case 401:\n case 403:\n case 404:\n case 405: {\n await this.auth.remove();\n this.ws = null;\n this.removeAllListeners();\n this.status = \"close\";\n break;\n }\n case 503: {\n await new Promise((resolve) => (setTimeout(resolve, 30_000)));\n this.status = \"reconnecting\";\n await this.login(method);\n break;\n }\n case 515: {\n this.status = \"reconnecting\";\n await this.login(method);\n break;\n }\n default: {\n if (update.lastDisconnect?.error?.message === \"Intentional disconnection.\") {\n this.ws = null;\n this.removeAllListeners();\n this.status = \"close\";\n break;\n }\n await new Promise((resolve) => (setTimeout(resolve, 5_000)));\n this.status = \"reconnecting\";\n await this.login(method);\n }\n }\n return;\n }\n else if (update.connection === \"open\") {\n const jid = normalize(this.ws?.user?.lid);\n const pn = normalize(this.ws?.user?.id);\n const name = this.ws?.user?.verifiedName ?? this.ws?.user?.name ?? \"\";\n if (!isPn(pn) || !isLid(jid)) {\n await this.disconnect(new Boom(\"Restart required.\", { statusCode: 515 }));\n return;\n }\n this.account = { jid, pn, name };\n contacts.set(jid, { jid, pn, name });\n this.status = \"open\";\n this.emit(\"open\", this.account);\n return;\n }\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n this.ws.ev.on(\"messages.upsert\", async (upsert) => {\n try {\n if (upsert.type !== \"notify\" || !upsert.messages.length) {\n return;\n }\n for (const message of upsert.messages) {\n const ctx = new Context(this, message);\n if (isGroup(ctx.chat.jid)) {\n if (!groups.has(ctx.chat.jid)) {\n const metadata = await this.groupMetadata(ctx.chat.jid);\n if (metadata) {\n groups.set(ctx.chat.jid, metadata);\n }\n }\n }\n if (isLid(ctx.from.jid) && isPn(ctx.from.pn)) {\n contacts.set(ctx.from.jid, { jid: ctx.from.jid, pn: ctx.from.pn, name: ctx.from.name });\n }\n const middlewares = [\n ...this.middlewares,\n ...(this.commands.get(ctx.commandName) ?? []),\n ];\n if (middlewares.length) {\n let index = -1;\n const runner = async (i: number): Promise<void> => {\n if (i <= index) {\n throw new Error(\"next() called multiple times.\");\n }\n index = i;\n const fn = middlewares[i];\n if (!fn) {\n return;\n }\n await fn(ctx, async () => {\n await runner(i + 1);\n });\n };\n await runner(0);\n }\n }\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n this.ws.ev.on(\"contacts.update\", (updates) => {\n try {\n for (const update of updates) {\n if (!isLid(update.id) || !contacts.has(update.id)) {\n continue;\n }\n const name = update.verifiedName ?? update.notify;\n const contact = contacts.get(update.id)!;\n if (name && contact.name !== name) {\n contact.name = name;\n }\n }\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n this.ws.ev.on(\"groups.update\", async (updates) => {\n try {\n for (const update of updates) {\n if (!isGroup(update.id)) {\n continue;\n }\n groups.delete(update.id);\n const metadata = await this.groupMetadata(update.id);\n if (metadata) {\n groups.set(update.id, metadata);\n }\n }\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n });\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n }\n public async disconnect(reason?: Error): Promise<void> {\n try {\n reason ??= new Error(\"Intentional disconnection.\");\n this.ws?.end(reason);\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n }\n public async logout(reason?: Boom): Promise<void> {\n try {\n await this.ws?.logout(reason?.message);\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n }\n }\n public parseMentions(text: string, server: JidServer): string[] {\n try {\n const mentions = new Set<string>();\n for (const match of text.matchAll(/@(\\d{7,})/g)) {\n if (!match[1]) {\n continue;\n }\n mentions.add(`${match[1]}@${server}`);\n }\n return Array.from(mentions.values());\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return [];\n }\n }\n public parseLinks(text: string): string[] {\n try {\n const links = new Set<string>();\n const html = Autolinker.link(text, {\n urls: {\n schemeMatches: true,\n ipV4Matches: false,\n tldMatches: true,\n },\n email: true,\n phone: true,\n mention: false,\n hashtag: false,\n stripPrefix: false,\n stripTrailingSlash: false,\n });\n const $ = load(html);\n $(\"a\").each((_, el) => {\n const link = $(el).attr(\"href\");\n if (!link) {\n return;\n }\n links.add(link);\n });\n return Array.from(links.values());\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return [];\n }\n }\n public async sendMessage(jid: string, content: AnyMessageContent, options?: IBotSendMessageOptions): Promise<Context | null> {\n try {\n if (!this.ws?.ws.isOpen) {\n throw new Error(\"The WASocket connection is not open.\");\n }\n const before = performance.now();\n const text = \"text\" in content && content.text ? content.text : \"caption\" in content && content.caption ? content.caption : \"\";\n const mentions = this.parseMentions(text, options?.addressing === \"lid\" ? \"lid\" : \"s.whatsapp.net\");\n const message = await this.ws.sendMessage(jid, {\n ...content,\n mentions: \"mentions\" in content && content.mentions ? content.mentions.concat(...mentions) : mentions,\n }, options);\n if (!message) {\n return null;\n }\n const after = performance.now();\n this.ping = after - before;\n return new Context(this, message);\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return null;\n }\n }\n public async groupMetadata(jid: string): Promise<GroupMetadata | null> {\n try {\n if (!this.ws?.ws.isOpen) {\n throw new Error(\"The WASocket connection is not open.\");\n }\n return groups.get(jid) ?? await this.ws.groupMetadata(jid);\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return null;\n }\n }\n public async profilePictureUrl(jid: string): Promise<string> {\n try {\n if (!this.ws?.ws.isOpen) {\n throw new Error(\"The WASocket connection is not open.\");\n }\n return await this.ws.profilePictureUrl(jid, \"image\") ?? \"https://i.pinimg.com/736x/62/01/0d/62010d848b790a2336d1542fcda51789.jpg\";\n }\n catch (e) {\n this.emit(\"error\", toError(e));\n return \"https://i.pinimg.com/736x/62/01/0d/62010d848b790a2336d1542fcda51789.jpg\";\n }\n }\n}"],
5
+ "mappings": "AAAA,OAAOA,MAAY,iBAEnB,OAAOC,MAAkB,cACzB,OAAS,QAAAC,MAAY,aAErB,OAA0B,gBAAAC,MAAgF,UAC1G,OAAS,WAAAC,MAAe,uBACxB,OAAS,UAAAC,EAAQ,WAAAC,EAAS,SAAAC,EAAO,QAAAC,EAAM,aAAAC,EAAW,WAAAC,MAAe,oBACjE,OAAOC,MAAQ,UACf,OAAS,YAAAC,EAAU,UAAAC,MAAc,oBACjC,OAAS,cAAAC,MAAkB,aAC3B,OAAS,QAAAC,MAAY,UAEd,MAAMC,UAAYf,CAA2B,CAC3C,K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3D,GAAI,CACF,GAAI,CAAC,KAAK,IAAI,GAAG,OACf,MAAM,IAAI,MAAM,sCAAsC,EAExD,OAAO,MAAM,KAAK,GAAG,kBAAkBA,EAAK,OAAO,GAAK,yEAC1D,OACOM,EAAG,CACR,YAAK,KAAK,QAASpB,EAAQoB,CAAC,CAAC,EACtB,yEACT,CACF,CACF",
6
+ "names": ["Logger", "EventEmitter", "Boom", "makeWASocket", "Context", "decode", "isGroup", "isLid", "isPn", "normalize", "toError", "os", "contacts", "groups", "Autolinker", "load", "Bot", "uuid", "auth", "account", "logger", "middlewares", "name", "method", "jid", "update", "otp", "output", "resolve", "pn", "e", "upsert", "message", "ctx", "metadata", "index", "runner", "i", "fn", "updates", "contact", "reason", "text", "server", "mentions", "match", "links", "html", "$", "_", "el", "link", "content", "options", "before", "after"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imjxsx/wapi",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Framework for developing bots for the WhatsApp application: fast, secure, and elegant, powered by Baileys and developed 100% in TypeScript.",
5
5
  "license": "MIT",
6
6
  "type": "module",