Revert "Merge pull request #13 from lazuee/main"

This reverts commit fd7910de95, reversing
changes made to 44db21c06f.
This commit is contained in:
March 7th
2022-04-01 18:22:36 +07:00
parent fd7910de95
commit 5b0ebe175b
4 changed files with 18 additions and 63 deletions

View File

@@ -11,18 +11,6 @@ class WebEmbed {
this._setup(data);
}
_setup(data) {
/**
* Shorten the link
* @type {?boolean}
*/
this.shorten = data.shorten ?? false;
/**
* Hidden Embed link
* @type {?boolean}
*/
this.hidden = data.hidden ?? false;
/**
* The title of this embed
* @type {?string}
@@ -246,15 +234,17 @@ class WebEmbed {
/**
* Return Message Content + Embed (if hidden, pls check content length because it has 1000+ length)
* @param {boolean} hidden Hidden Embed link
* @param {boolean} shorten Shorten link ?
* @returns {string} Message Content
*/
async toMessage() {
async toMessage(hidden = false, shorten = true) {
const arrayQuery = [];
if (this.title) {
arrayQuery.push(`title=${encodeURIComponent(this.title)}`);
arrayQuery.push(`title=${this.title}`);
}
if (this.description) {
arrayQuery.push(`description=${encodeURIComponent(this.description)}`);
arrayQuery.push(`description=${this.description}`);
}
if (this.url) {
arrayQuery.push(`url=${encodeURIComponent(this.url)}`);
@@ -287,12 +277,12 @@ class WebEmbed {
);
}
const fullURL = `${baseURL}${arrayQuery.join('&')}`;
if (this.shorten) {
if (shorten) {
const url = await getShorten(fullURL);
if (!url) console.log('Cannot shorten URL in WebEmbed');
return this.hidden ? `${hiddenCharter} ${url || fullURL}` : (url || fullURL);
return hidden ? `${hiddenCharter} ${url || fullURL}` : (url || fullURL);
} else {
return this.hidden ? `${hiddenCharter} ${fullURL}` : fullURL;
return hidden ? `${hiddenCharter} ${fullURL}` : fullURL;
}
}
}
@@ -311,4 +301,4 @@ const getShorten = async (url) => {
}
}
module.exports = WebEmbed;
module.exports = WebEmbed;