Last active
July 22, 2025 20:06
-
-
Save weskerty/6a5fda1160e4a4d963603137bc6e4ff5 to your computer and use it in GitHub Desktop.
MultiAccounts on Same Server LyFeLevanter Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // yobot.js - Plugin para agregar sesiones al config.json | |
| // Debes Agregar un nuevo id propio primero, ya que el anterior sera reemplazado. | |
| // Weskerty | |
| const fs = require('fs').promises; | |
| const path = require('path'); | |
| const { bot, lang, sleep } = require('../lib'); | |
| const { restartInstance } = require('../lib/pm2'); | |
| const defaultSessionConfig = { | |
| "PREFIX": "^[.,!]", | |
| "SUDO": "0", | |
| "STICKER_PACKNAME": "❤️,LyFE", | |
| "ALWAYS_ONLINE": "false", | |
| "RMBG_KEY": "null", | |
| "WARN_LIMIT": "3", | |
| "FORCE_LOGOUT": "false", | |
| "DISABLE_BOT": "null", | |
| "ANTILINK_MSG": "_Antilink Detected &mention kicked_", | |
| "ANTISPAM_MSG": "_Antispam Detected &mention kicked_", | |
| "ANTIWORDS_MSG": "_AntiWord Detected &mention kicked_", | |
| "ANTIWORDS": "word", | |
| "REJECT_CALL": "false", | |
| "AUTO_STATUS_VIEW": "false", | |
| "SEND_READ": "false", | |
| "AJOIN": "false", | |
| "GPT": "free", | |
| "MODEL": "gpt-3.5-turbo", | |
| "ANTI_DELETE": "null", | |
| "PERSONAL_MESSAGE": "null", | |
| "DISABLE_START_MESSAGE": "false", | |
| "WARN_MESSAGE": "⚠️WARNING⚠️\n*User :* &mention\n*Warn :* &warn\n*Remaining :* &remaining", | |
| "WARN_RESET_MESSAGE": "WARN RESET\nUser : &mention\nRemaining : &remaining\nWARN_KICK_MESSAGE=&mention kicked", | |
| "WARN_KICK_MESSAGE": "&mention kicked", | |
| "DELETE_TYPE": "all", | |
| "LIST_TYPE": "text", | |
| "BING_COOKIE": "", | |
| "GEMINI_API_KEY": "", | |
| "GROUP_ADMINS": "", | |
| "CMD_REACTION": "true" | |
| }; | |
| class SessionManager { | |
| constructor() { | |
| this.configPath = path.join(process.cwd(), 'config.json'); | |
| this.dbPath = path.join(process.cwd(), 'database.db'); | |
| } | |
| async checkAndDeleteDatabase() { | |
| try { | |
| await fs.access(this.configPath); | |
| } catch (configError) { | |
| if (configError.code === 'ENOENT') { | |
| try { | |
| await fs.access(this.dbPath); | |
| await fs.unlink(this.dbPath); | |
| console.log('Database.db eliminado'); | |
| } catch (dbError) { | |
| if (dbError.code !== 'ENOENT') { | |
| console.error('YOBOT-PLUGIN Error eliminando database:', dbError); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| async loadConfig() { | |
| try { | |
| const configData = await fs.readFile(this.configPath, 'utf8'); | |
| return JSON.parse(configData); | |
| } catch (error) { | |
| if (error.code === 'ENOENT') { | |
| return {}; | |
| } | |
| throw error; | |
| } | |
| } | |
| async saveConfig(config) { | |
| await fs.writeFile(this.configPath, JSON.stringify(config, null, 2), 'utf8'); | |
| } | |
| getNextSessionNumber(config) { | |
| const sessionKeys = Object.keys(config).filter(key => key.startsWith('session')); | |
| if (sessionKeys.length === 0) return 1; | |
| const sessionNumbers = sessionKeys.map(key => { | |
| const match = key.match(/session(\d+)/); | |
| return match ? parseInt(match[1], 10) : 0; | |
| }); | |
| return Math.max(...sessionNumbers) + 1; | |
| } | |
| async addSession(sessionId) { | |
| try { | |
| await this.checkAndDeleteDatabase(); | |
| const config = await this.loadConfig(); | |
| if (!sessionId.toLowerCase().includes('levanter')) { | |
| return { | |
| success: false, | |
| error: 'INVALID_SESSION_FORMAT' | |
| }; | |
| } | |
| const nextSessionNumber = this.getNextSessionNumber(config); | |
| const sessionKey = `session${nextSessionNumber}`; | |
| config[sessionKey] = { | |
| SESSION_ID: sessionId, | |
| ...defaultSessionConfig | |
| }; | |
| await this.saveConfig(config); | |
| return { | |
| success: true, | |
| sessionKey, | |
| sessionNumber: nextSessionNumber, | |
| needsRestart: true | |
| }; | |
| } catch (error) { | |
| console.error(`YOBOT-PLUGIN Error adding session: ${error.message}`); | |
| return { | |
| success: false, | |
| error: error.message | |
| }; | |
| } | |
| } | |
| async deleteSession(sessionIdentifier) { | |
| try { | |
| const config = await this.loadConfig(); | |
| let sessionKey = sessionIdentifier; | |
| if (/^\d+$/.test(sessionIdentifier)) { | |
| sessionKey = `session${sessionIdentifier}`; | |
| } | |
| if (config[sessionKey]) { | |
| delete config[sessionKey]; | |
| await this.saveConfig(config); | |
| return { | |
| success: true, | |
| sessionKey | |
| }; | |
| } else { | |
| return { | |
| success: false, | |
| error: `Sesión ${sessionKey} no encontrada` | |
| }; | |
| } | |
| } catch (error) { | |
| console.error(`YOBOT-PLUGIN Error deleting session: ${error.message}`); | |
| return { | |
| success: false, | |
| error: error.message | |
| }; | |
| } | |
| } | |
| } | |
| const sessionManager = new SessionManager(); | |
| bot( | |
| { | |
| pattern: 'yobot ?(.*)', | |
| fromMe: true, | |
| desc: 'Gestor de sesiones', | |
| type: 'config', | |
| }, | |
| async (message, match) => { | |
| const input = match.trim(); | |
| if (!input) { | |
| await message.send( | |
| '> 🗝️ *Gestor de Sesiones*\n' + | |
| 'Agregar nueva sesión:\n`yobot` <sessionId>\n' + | |
| 'Eliminar sesión:\n`yobot del` <número/clave>\n' + | |
| '⚠️ *Recuerda LEER el Tutorial:*\n> \n' + | |
| 'Conseguir SesionID: \nlevanter-delta.vercel.app/', | |
| { quoted: message.data } | |
| ); | |
| return; | |
| } | |
| if (input.startsWith('del ')) { | |
| const sessionIdentifier = input.substring(4).trim(); | |
| if (!sessionIdentifier) { | |
| await message.send('Especifica la sesión a eliminar. Ejemplo: `.yobot del 3`'); | |
| return; | |
| } | |
| const result = await sessionManager.deleteSession(sessionIdentifier); | |
| if (result.success) { | |
| await message.send(`✅ Sesión *${result.sessionKey}* eliminada`); | |
| } else { | |
| await message.send(`❌ Error: ${result.error}`); | |
| } | |
| return; | |
| } | |
| const sessionId = input; | |
| if (!sessionId.toLowerCase().includes('levanter')) { | |
| await message.send( | |
| "🔒 Formato incorrecto\n" + | |
| "⚠️ *Recuerda LEER el Tutorial:*\n> :", | |
| { quoted: message.data } | |
| ); | |
| return; | |
| } | |
| try { | |
| const result = await sessionManager.addSession(sessionId); | |
| if (result.success) { | |
| await message.send( | |
| `✅ *Sesión agregada!*\n` + | |
| `📝 Clave: \n> ${result.sessionKey}\n` + | |
| `🔑 Session ID: \n> ${sessionId}\n` + | |
| `⚠️ *Recuerda LEER el Tutorial:*\n> \n` + | |
| `‼️ *EL BOT SE REINICIARA AHORA* ‼️`, | |
| { quoted: message.data } | |
| ); | |
| if (result.needsRestart) { | |
| await sleep(000); | |
| restartInstance(); | |
| } | |
| } else { | |
| if (result.error === 'INVALID_SESSION_FORMAT') { | |
| await message.send( | |
| "🔒 Formato incorrecto\n" + | |
| "⚠️ *Recuerda LEER el Tutorial:*\n> ", | |
| { quoted: message.data } | |
| ); | |
| } else { | |
| await message.send( | |
| `❌ Error: ${result.error}`, | |
| { quoted: message.data } | |
| ); | |
| } | |
| } | |
| } catch (error) { | |
| console.error(`YOBOT-PLUGIN Error: ${error.message}`); | |
| await message.send( | |
| `❌ Error: ${error.message}`, | |
| { quoted: message.data } | |
| ); | |
| } | |
| } | |
| ); | |
| module.exports = { sessionManager }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment