2 Commits
2.4.2 ... 2.4.3

Author SHA1 Message Date
synt-xerror
45323b2d3d [fix] corrige sendTo passando client explicitamente para a pluginApi 2026-03-24 01:26:46 -03:00
synt-xerror
58f5e13eb3 Bump version to 2.4.2 2026-03-24 01:26:43 -03:00
4 changed files with 75 additions and 22 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "manybot", "name": "manybot",
"version": "2.4.1", "version": "2.4.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "manybot", "name": "manybot",
"version": "2.4.1", "version": "2.4.2",
"dependencies": { "dependencies": {
"node-addon-api": "^7", "node-addon-api": "^7",
"node-gyp": "^12.2.0", "node-gyp": "^12.2.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "manybot", "name": "manybot",
"version": "2.4.1", "version": "2.4.2",
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"node-addon-api": "^7", "node-addon-api": "^7",

View File

@@ -5,6 +5,7 @@
* *
* Ordem: * Ordem:
* 1. Filtra chats não permitidos (CHATS do .conf) * 1. Filtra chats não permitidos (CHATS do .conf)
* — se CHATS estiver vazio, aceita todos os chats
* 2. Loga a mensagem * 2. Loga a mensagem
* 3. Passa o contexto para todos os plugins ativos * 3. Passa o contexto para todos os plugins ativos
* *
@@ -12,17 +13,15 @@
* Cada plugin decide por conta própria se age ou ignora. * Cada plugin decide por conta própria se age ou ignora.
*/ */
import { CHATS } from "../config.js"; import { CHATS, BOT_PREFIX } from "../config.js";
import { getChatId } from "../utils/getChatId.js"; import { getChatId } from "../utils/getChatId.js";
import { buildApi } from "./pluginApi.js"; import { buildApi } from "./pluginApi.js";
import { pluginRegistry } from "./pluginLoader.js"; import { pluginRegistry } from "./pluginLoader.js";
import { runPlugin } from "./pluginGuard.js"; import { runPlugin } from "./pluginGuard.js";
import { buildMessageContext } from "../logger/messageContext.js"; import { buildMessageContext } from "../logger/messageContext.js";
import { logger } from "../logger/logger.js"; import { logger } from "../logger/logger.js";
import client from "../client/whatsappClient.js";
/**
* @param {import("whatsapp-web.js").Message} msg
*/
export async function handleMessage(msg) { export async function handleMessage(msg) {
const chat = await msg.getChat(); const chat = await msg.getChat();
const chatId = getChatId(chat); const chatId = getChatId(chat);
@@ -30,10 +29,10 @@ export async function handleMessage(msg) {
// CHATS vazio = aceita todos os chats // CHATS vazio = aceita todos os chats
if (CHATS.length > 0 && !CHATS.includes(chatId)) return; if (CHATS.length > 0 && !CHATS.includes(chatId)) return;
const ctx = await buildMessageContext(msg, chat); const ctx = await buildMessageContext(msg, chat, BOT_PREFIX);
logger.msg(ctx); logger.msg(ctx);
const api = buildApi({ msg, chat, pluginRegistry }); const api = buildApi({ msg, chat, client, pluginRegistry });
const context = { msg: api.msg, chat: api.chat, api }; const context = { msg: api.msg, chat: api.chat, api };
for (const plugin of pluginRegistry.values()) { for (const plugin of pluginRegistry.values()) {

View File

@@ -20,9 +20,8 @@ const { MessageMedia } = pkg;
* @param {Map<string, any>} params.pluginRegistry * @param {Map<string, any>} params.pluginRegistry
* @returns {object} api * @returns {object} api
*/ */
export function buildApi({ msg, chat, pluginRegistry }) { export function buildApi({ msg, chat, client, pluginRegistry }) {
// ── Helpers internos ──────────────────────────────────────
const currentChat = chat; const currentChat = chat;
return { return {
@@ -155,6 +154,61 @@ export function buildApi({ msg, chat, pluginRegistry }) {
return currentChat.sendMessage(media, { sendMediaAsSticker: true }); return currentChat.sendMessage(media, { sendMediaAsSticker: true });
}, },
// ── Envio para chat específico ───────────────────────────
/**
* Envia texto para um chat específico por ID.
* @param {string} chatId
* @param {string} text
*/
async sendTo(chatId, text) {
return client.sendMessage(chatId, text);
},
/**
* Envia vídeo para um chat específico por ID.
* @param {string} chatId
* @param {string} filePath
* @param {string} [caption]
*/
async sendVideoTo(chatId, filePath, caption = "") {
const media = MessageMedia.fromFilePath(filePath);
return client.sendMessage(chatId, media, { caption });
},
/**
* Envia áudio para um chat específico por ID.
* @param {string} chatId
* @param {string} filePath
*/
async sendAudioTo(chatId, filePath) {
const media = MessageMedia.fromFilePath(filePath);
return client.sendMessage(chatId, media, { sendAudioAsVoice: true });
},
/**
* Envia imagem para um chat específico por ID.
* @param {string} chatId
* @param {string} filePath
* @param {string} [caption]
*/
async sendImageTo(chatId, filePath, caption = "") {
const media = MessageMedia.fromFilePath(filePath);
return client.sendMessage(chatId, media, { caption });
},
/**
* Envia figurinha para um chat específico por ID.
* @param {string} chatId
* @param {string | Buffer} source
*/
async sendStickerTo(chatId, source) {
const media = typeof source === "string"
? MessageMedia.fromFilePath(source)
: new MessageMedia("image/webp", source.toString("base64"));
return client.sendMessage(chatId, media, { sendMediaAsSticker: true });
},
// ── Acesso a outros plugins ────────────────────────────── // ── Acesso a outros plugins ──────────────────────────────
/** /**