From bd48db3f8cef8b3414ee963d9a788e8eb8255b14 Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Sat, 12 Nov 2022 17:56:42 +0700 Subject: [PATCH] feat: static getShorten (WebEmbed) --- src/structures/WebEmbed.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/structures/WebEmbed.js b/src/structures/WebEmbed.js index f154123..472a70a 100644 --- a/src/structures/WebEmbed.js +++ b/src/structures/WebEmbed.js @@ -371,31 +371,31 @@ class WebEmbed { } const fullURL = `${this.baseURL}${arrayQuery.join('&')}`; if (this.shorten) { - const url = await getShorten(fullURL, this); + const url = await this.constructor.getShorten(fullURL, this); if (!url) console.log('Cannot shorten URL in WebEmbed'); return this.hidden ? `${hiddenCharter} ${url || fullURL}` : url || fullURL; } else { return this.hidden ? `${hiddenCharter} ${fullURL}` : fullURL; } } -} -const getShorten = async (url, embed) => { - const APIurl = ['https://tinyurl.com/api-create.php?url=']; - const shorten = `${ - embed.shortenAPI && typeof embed.shortenAPI == 'string' - ? embed.shortenAPI - : APIurl[Math.floor(Math.random() * APIurl.length)] - }${encodeURIComponent(url)}`; - try { - const res = await axios.get(`${shorten}`); - if (typeof res.data === 'string') return res.data; - else if (typeof res.data === 'object') return res.data.shorten; - else throw new Error('Unknown error'); - } catch { - return undefined; + static async getShorten(url, embed) { + const APIurl = ['https://tinyurl.com/api-create.php?url=']; + const shorten = `${ + embed.shortenAPI && typeof embed.shortenAPI == 'string' + ? embed.shortenAPI + : APIurl[Math.floor(Math.random() * APIurl.length)] + }${encodeURIComponent(url)}`; + try { + const res = await axios.get(`${shorten}`); + if (typeof res.data === 'string') return res.data; + else if (typeof res.data === 'object') return res.data.shorten; + else throw new Error('Unknown error'); + } catch { + return undefined; + } } -}; +} module.exports = WebEmbed; module.exports.hiddenEmbed = hiddenCharter;