Skip to content

Commit

Permalink
Add a awww command and aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
gideontong committed Dec 2, 2020
1 parent f3d8471 commit 7adc55a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
9 changes: 9 additions & 0 deletions commands/aw.js
@@ -0,0 +1,9 @@
/**
* Alias for awww command
* @param {Client} client Discord server client
* @param {Message} msg Command
* @param {Array} args Command arguments
*/
module.exports = async (client, msg, args) => {
require('./awww')(client, msg, args);
}
9 changes: 9 additions & 0 deletions commands/aww.js
@@ -0,0 +1,9 @@
/**
* Alias for awww command
* @param {Client} client Discord server client
* @param {Message} msg Command
* @param {Array} args Command arguments
*/
module.exports = async (client, msg, args) => {
require('./awww')(client, msg, args);
}
39 changes: 39 additions & 0 deletions commands/awww.js
@@ -0,0 +1,39 @@
const host = 'www.reddit.com';
const endpoint = '/r/awww/random.json'

const { authenticatedGet } = require('../lib/Internet');
const log = require('log4js').getLogger('amy');

/**
* Returns a random photo from /r/awww
* @param {Client} client Discord server client
* @param {Message} msg Command
* @param {Array} args Arguments
*/
module.exports = async (client, msg, args) => {
try {
authenticatedGet(function (data) {
if (data
&& data.length > 0
&& data[0]
&& data[0].data
&& data[0].data.children
&& data[0].data.children.length > 0
&& data[0].data.children[0].data
&& data[0].data.children[0].data.url_overridden_by_dest) {
const link = data[0].data.children[0].data.url_overridden_by_dest;
if (link.startsWith('https://www.reddit.com')) {
msg.channel.send(`Check out this Reddit gallery (auto-gallery coming soon!): ${link}`);
} else {
msg.channel.send(link);
}
} else {
msg.channel.send("That didn't work... try again?");
}
}, host, endpoint, {}, {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
});
} catch (err) {
log.error(`While trying to grab a Reddit battlestation I got ${err}`);
}
}
9 changes: 9 additions & 0 deletions commands/awwww.js
@@ -0,0 +1,9 @@
/**
* Alias for awww command
* @param {Client} client Discord server client
* @param {Message} msg Command
* @param {Array} args Command arguments
*/
module.exports = async (client, msg, args) => {
require('./awww')(client, msg, args);
}
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "amy",
"version": "3.0.5",
"version": "3.1.0",
"description": "Your personal assisstant, reimagined",
"author": "Gideon Tong <gideon@gideontong.com>",
"main": "index.js",
Expand Down

0 comments on commit 7adc55a

Please sign in to comment.