mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-04 07:46:43 +02:00
URL Shorten Command
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { GOOGLE_KEY } = process.env;
|
||||
|
||||
module.exports = class ShortenURLCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'shorten-url',
|
||||
aliases: ['short-url', 'url-shorten'],
|
||||
group: 'random',
|
||||
memberName: 'shorten-url',
|
||||
description: 'Creates a goo.gl short URL from another URL.',
|
||||
args: [
|
||||
{
|
||||
key: 'url',
|
||||
prompt: 'What url do you want to shorten?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { url }) {
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.post(`https://www.googleapis.com/urlshortener/v1/url`)
|
||||
.query({ key: GOOGLE_KEY })
|
||||
.send({ longUrl: url });
|
||||
return msg.say(`<${body.id}>`);
|
||||
} catch (err) {
|
||||
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "40.0.0",
|
||||
"version": "40.1.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Shard.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user