-
-
Notifications
You must be signed in to change notification settings - Fork 382
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
7b1d74c
commit b7d61f3
Showing
1 changed file
with
33 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,33 @@ | ||
import fetch from "node-fetch" | ||
|
||
let handler = async (m, { | ||
conn, | ||
usedPrefix, | ||
args, | ||
command | ||
}) => { | ||
let query = "Where is the link? The link you want to convert to pdf!\n Example :\n .urltopdf https://github.com/whiteshadowofficial/Jessi-md" | ||
let text | ||
if (args.length >= 1) { | ||
text = args.slice(0).join(" ") | ||
} else if (m.quoted && m.quoted.text) { | ||
text = m.quoted.text | ||
} else throw query | ||
await m.reply(wait) | ||
|
||
if (!isValidURL(text)) return m.reply("*The link is not available or is not transferable. Try again with another link*") | ||
try { | ||
let gas = "https://api.html2pdf.app/v1/generate?url=" + text + "&apiKey=DzhGk9fhdPope6j8PmVmbxoNDDiWbsFpdeKZfMMrrxtsl3pXCRbfYOd7N4HovaJ1" | ||
await conn.sendFile(m.chat, gas, m.name, text, m) | ||
} catch (e) { | ||
await m.reply('error') | ||
} | ||
} | ||
handler.tags = ["pdf"] | ||
handler.command = handler.help = ["urltopdf"] | ||
export default handler | ||
|
||
function isValidURL(message) { | ||
const urlPattern = /https?:\/\/[^\s/$.?#].[^\s]*/; | ||
return urlPattern.test(message); | ||
} |