Created
October 7, 2021 03:55
-
-
Save aditya-dev201/b018ce3f372a911925e8ee08153869fb to your computer and use it in GitHub Desktop.
A Code In BJS Who Take URL And Send Its Image
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
//CMD - /screenshot | |
function validURL(Url) { | |
var regex = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/ | |
return regex.test(Url) | |
} | |
if (!validURL(message)) { | |
Api.sendMessage({ | |
text: "<b> Link Not Valid </b>", | |
parse_mode: "HTML", | |
disable_web_page_preview: true | |
}) | |
return | |
} | |
var params = { | |
url: | |
"https://shot.screenshotapi.net/screenshot?url=" + | |
encodeURIComponent(message), | |
success: "/onSendingImage", | |
error: "/onError", | |
background: true | |
} | |
Api.sendMessage({ | |
text: | |
"<b> Capturing Photo From Website!!\n\nUrl : " + | |
message + | |
"\nWait A Little.</b>", | |
parse_mode: "HTML", | |
disable_web_page_preview: true | |
}) | |
HTTP.get(params) | |
//Ending | |
//CMD - /onSendingImage | |
var json = JSON.parse(content) | |
var photoUrl = json.screenshot | |
var captionText = "* Your Image Of Website*" | |
var params = { | |
photo: photoUrl, | |
caption: captionText, | |
parse_mode : 'markdown' | |
} | |
Api.sendPhoto(params) | |
//END | |
//CMD - /onError | |
Bot.sendMessage("Error on downloading"); | |
Bot.inspect(http_status); | |
Bot.inspect(http_headers); // headers from response | |
Bot.inspect(cookies); | |
//END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment