From 05f521d78b83cfcf72a48b3ec473a800701bc6c4 Mon Sep 17 00:00:00 2001 From: synt-xerror <169557594+synt-xerror@users.noreply.github.com> Date: Tue, 24 Mar 2026 01:35:55 -0300 Subject: [PATCH] [fix] tirando o bot_prefix e melhorando o script de update --- package-lock.json | 4 +- src/kernel/messageHandler.js | 4 +- update | 104 ++++++++++++++++++----------------- 3 files changed, 59 insertions(+), 53 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1ee225a..9b91d61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "manybot", - "version": "2.4.2", + "version": "2.4.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "manybot", - "version": "2.4.2", + "version": "2.4.3", "dependencies": { "node-addon-api": "^7", "node-gyp": "^12.2.0", diff --git a/src/kernel/messageHandler.js b/src/kernel/messageHandler.js index 8961711..705945b 100644 --- a/src/kernel/messageHandler.js +++ b/src/kernel/messageHandler.js @@ -13,7 +13,7 @@ * Cada plugin decide por conta própria se age ou ignora. */ -import { CHATS, BOT_PREFIX } from "../config.js"; +import { CHATS } from "../config.js"; import { getChatId } from "../utils/getChatId.js"; import { buildApi } from "./pluginApi.js"; import { pluginRegistry } from "./pluginLoader.js"; @@ -29,7 +29,7 @@ export async function handleMessage(msg) { // CHATS vazio = aceita todos os chats if (CHATS.length > 0 && !CHATS.includes(chatId)) return; - const ctx = await buildMessageContext(msg, chat, BOT_PREFIX); + const ctx = await buildMessageContext(msg, chat); logger.msg(ctx); const api = buildApi({ msg, chat, client, pluginRegistry }); diff --git a/update b/update index 60bbcc8..b38ada7 100644 --- a/update +++ b/update @@ -11,8 +11,18 @@ set -euo pipefail dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" tmp_dir="$dir/tmp" log_file="$dir/update.log" +bin_dir="$dir/bin" config_items=(".wwebjs_auth" ".wwebjs_cache" "node_modules") +# Detecta plataforma automaticamente se PLATFORM não estiver definido +: "${PLATFORM:=}" +if [[ -z "$PLATFORM" ]]; then + case "$(uname -s)" in + MINGW*|CYGWIN*|MSYS*) PLATFORM="win" ;; + *) PLATFORM="unix" ;; + esac +fi + # ------------------------------------------------------------------------------ # Logging # ------------------------------------------------------------------------------ @@ -32,7 +42,7 @@ cleanup_on_error() { log "ERROR" "Falha durante a atualização (código: $exit_code)." if [ -d "$tmp_dir" ] && [ "$(ls -A "$tmp_dir" 2>/dev/null)" ]; then log "WARN" "Arquivos de configuração preservados em: $tmp_dir" - log "WARN" "Restaure manualmente com: mv $tmp_dir/* $dir/" + log "WARN" "Restaure manualmente com: mv \"$tmp_dir\"/* \"$dir\"/" fi exit $exit_code } @@ -42,6 +52,7 @@ trap cleanup_on_error ERR # Validações iniciais # ------------------------------------------------------------------------------ log "INFO" "Iniciando atualização do ManyBot..." +log "INFO" "Plataforma detectada: $PLATFORM" # Verifica dependências obrigatórias for cmd in git npm; do @@ -109,67 +120,62 @@ else fi # ------------------------------------------------------------------------------ -# Instalação de dependências +# Instalação de dependências Node # ------------------------------------------------------------------------------ -log "INFO" "Instalando dependências..." +log "INFO" "Instalando dependências Node..." npm ci --omit=dev 2>&1 | tee -a "$log_file" -# ------------------------ -# Download -# ------------------------ +# ------------------------------------------------------------------------------ +# Download de binários por plataforma +# ------------------------------------------------------------------------------ + +# Cria o diretório de binários se não existir +mkdir -p "$bin_dir" + +# Função de download com fallback curl → wget download_file() { - local url="$1" - local dest="$2" + local url="$1" + local dest="$2" - log "download_file(url=$url, dest=$dest)" + log "INFO" "Baixando: $url → $dest" - log "Baixando $url" - log "Destino: $dest" + if command -v curl &>/dev/null; then + log "INFO" "Downloader: curl" + curl -fsSL "$url" -o "$dest" + elif command -v wget &>/dev/null; then + log "INFO" "Downloader: wget" + wget -q "$url" -O "$dest" + else + log "ERROR" "Nenhum downloader encontrado (curl ou wget são necessários)." + exit 1 + fi - if command -v curl >/dev/null 2>&1; then - log "Downloader: curl" - curl -L "$url" -o "$dest" - elif command -v wget >/dev/null 2>&1; then - log "Downloader: wget" - wget "$url" -O "$dest" - else - log "curl ou wget não encontrados" - exit 1 - fi - - chmod +x "$dest" 2>/dev/null || true - log "Arquivo pronto: $dest" + chmod +x "$dest" 2>/dev/null || true + log "INFO" "Arquivo pronto: $dest" } -# ------------------------ -# Arquivos por plataforma -# ------------------------ -log "Selecionando dependências binárias" +log "INFO" "Selecionando binários para plataforma: $PLATFORM" -files=() if [[ "$PLATFORM" == "win" ]]; then - log "Usando binários Windows" - files=( - "https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe bin/yt-dlp.exe" - "https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg.exe bin/ffmpeg.exe" - ) + log "INFO" "Usando binários Windows" + files=( + "https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe $bin_dir/yt-dlp.exe" + "https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg.exe $bin_dir/ffmpeg.exe" + ) else - log "Usando binários Unix" - files=( - "https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp bin/yt-dlp" - "https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg bin/ffmpeg" - ) -log "Total de arquivos para baixar: ${#files[@]}" + log "INFO" "Usando binários Unix" + files=( + "https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp $bin_dir/yt-dlp" + "https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg $bin_dir/ffmpeg" + ) +fi # <-- fi que estava faltando no original + +log "INFO" "Total de arquivos para baixar: ${#files[@]}" -# ------------------------ -# Download -# ------------------------ for file in "${files[@]}"; do - url="${file%% *}" - dest="${file##* }" - - log "Processando dependência" - download_file "$url" "$dest" + url="${file%% *}" + dest="${file##* }" + download_file "$url" "$dest" done # ------------------------------------------------------------------------------ @@ -183,7 +189,7 @@ if [ ${#backed_up[@]} -gt 0 ]; then # Remove o que npm possa ter criado (ex: node_modules) rm -rf "$dst" mv "$src" "$dst" - l"INFO" "Restaurado: $item" + log "INFO" "Restaurado: $item" else log "WARN" "Item esperado no backup não encontrado: $item" fi