stuff and things
This commit is contained in:
parent
3957b17645
commit
e67c0d96ca
28 changed files with 54 additions and 150 deletions
|
@ -38,6 +38,17 @@ const combined = [...tenorURLs, ...giphyURLs, ...giphyMediaURLs, ...imgurURLs, .
|
|||
const imageFormats = ["image/jpeg", "image/png", "image/webp", "image/gif", "large"];
|
||||
const videoFormats = ["video/mp4", "video/webm", "video/mov"];
|
||||
|
||||
// check if url contents is valid url
|
||||
const isValidUrl = urlString=> {
|
||||
var urlPattern = new RegExp('^(https?:\\/\\/)?'+ // validate protocol
|
||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // validate domain name
|
||||
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // validate OR ip (v4) address
|
||||
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // validate port and path
|
||||
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // validate query string
|
||||
'(\\#[-a-z\\d_]*)?$','i'); // validate fragment locator
|
||||
return !!urlPattern.test(urlString);
|
||||
}
|
||||
|
||||
// gets the proper image paths
|
||||
const getImage = async (image, image2, video, extraReturnTypes, gifv = false, type = null, link = false) => {
|
||||
try {
|
||||
|
@ -125,7 +136,16 @@ const checkImages = async (message, extraReturnTypes, video, sticker) => {
|
|||
const fileNameNoExtension = message.content.body.slice(0, message.content.body.lastIndexOf("."));
|
||||
type = {name: fileNameNoExtension, path: url, url: url, type: message.content.info.mimetype}
|
||||
}
|
||||
}
|
||||
if (message.content.msgtype == "m.text") {
|
||||
let url = message.content.body
|
||||
url = url.replace(/.*\n\n/g, "")
|
||||
if (isValidUrl(url)){
|
||||
const mimetype = await getType(url, extraReturnTypes)
|
||||
type = {name: "image", path: url, url: url, type: mimetype}
|
||||
}
|
||||
}
|
||||
|
||||
// // first check the embeds
|
||||
// if (message.embeds.length !== 0) {
|
||||
// // embeds can vary in types, we check for tenor gifs first
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue