-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
858e4c3
commit 47609b2
Showing
1 changed file
with
57 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import fetch from 'node-fetch'; | ||
|
||
let handler = async (m, { conn, text }) => { | ||
if (!text) throw 'Please provide a movie title'; | ||
|
||
try { | ||
let res = await fetch(`https://api.popcat.xyz/imdb?q=${encodeURIComponent(text)}`); | ||
|
||
if (!res.ok) { | ||
throw new Error(`API request failed with status ${res.status}`); | ||
} | ||
|
||
let json = await res.json(); | ||
|
||
console.log('JSON response:', json); | ||
|
||
let ratings = json.ratings.map(rating => `• *${rating.source}:* ${rating.value}`).join('\n'); | ||
|
||
let movieInfo = | ||
`*Movie Information:*\n | ||
• *Title:* ${json.title}\n | ||
• *Year:* ${json.year}\n | ||
• *Rated:* ${json.rated}\n | ||
• *Released:* ${json.released}\n | ||
• *Runtime:* ${json.runtime}\n | ||
• *Genres:* ${json.genres}\n | ||
• *Director:* ${json.director}\n | ||
• *Writer:* ${json.writer}\n | ||
• *Actors:* ${json.actors}\n | ||
• *Plot:* ${json.plot}\n | ||
• *Languages:* ${json.languages}\n | ||
• *Country:* ${json.country}\n | ||
• *Awards:* ${json.awards}\n | ||
• *Metascore:* ${json.metascore}\n | ||
• *Rating:* ${json.rating}\n | ||
• *Votes:* ${json.votes}\n | ||
• *IMDB ID:* ${json.imdbid}\n | ||
• *Type:* ${json.type}\n | ||
• *DVD:* ${json.dvd}\n | ||
• *Box Office:* ${json.boxoffice}\n | ||
• *Production:* ${json.production}\n | ||
• *Website:* ${json.website}\n\n | ||
*Ratings:*\n${ratings}`; | ||
|
||
// send the movie poster along with the movie information as caption | ||
await conn.sendFile(m.chat, json.poster, 'poster.jpg', movieInfo, m); | ||
} catch (error) { | ||
console.error(error); | ||
// Handle the error appropriately | ||
} | ||
}; | ||
|
||
handler.help = ['movie']; | ||
handler.tags = ['information']; | ||
handler.command = /^(imdb|movie)$/i; | ||
|
||
export default handler; |