feat(WebEmbed) Custom API, Custom ShortenAPI, and open-source API

https://github.com/aiko-chan-ai/WebEmbed
This commit is contained in:
Cinnamon 2022-06-27 13:23:00 +07:00
parent 3b2d88caf9
commit 58b4179e81
8 changed files with 45 additions and 23 deletions

View File

@ -2,6 +2,16 @@ name: Bug report
description: Report incorrect or unexpected behavior of a package description: Report incorrect or unexpected behavior of a package
labels: [bug, need repro] labels: [bug, need repro]
body: body:
- type: dropdown
id: package
attributes:
label: Which package has the bugs?
options:
- The core library
- The documentation
- WebEmbed x Shorten API
validations:
required: true
- type: textarea - type: textarea
id: description id: description
attributes: attributes:

View File

@ -14,6 +14,7 @@ body:
options: options:
- The core library - The core library
- The documentation - The documentation
- WebEmbed x Shorten API
validations: validations:
required: true required: true
- type: textarea - type: textarea

View File

@ -69,9 +69,12 @@ In this way, all Slash commands can be obtained
Code: Code:
```js ```js
const Discord = require('discord.js-selfbot-v13'); const Discord = require('discord.js-selfbot-v13');
// Selfhost WebEmbed: https://github.com/aiko-chan-ai/WebEmbed
const w = new Discord.WebEmbed({ const w = new Discord.WebEmbed({
shorten: true, shorten: true,
hidden: false // if you send this embed with MessagePayload.options.embeds, it must set to false hidden: false // if you send this embed with MessagePayload.options.embeds, it must set to false
baseURL: '', // if you want self-host API, else skip :v
shortenAPI: '', // if you want Custom shortenAPI (Method: Get, response: Text => URL), else skip :v
}) })
.setAuthor({ name: 'hello', url: 'https://google.com' }) .setAuthor({ name: 'hello', url: 'https://google.com' })
.setColor('RED') .setColor('RED')

View File

@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007 Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Copyright (C) 2022 aiko-chan-ai and discordjs
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.

View File

@ -32,8 +32,8 @@
### <strong>[Document Website (recommend)](https://discordjs-self-v13.netlify.app/)</strong> ### <strong>[Document Website (recommend)](https://discordjs-self-v13.netlify.app/)</strong>
But if you want to see some specific notes (with pictures) you can go to [here](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/tree/main/Document)
### <strong>[Risky actions](https://github.com/Merubokkusu/Discord-S.C.U.M/issues/66)</strong> ### <strong>[Extend Document (With Example)](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/tree/main/Document)</strong>
## Checklist ## Checklist
- [x] Send + receive messages (not send Embed :v ). - [x] Send + receive messages (not send Embed :v ).
@ -95,17 +95,6 @@ console.log(`%cYou now have your token in the clipboard!`, 'font-size: 16px');
Credit: <img src="https://cdn.discordapp.com/emojis/889092230063734795.png" alt="." width="16" height="16"/> [<strong>hxr404</strong>](https://github.com/hxr404/Discord-Console-hacks) Credit: <img src="https://cdn.discordapp.com/emojis/889092230063734795.png" alt="." width="16" height="16"/> [<strong>hxr404</strong>](https://github.com/hxr404/Discord-Console-hacks)
## Links (Discord.js)
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))
- [Documentation](https://discord.js.org/#/docs)
- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide))
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v13.html), including updated and removed items in the library.
- [discord.js Discord server](https://discord.gg/djs)
- [Discord API Discord server](https://discord.gg/discord-api)
- [GitHub](https://github.com/discordjs/discord.js)
- [npm](https://www.npmjs.com/package/discord.js)
- [Related libraries](https://discord.com/developers/docs/topics/community-resources#libraries)
## Contributing ## Contributing
@ -120,7 +109,6 @@ Contact me in Discord: [Shiraori#1782](https://discord.com/users/721746046543331
- [Discord.js](https://github.com/discordjs/discord.js) - [Discord.js](https://github.com/discordjs/discord.js)
- [Discord S.C.U.M](https://github.com/Merubokkusu/Discord-S.C.U.M) - [Discord S.C.U.M](https://github.com/Merubokkusu/Discord-S.C.U.M)
- [Discord Console Hack](https://github.com/hxr404/Discord-Console-hacks) - [Discord Console Hack](https://github.com/hxr404/Discord-Console-hacks)
- And the people who submitted the issue, colab, ...
## <strong><img src="https://cdn.discordapp.com/attachments/820557032016969751/952436539118456882/flag-vietnam_1f1fb-1f1f3.png" alt="." width="20" height="20"/> Vietnamese</strong> ## <strong><img src="https://cdn.discordapp.com/attachments/820557032016969751/952436539118456882/flag-vietnam_1f1fb-1f1f3.png" alt="." width="20" height="20"/> Vietnamese</strong>
Được tạo bởi người Việt Nam, dựa trên Discord API v9, đây là một trong những module selfbot được hỗ trợ tốt nhất. Được tạo bởi người Việt Nam, dựa trên Discord API v9, đây là một trong những module selfbot được hỗ trợ tốt nhất.

File diff suppressed because one or more lines are too long

View File

@ -208,7 +208,7 @@ class MessagePayload {
// Add hidden embed link // Add hidden embed link
content += `\n${WebEmbed.hiddenEmbed} \n`; content += `\n${WebEmbed.hiddenEmbed} \n`;
if (webembeds.length > 1) { if (webembeds.length > 1) {
console.warn('Multiple webembeds are not supported, this will be ignored.'); console.warn('[WARN] Multiple webembeds are not supported, this will be ignored.');
} }
// Const embed = webembeds[0]; // Const embed = webembeds[0];
for (const webE of webembeds) { for (const webE of webembeds) {

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const axios = require('axios'); const axios = require('axios');
const baseURL = 'https://sagiri-fansub.tk/embed?'; const baseURL = 'https://sagiri-v3dot3.herokuapp.com/embed?';
const hiddenCharter = const hiddenCharter =
'||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||'; '||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||';
const { RangeError } = require('../errors'); const { RangeError } = require('../errors');
@ -49,6 +49,20 @@ class WebEmbed {
* @type {?boolean} * @type {?boolean}
*/ */
this.hidden = data.hidden ?? false; this.hidden = data.hidden ?? false;
/**
* Using Custom WebEmbed server ?
* @type {?string} https://sagiri-v3dot3.herokuapp.com/embed?
* @see https://github.com/aiko-chan-ai/WebEmbed
*/
this.baseURL = data.baseURL ?? baseURL;
/**
* Shorten API
* @type {?string} https://sagiri-v3dot3.herokuapp.com/short?url=
* @see https://github.com/aiko-chan-ai/WebEmbed
*/
this.shortenAPI = data.shortenAPI;
} }
/** /**
* @private * @private
@ -353,9 +367,9 @@ class WebEmbed {
if (this.thumbnail?.url) { if (this.thumbnail?.url) {
arrayQuery.push(`image=${encodeURIComponent(this.thumbnail.url)}`); arrayQuery.push(`image=${encodeURIComponent(this.thumbnail.url)}`);
} }
const fullURL = `${baseURL}${arrayQuery.join('&')}`; const fullURL = `${this.baseURL}${arrayQuery.join('&')}`;
if (this.shorten) { if (this.shorten) {
const url = await getShorten(fullURL); const url = await getShorten(fullURL, this);
if (!url) console.log('Cannot shorten URL in WebEmbed'); if (!url) console.log('Cannot shorten URL in WebEmbed');
return this.hidden ? `${hiddenCharter} ${url || fullURL}` : url || fullURL; return this.hidden ? `${hiddenCharter} ${url || fullURL}` : url || fullURL;
} else { } else {
@ -365,14 +379,20 @@ class WebEmbed {
} }
// 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 getShorten = async (url, embed) => {
const APIurl = [ const APIurl = [
'https://tinyurl.com/api-create.php?url=', 'https://tinyurl.com/api-create.php?url=',
'https://sagiri-fansub.tk/api/v1/short?url=', // My api, pls don't ddos :( // 'https://sagiri-fansub.tk/api/v1/short?url=', // My api, pls don't ddos :(
'https://sagiri-v3dot3.herokuapp.com/short?url=', // My api, pls don't ddos :(
// 'https://lazuee.ga/api/v1/shorten?url=', // 'https://lazuee.ga/api/v1/shorten?url=',
]; ];
const shorten = `${
embed.shortenAPI && typeof embed.shortenAPI == 'string'
? embed.shortenAPI
: APIurl[Math.floor(Math.random() * APIurl.length)]
}${encodeURIComponent(url)}`;
try { try {
const res = await axios.get(`${APIurl[Math.floor(Math.random() * APIurl.length)]}${encodeURIComponent(url)}`); const res = await axios.get(`${shorten}`);
if (typeof res.data === 'string') return res.data; if (typeof res.data === 'string') return res.data;
else if (typeof res.data === 'object') return res.data.shorten; else if (typeof res.data === 'object') return res.data.shorten;
else throw new Error('Unknown error'); else throw new Error('Unknown error');