[fix] tirando o bot_prefix e melhorando o script de update

This commit is contained in:
synt-xerror
2026-03-24 01:35:55 -03:00
parent 95767ee0d5
commit 05f521d78b
3 changed files with 59 additions and 53 deletions

4
package-lock.json generated
View File

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

View File

@@ -13,7 +13,7 @@
* Cada plugin decide por conta própria se age ou ignora. * 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 { 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";
@@ -29,7 +29,7 @@ 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, BOT_PREFIX); const ctx = await buildMessageContext(msg, chat);
logger.msg(ctx); logger.msg(ctx);
const api = buildApi({ msg, chat, client, pluginRegistry }); const api = buildApi({ msg, chat, client, pluginRegistry });

104
update
View File

@@ -11,8 +11,18 @@ set -euo pipefail
dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
tmp_dir="$dir/tmp" tmp_dir="$dir/tmp"
log_file="$dir/update.log" log_file="$dir/update.log"
bin_dir="$dir/bin"
config_items=(".wwebjs_auth" ".wwebjs_cache" "node_modules") 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 # Logging
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -32,7 +42,7 @@ cleanup_on_error() {
log "ERROR" "Falha durante a atualização (código: $exit_code)." log "ERROR" "Falha durante a atualização (código: $exit_code)."
if [ -d "$tmp_dir" ] && [ "$(ls -A "$tmp_dir" 2>/dev/null)" ]; then if [ -d "$tmp_dir" ] && [ "$(ls -A "$tmp_dir" 2>/dev/null)" ]; then
log "WARN" "Arquivos de configuração preservados em: $tmp_dir" 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 fi
exit $exit_code exit $exit_code
} }
@@ -42,6 +52,7 @@ trap cleanup_on_error ERR
# Validações iniciais # Validações iniciais
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
log "INFO" "Iniciando atualização do ManyBot..." log "INFO" "Iniciando atualização do ManyBot..."
log "INFO" "Plataforma detectada: $PLATFORM"
# Verifica dependências obrigatórias # Verifica dependências obrigatórias
for cmd in git npm; do for cmd in git npm; do
@@ -109,67 +120,62 @@ else
fi 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" 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() { download_file() {
local url="$1" local url="$1"
local dest="$2" local dest="$2"
log "download_file(url=$url, dest=$dest)" log "INFO" "Baixando: $url → $dest"
log "Baixando $url" if command -v curl &>/dev/null; then
log "Destino: $dest" 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 chmod +x "$dest" 2>/dev/null || true
log "Downloader: curl" log "INFO" "Arquivo pronto: $dest"
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"
} }
# ------------------------ log "INFO" "Selecionando binários para plataforma: $PLATFORM"
# Arquivos por plataforma
# ------------------------
log "Selecionando dependências binárias"
files=()
if [[ "$PLATFORM" == "win" ]]; then if [[ "$PLATFORM" == "win" ]]; then
log "Usando binários Windows" log "INFO" "Usando binários Windows"
files=( 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/yt-dlp.exe $bin_dir/yt-dlp.exe"
"https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg.exe bin/ffmpeg.exe" "https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg.exe $bin_dir/ffmpeg.exe"
) )
else else
log "Usando binários Unix" log "INFO" "Usando binários Unix"
files=( files=(
"https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp bin/yt-dlp" "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/ffmpeg" "https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg $bin_dir/ffmpeg"
) )
log "Total de arquivos para baixar: ${#files[@]}" fi # <-- fi que estava faltando no original
log "INFO" "Total de arquivos para baixar: ${#files[@]}"
# ------------------------
# Download
# ------------------------
for file in "${files[@]}"; do for file in "${files[@]}"; do
url="${file%% *}" url="${file%% *}"
dest="${file##* }" dest="${file##* }"
download_file "$url" "$dest"
log "Processando dependência"
download_file "$url" "$dest"
done done
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -183,7 +189,7 @@ if [ ${#backed_up[@]} -gt 0 ]; then
# Remove o que npm possa ter criado (ex: node_modules) # Remove o que npm possa ter criado (ex: node_modules)
rm -rf "$dst" rm -rf "$dst"
mv "$src" "$dst" mv "$src" "$dst"
l"INFO" "Restaurado: $item" log "INFO" "Restaurado: $item"
else else
log "WARN" "Item esperado no backup não encontrado: $item" log "WARN" "Item esperado no backup não encontrado: $item"
fi fi