URL Shorten Command

This commit is contained in:
Dragon Fire
2020-06-08 11:34:19 -04:00
parent 858b8194ad
commit 1942e9ffb2
3 changed files with 52 additions and 2 deletions
+4 -1
View File
@@ -225,7 +225,7 @@ in the appropriate channel's topic to use it.
## Commands
Total: 461
Total: 462
### Utility:
@@ -679,6 +679,7 @@ Total: 461
* **sha-1:** Creates a hash of text with the SHA-1 algorithm.
* **sha-256:** Creates a hash of text with the SHA-256 algorithm.
* **ship-name:** Creates a ship name from two names.
* **shorten-url:** Shortens a URL using bit.ly.
* **shuffle:** Shuffles text.
* **snake-speak:** Convertsssss text to sssssnake ssssspeak.
* **spoiler-letter:** Sends text with each and every character as an individual spoiler.
@@ -838,6 +839,8 @@ here.
* dislike ([Image, Original "Fallout" Game](https://fallout.bethesda.net/en/))
* like ([Image, Original "Fallout" Game](https://fallout.bethesda.net/en/))
* skyrim-skill ([Image, Original "The Elder Scrolls V: Skyrim" Game](https://elderscrolls.bethesda.net/en/skyrim))
- [Bitly](https://bitly.com/)
* shorten-url ([API](https://dev.bitly.com/v4_documentation.html))
- [Bob Ross](https://www.bobross.com/)
* bob-ross (Himself)
- [Bowserinator](https://github.com/Bowserinator/)
+47
View File
@@ -0,0 +1,47 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { BITLY_KEY } = process.env;
module.exports = class ShortenUrlCommand extends Command {
constructor(client) {
super(client, {
name: 'shorten-url',
aliases: ['short-url', 'bit-ly', 'bit.ly', 'url-shorten', 'url-short'],
group: 'edit-text',
memberName: 'shorten-url',
description: 'Shortens a URL using bit.ly.',
credit: [
{
name: 'Bitly',
url: 'https://bitly.com/',
reason: 'API',
reasonURL: 'https://dev.bitly.com/v4_documentation.html'
}
],
args: [
{
key: 'url',
prompt: 'What url would you like to shorten?',
type: 'string',
validate: url => {
if (encodeURI(url).length > 2083) return 'Your URL is too long.';
return true;
}
}
]
});
}
async run(msg, { url }) {
try {
const { body } = await request
.post('https://api-ssl.bitly.com/v4/shorten')
.query({ long_url: url })
.set({ Authorization: `Bearer ${BITLY_KEY}` });
return msg.say(body.link);
} catch (err) {
if (err.status === 400) return msg.reply('You provided an invalid URL. Please try again.');
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "116.6.0",
"version": "116.7.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {