From 35e44c6ba5ac5396f00d5cf8d2cb589a96fef378 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 16 Sep 2017 15:23:58 +0000 Subject: [PATCH] URL Shorten Command --- commands/random/shorten-url.js | 34 ++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 commands/random/shorten-url.js diff --git a/commands/random/shorten-url.js b/commands/random/shorten-url.js new file mode 100644 index 00000000..c079b85f --- /dev/null +++ b/commands/random/shorten-url.js @@ -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!`); + } + } +}; diff --git a/package.json b/package.json index ac16c7a4..fff49457 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "40.0.0", + "version": "40.1.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {