[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",
"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",

View File

@@ -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 });

78
update
View File

@@ -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,66 +120,61 @@ 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"
log "download_file(url=$url, dest=$dest)"
log "INFO" "Baixando: $url → $dest"
log "Baixando $url"
log "Destino: $dest"
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"
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 "curl ou wget não encontrados"
log "ERROR" "Nenhum downloader encontrado (curl ou wget são necessários)."
exit 1
fi
chmod +x "$dest" 2>/dev/null || true
log "Arquivo pronto: $dest"
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"
log "INFO" "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"
"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"
log "INFO" "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"
"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"
)
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
url="${file%% *}"
dest="${file##* }"
log "Processando dependência"
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