Last active
August 1, 2024 15:50
-
-
Save Tarkiin/accfbce4e45f9995fbf1dd715985646e to your computer and use it in GitHub Desktop.
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
const { bot } = require('../lib/'); | |
const path = require('path'); | |
const fs = require('fs'); | |
// Directorio de imágenes | |
const imageDirectory = path.join(__dirname, 'images'); | |
// Mapa de comandos a nombres de archivos de imagen | |
const imageMap = { | |
'acolores': 'acolores.jpg', | |
'imagen1': 'imagen1.jpg', | |
'imagen2': 'imagen2.jpg', | |
'imagen3': 'imagen3.jpg' | |
}; | |
bot( | |
{ | |
pattern: '^(acolores|imagen1|imagen2|imagen3)$', | |
fromMe: true, | |
desc: 'Send specific image based on the command', | |
type: 'misc', | |
}, | |
async (message, match) => { | |
// match contiene el comando que coincide con uno de los patrones definidos | |
const command = match.trim(); | |
// Verificar si el comando está en el mapa | |
if (imageMap[command]) { | |
// Construir la ruta del archivo de imagen | |
const imagePath = path.join(imageDirectory, imageMap[command]); | |
// Verificar si el archivo de imagen existe | |
if (fs.existsSync(imagePath)) { | |
// Enviar la imagen desde el archivo | |
await message.send( | |
{ file: imagePath, mimetype: 'image/jpeg' }, | |
{}, | |
'document' | |
); | |
} else { | |
// Enviar un mensaje de error si la imagen no existe | |
await message.send('Imagen no encontrada.'); | |
} | |
} else { | |
// Enviar un mensaje de error si el comando no es válido | |
await message.send('Comando no válido. Usa "acolores", "imagen1", "imagen2" o "imagen3".'); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment