[fix] tirando o bot_prefix e melhorando o script de update
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -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",
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|||||||
78
update
78
update
@@ -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,66 +120,61 @@ 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"
|
||||||
if command -v curl >/dev/null 2>&1; then
|
elif command -v wget &>/dev/null; then
|
||||||
log "Downloader: curl"
|
log "INFO" "Downloader: wget"
|
||||||
curl -L "$url" -o "$dest"
|
wget -q "$url" -O "$dest"
|
||||||
elif command -v wget >/dev/null 2>&1; then
|
|
||||||
log "Downloader: wget"
|
|
||||||
wget "$url" -O "$dest"
|
|
||||||
else
|
else
|
||||||
log "curl ou wget não encontrados"
|
log "ERROR" "Nenhum downloader encontrado (curl ou wget são necessários)."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod +x "$dest" 2>/dev/null || true
|
chmod +x "$dest" 2>/dev/null || true
|
||||||
log "Arquivo pronto: $dest"
|
log "INFO" "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##* }"
|
||||||
|
|
||||||
log "Processando dependência"
|
|
||||||
download_file "$url" "$dest"
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user