Update before publish to npm

Dev version
This commit is contained in:
March 7th
2022-04-01 20:09:32 +07:00
parent d233d0e83e
commit 50516bf89d
6 changed files with 60 additions and 19 deletions

View File

@@ -127,7 +127,7 @@ class MessagePayload {
const isInteraction = this.isInteraction;
const isWebhook = this.isWebhook;
const content = this.makeContent();
let content = this.makeContent();
const tts = Boolean(this.options.tts);
let nonce;
@@ -197,11 +197,22 @@ class MessagePayload {
let webembeds = this.options.embeds.filter(e => e instanceof WebEmbed);
this.options.embeds = this.options.embeds.filter(e => !(e instanceof WebEmbed));
if (webembeds.length > 0) {
// add hidden embed link
content += `\n${WebEmbed.hiddenEmbed} \n`;
}
while (webembeds.length) {
const embed = webembeds.shift();
const data = await embed.toMessage();
content +=`\n${data}`
}
// Check content
if (content.length > 2000) {
console.warn(`[WARN] Content is longer than 2000 characters.`);
}
if (content.length > 4000) { // Max length if user has nitro boost
throw new RangeError('MESSAGE_EMBED_LINK_LENGTH');
}
}
this.data = {

View File

@@ -2,7 +2,7 @@
const axios = require('axios');
const baseURL = 'https://embed.benny.fun/?';
const hiddenCharter =
'||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||';
'||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||';
const { RangeError } = require('../errors');
const Util = require('../util/Util');
@@ -11,6 +11,17 @@ class WebEmbed {
this._setup(data);
}
_setup(data) {
/**
* Shorten the link
* @type {?boolean}
*/
this.shorten = data.shorten ?? true;
/**
* Hidden Embed link
* @type {?boolean}
*/
this.hidden = data.hidden ?? false;
/**
* The title of this embed
* @type {?string}
@@ -234,17 +245,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(hidden = false, shorten = true) {
async toMessage() {
const arrayQuery = [];
if (this.title) {
arrayQuery.push(`title=${this.title}`);
arrayQuery.push(`title=${encodeURIComponent(this.title)}`);
}
if (this.description) {
arrayQuery.push(`description=${this.description}`);
arrayQuery.push(
`description=${encodeURIComponent(this.description)}`,
);
}
if (this.url) {
arrayQuery.push(`url=${encodeURIComponent(this.url)}`);
@@ -262,7 +273,7 @@ class WebEmbed {
}
if (this.author) {
if (this.author.name) arrayQuery.push(
`author_name=${this.author.name}`,
`author_name=${encodeURIComponent(this.author.name)}`,
);
if (this.author.url) arrayQuery.push(
`author_url=${encodeURIComponent(this.author.url)}`,
@@ -270,24 +281,24 @@ class WebEmbed {
}
if (this.provider) {
if (this.provider.name) arrayQuery.push(
`provider_name=${this.provider.name}`,
`provider_name=${encodeURIComponent(this.provider.name)}`,
);
if (this.provider.url) arrayQuery.push(
`provider_url=${encodeURIComponent(this.provider.url)}`,
);
}
const fullURL = `${baseURL}${arrayQuery.join('&')}`;
if (shorten) {
if (this.shorten) {
const url = await getShorten(fullURL);
if (!url) console.log('Cannot shorten URL in WebEmbed');
return hidden ? `${hiddenCharter} ${url || fullURL}` : (url || fullURL);
return this.hidden ? `${hiddenCharter} ${url || fullURL}` : (url || fullURL);
} else {
return hidden ? `${hiddenCharter} ${fullURL}` : fullURL;
return this.hidden ? `${hiddenCharter} ${fullURL}` : fullURL;
}
}
}
// Credit: https://www.npmjs.com/package/node-url-shortener + google :))
// Credit: https://www.npmjs.com/package/node-url-shortener + google :))
const getShorten = async (url) => {
const APIurl = [
'https://is.gd/create.php?format=simple&url=',

View File

@@ -186,9 +186,9 @@ class Webhook {
let messagePayload;
if (options instanceof MessagePayload) {
messagePayload = options.resolveData();
messagePayload = await options.resolveData();
} else {
messagePayload = MessagePayload.create(this, options).resolveData();
messagePayload = await MessagePayload.create(this, options).resolveData();
}
const { data, files } = await messagePayload.resolveFiles();

View File

@@ -166,9 +166,9 @@ class TextBasedChannel {
let messagePayload;
if (options instanceof MessagePayload) {
messagePayload = options.resolveData();
messagePayload = await options.resolveData();
} else {
messagePayload = MessagePayload.create(this, options).resolveData();
messagePayload = await MessagePayload.create(this, options).resolveData();
}
const { data, files } = await messagePayload.resolveFiles();