Spaces:
Runtime error
Runtime error
const axios = require('axios'); | |
const { cmd } = require('../command'); | |
const config = require('../config'); // Ensure your API key is in config | |
cmd({ | |
pattern: "movie", | |
desc: "Fetch detailed information about a movie.", | |
category: "utility", | |
react: "π¬", | |
filename: __filename | |
}, | |
async (conn, mek, m, { from, quoted, body, isCmd, command, args, q, isGroup, sender, senderNumber, botNumber2, botNumber, pushname, isMe, isOwner, groupMetadata, groupName, participants, groupAdmins, isBotAdmins, isAdmins, reply }) => { | |
try { | |
const movieName = args.join(' '); | |
if (!movieName) { | |
return reply("π½οΈ Please provide the name of the movie."); | |
} | |
const apiUrl = `http://www.omdbapi.com/?t=${encodeURIComponent(movieName)}&apikey=${config.OMDB_API_KEY}`; | |
const response = await axios.get(apiUrl); | |
const data = response.data; | |
if (data.Response === "False") { | |
return reply("π« Movie not found."); | |
} | |
const movieInfo = ` | |
π¬ *Movie Information* π¬ | |
π₯ *Title:* ${data.Title} | |
π *Year:* ${data.Year} | |
π *Rated:* ${data.Rated} | |
π *Released:* ${data.Released} | |
β³ *Runtime:* ${data.Runtime} | |
π *Genre:* ${data.Genre} | |
π¬ *Director:* ${data.Director} | |
βοΈ *Writer:* ${data.Writer} | |
π *Actors:* ${data.Actors} | |
π *Plot:* ${data.Plot} | |
π *Language:* ${data.Language} | |
πΊπΈ *Country:* ${data.Country} | |
π *Awards:* ${data.Awards} | |
β *IMDB Rating:* ${data.imdbRating} | |
π³οΈ *IMDB Votes:* ${data.imdbVotes} | |
`; | |
// Define the image URL | |
const imageUrl = data.Poster && data.Poster !== 'N/A' ? data.Poster : config.ALIVE_IMG; | |
// Send the movie information along with the poster image | |
await conn.sendMessage(from, { | |
image: { url: imageUrl }, | |
caption: `${movieInfo}\n> Β©α΄α΄α΄‘α΄Κα΄α΄ ΚΚ sα΄Κα΄’α΄Κα΄` | |
}, { quoted: mek }); | |
} catch (e) { | |
console.log(e); | |
reply(`β Error: ${e.message}`); | |
} | |
}); | |