-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #295 from weskerty/master
Nuevos Plugins (Aun sin Testear) y Repertorio de Plugins
- Loading branch information
Showing
21 changed files
with
664 additions
and
151 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Custom | ||
|
||
web | ||
MysticSession | ||
jadibts | ||
pluginpilot | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ | |
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>The Mystic Bot🔮</title> | ||
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:[email protected]&display=swap" rel="stylesheet"> | ||
<title>Mystic Bot 🔮</title> | ||
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:[email protected]&display=swap" rel="stylesheet"> | ||
<link rel="icon" type="image/x-icon" href="web/favicon.ico"> | ||
<link rel="stylesheet" href="web/estilo.css"> | ||
<style> | ||
/* Estilo de Carga*/ | ||
/* Estilo de la pantalla de carga */ | ||
.loading-screen { | ||
position: fixed; | ||
top: 0; | ||
|
@@ -27,7 +27,7 @@ | |
font-family: 'Comfortaa', sans-serif; | ||
} | ||
|
||
/* Ocultar el Cargando cuando Cargo gg */ | ||
/* Clase para ocultar elementos */ | ||
.hide { | ||
display: none; | ||
} | ||
|
@@ -39,41 +39,38 @@ | |
</div> | ||
|
||
<video autoplay muted loop id="bg-video" preload="auto"> | ||
<source src="https://github.com/user-attachments/assets/39cbf647-28cd-4604-a717-ada1439d274b" type="video/mp4"> | ||
Er Video | ||
<source src="https://videos.pexels.com/video-files/7180356/7180356-hd_1366_720_25fps.mp4" type="video/mp4"> | ||
Error al cargar el video | ||
</video> | ||
|
||
<div class="content" id="content"> | ||
<p>⌛Cargando⏳</p> | ||
</div> | ||
|
||
<script> | ||
|
||
// Oculta la pantalla de carga | ||
function hideLoadingScreen() { | ||
document.getElementById('loading-screen').classList.add('hide'); | ||
} | ||
|
||
|
||
// Carga el contenido de la URL proporcionada | ||
async function loadContent(url, fallbackUrl = null) { | ||
try { | ||
const response = await fetch(url); | ||
if (!response.ok) throw new Error(`Error fetching ${url}: ${response.statusText}`); | ||
document.getElementById('content').innerHTML = await response.text(); | ||
|
||
// Comentarios Disqus, PErsonalizable y Claramente Opcional. | ||
loadDisqus(); | ||
loadDisqus(); // Carga Disqus si el contenido se cargó correctamente | ||
} catch (error) { | ||
console.error(`Error cargando D: ${error.message}`); | ||
console.error(`Error cargando contenido: ${error.message}`); | ||
if (fallbackUrl) { | ||
console.log(`Usando fallback URL: ${fallbackUrl}`); | ||
loadContent(fallbackUrl); | ||
loadContent(fallbackUrl); // Intenta cargar el fallback si hay error | ||
} else { | ||
document.getElementById('content').innerHTML = `<p>Error Cargando: ${error.message}</p>`; | ||
} | ||
} | ||
} | ||
|
||
|
||
// Carga Disqus para comentarios | ||
function loadDisqus() { | ||
const disqusDiv = document.createElement('div'); | ||
disqusDiv.id = 'disqus_thread'; | ||
|
@@ -84,17 +81,15 @@ | |
this.page.identifier = document.title; | ||
}; | ||
|
||
(function() { | ||
const d = document, s = d.createElement('script'); | ||
s.src = 'https://amigos-steam.disqus.com/embed.js'; | ||
s.setAttribute('data-timestamp', +new Date()); | ||
(d.head || d.body).appendChild(s); | ||
})(); | ||
const s = document.createElement('script'); | ||
s.src = 'https://amigos-steam.disqus.com/embed.js'; | ||
s.setAttribute('data-timestamp', +new Date()); | ||
document.body.appendChild(s); | ||
} | ||
|
||
|
||
// Devuelve la URL localizada según el idioma del navegador | ||
function getLocalizedUrl(urlBase) { | ||
const lang = navigator.language || navigator.userLanguage; | ||
const lang = navigator.language.slice(0, 2); // Obtener el código de idioma | ||
const langMap = { | ||
es: 'es.html', | ||
pt: 'pt.html', | ||
|
@@ -103,46 +98,52 @@ | |
ar: 'ar.html', | ||
hi: 'hi.html' | ||
}; | ||
return urlBase + (langMap[lang.slice(0, 2)] || 'ingles.html'); | ||
return `${urlBase}${langMap[lang] || 'ingles.html'}`; | ||
} | ||
|
||
|
||
// Carga el contenido localizado | ||
function loadLocalizedContent(urlBase) { | ||
const localizedUrl = getLocalizedUrl(urlBase); | ||
const fallbackUrl = `${urlBase}ingles.html`; | ||
loadContent(localizedUrl, fallbackUrl); | ||
} | ||
|
||
|
||
// Inicialización al cargar el DOM | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const bgVideo = document.getElementById('bg-video'); | ||
|
||
|
||
|
||
// Ocultar pantalla de carga después de 5 segundos | ||
const timeoutId = setTimeout(hideLoadingScreen, 5000); | ||
|
||
// Intentar cargar el contenido localizado inmediatamente | ||
loadLocalizedContent('web/'); | ||
|
||
// Ocultar la pantalla de carga cuando el video esté listo, si no se ha ocultado aún | ||
bgVideo.addEventListener('loadeddata', () => { | ||
loadLocalizedContent('web/'); | ||
hideLoadingScreen(); | ||
clearTimeout(timeoutId); // Cancelar el timeout si se ha cargado el video | ||
hideLoadingScreen(); // Ocultar la pantalla de carga | ||
}); | ||
}); | ||
|
||
|
||
// Manejo de clics en enlaces internos | ||
document.addEventListener('click', (event) => { | ||
const anchor = event.target.closest('a'); | ||
if (anchor && anchor.getAttribute('href')?.includes('web/')) { | ||
if (anchor && anchor.href.includes('web/')) { | ||
event.preventDefault(); | ||
window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
loadLocalizedContent(anchor.getAttribute('href').replace('.html', '')); | ||
loadLocalizedContent(anchor.href.replace('.html', '')); | ||
} | ||
}); | ||
|
||
|
||
// Recarga la página al cambiar el estado del historial | ||
window.onpopstate = () => location.reload(); | ||
</script> | ||
|
||
<!-- Widget de Discord --> | ||
<script src="https://cdn.jsdelivr.net/npm/@widgetbot/crate@3" async defer> | ||
new Crate({ | ||
server: '1278571215635877908', | ||
channel: '1286022420330840215' | ||
channel: '1280978443793727549' | ||
}); | ||
</script> | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import fetch from 'node-fetch'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const pluginsDir = path.join(__dirname, '../plugins'); | ||
const gitignorePath = path.join(__dirname, '../.gitignore'); | ||
|
||
// no es necesario verificar que exista lka carpeta plugins, ya que existe en mystic. pero puede ser util para otros bots | ||
const ensurePluginsDirExists = () => { | ||
if (!fs.existsSync(pluginsDir)) { | ||
fs.mkdirSync(pluginsDir, { recursive: true }); | ||
} | ||
}; | ||
|
||
const isValidUrl = (text) => { | ||
try { | ||
new URL(text); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
|
||
const readGitignore = async () => { | ||
if (fs.existsSync(gitignorePath)) { | ||
return await fs.promises.readFile(gitignorePath, 'utf-8'); | ||
} | ||
return ''; | ||
}; | ||
|
||
const writeGitignore = async (content) => { | ||
await fs.promises.writeFile(gitignorePath, content, 'utf-8'); | ||
}; | ||
|
||
const addToGitignore = async (pluginPath) => { | ||
try { | ||
const relativePluginPath = path.relative(path.join(__dirname, '../'), pluginPath); | ||
let gitignoreContent = await readGitignore(); | ||
|
||
if (!gitignoreContent.includes(relativePluginPath)) { | ||
gitignoreContent += `\n${relativePluginPath}\n`; | ||
await writeGitignore(gitignoreContent); | ||
console.log(`✅ ${relativePluginPath} añadido a .gitignore`); | ||
} | ||
} catch (error) { | ||
throw new Error(`Error al actualizar .gitignore: ${error.message}`); | ||
} | ||
}; | ||
|
||
const removeFromGitignore = async (pluginPath) => { | ||
try { | ||
const relativePluginPath = path.relative(path.join(__dirname, '../'), pluginPath); | ||
let gitignoreContent = await readGitignore(); | ||
|
||
if (gitignoreContent.includes(relativePluginPath)) { | ||
gitignoreContent = gitignoreContent | ||
.split('\n') | ||
.filter(line => line.trim() !== relativePluginPath) | ||
.join('\n'); | ||
await writeGitignore(gitignoreContent); | ||
console.log(`✅ ${relativePluginPath} eliminado de .gitignore`); | ||
} | ||
} catch (error) { | ||
throw new Error(`Error al actualizar .gitignore: ${error.message}`); | ||
} | ||
}; | ||
|
||
const downloadPlugin = async (url, pluginName) => { | ||
try { | ||
const response = await fetch(url); | ||
if (!response.ok) throw new Error(`❌ Error al descargar el plugin: ${response.statusText}`); | ||
|
||
const pluginPath = path.join(pluginsDir, pluginName); | ||
const fileStream = fs.createWriteStream(pluginPath); | ||
|
||
await new Promise((resolve, reject) => { | ||
response.body.pipe(fileStream); | ||
response.body.on('error', reject); | ||
fileStream.on('finish', resolve); | ||
}); | ||
|
||
console.log(`✅ Plugin descargado: ${pluginName}`); | ||
return pluginPath; | ||
} catch (error) { | ||
throw new Error(`Error al descargar el plugin: ${error.message}`); | ||
} | ||
}; | ||
|
||
const deletePlugin = async (pluginName) => { | ||
const pluginPath = path.join(pluginsDir, pluginName); | ||
try { | ||
if (fs.existsSync(pluginPath)) { | ||
await removeFromGitignore(pluginPath); | ||
fs.unlinkSync(pluginPath); | ||
console.log(`✅ Plugin ${pluginName} eliminado.`); | ||
return `✅ 🗑️ ${pluginName} `; | ||
} else { | ||
return `❌ ${pluginName} no existe.`; | ||
} | ||
} catch (error) { | ||
throw new Error(`Error al eliminar el plugin: ${error.message}`); | ||
} | ||
}; | ||
|
||
const handler = async (m, { text }) => { | ||
if (!text) return m.reply('❌ Ej .plg url .plg nombre'); | ||
|
||
try { | ||
const input = text.trim(); | ||
ensurePluginsDirExists(); // innecesario | ||
|
||
if (isValidUrl(input)) { | ||
const pluginName = path.basename(input); | ||
const pluginPath = await downloadPlugin(input, pluginName); | ||
await addToGitignore(pluginPath); | ||
m.reply(`✅ ${pluginName} instalado`); | ||
} else { | ||
const result = await deletePlugin(input); | ||
m.reply(result); | ||
} | ||
} catch (error) { | ||
console.error("Error al procesar el comando:", error); | ||
const errorMessage = error.message.includes('Error al eliminar el plugin') // complejo e ineccesario. Brr | ||
? error.message.split('❌ ')[1] | ||
: `❌ ${error.message}`; | ||
m.reply(errorMessage); | ||
} | ||
}; | ||
|
||
handler.command = /^plg$/i; | ||
handler.help = ['Instalador Plugins plg <url o nombre>']; | ||
handler.tags = ['tools']; | ||
handler.owner = true; // Solo el propietario puede usar este comando | ||
|
||
export default handler; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
// Uboicaciones | ||
const configPath = path.join(__dirname, '../config.js'); | ||
const gitignorePath = path.join(__dirname, '../.gitignore'); | ||
|
||
const ensureConfigIgnored = async () => { | ||
try { | ||
let gitignoreContent = ''; | ||
|
||
if (fs.existsSync(gitignorePath)) { | ||
gitignoreContent = await fs.promises.readFile(gitignorePath, 'utf-8'); | ||
} | ||
|
||
if (!gitignoreContent.includes('config.js')) { | ||
gitignoreContent += '\nconfig.js\n'; | ||
await fs.promises.writeFile(gitignorePath, gitignoreContent, 'utf-8'); | ||
console.log('✅ config.js añadido a .gitignore'); | ||
} | ||
} catch (error) { | ||
throw new Error(`❌ .gitignore ${error.message}`); | ||
} | ||
}; | ||
|
||
const updateConfigFile = async (variable, value) => { | ||
try { | ||
let configContent = await fs.promises.readFile(configPath, 'utf-8'); | ||
|
||
const cleanVariable = variable.replace(/^global\./, ''); | ||
|
||
const variablePattern = new RegExp(`(^|\\n)global\\.${cleanVariable}\\s*=\\s*['"\`].*?['"\`];?`, 'm'); | ||
|
||
const formattedValue = /^['"`].*['"]$/.test(value) ? value : `'${value}'`; | ||
|
||
if (variablePattern.test(configContent)) { | ||
configContent = configContent.replace(variablePattern, `global.${cleanVariable} = ${formattedValue};`); | ||
} else { | ||
configContent += `\nglobal.${cleanVariable} = ${formattedValue};\n`; | ||
} | ||
|
||
await fs.promises.writeFile(configPath, configContent, 'utf-8'); | ||
} catch (error) { | ||
throw new Error(`❌ ${error.message}`); | ||
} | ||
}; | ||
|
||
const handler = async (m, { text }) => { | ||
if (!text) return m.reply('❌ Ej .setvar global.groq = gsk'); | ||
|
||
const [variable, value] = text.split('=').map(item => item.trim()); | ||
|
||
if (!variable || !value) return m.reply('❌ Ej .setvar variable = valor'); | ||
|
||
try { | ||
await ensureConfigIgnored(); | ||
await updateConfigFile(variable, value); | ||
m.reply(`✅ ${variable.replace(/^global\./, '')} actualizada a ${value}`); | ||
} catch (error) { | ||
console.error("❌ Error al actualizar config.js:", error); | ||
m.reply(`❌ ${error.message}`); | ||
} | ||
}; | ||
|
||
handler.command = /^setvar$/i; | ||
handler.help = ['cambia ajustes']; | ||
handler.tags = ['tools']; | ||
handler.owner = true; | ||
|
||
export default handler; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
es file |
Oops, something went wrong.