Skip to content

Commit 7adc55a

Browse files
committed
Add a awww command and aliases
1 parent f3d8471 commit 7adc55a

5 files changed

Lines changed: 67 additions & 1 deletion

File tree

commands/aw.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Alias for awww command
3+
* @param {Client} client Discord server client
4+
* @param {Message} msg Command
5+
* @param {Array} args Command arguments
6+
*/
7+
module.exports = async (client, msg, args) => {
8+
require('./awww')(client, msg, args);
9+
}

commands/aww.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Alias for awww command
3+
* @param {Client} client Discord server client
4+
* @param {Message} msg Command
5+
* @param {Array} args Command arguments
6+
*/
7+
module.exports = async (client, msg, args) => {
8+
require('./awww')(client, msg, args);
9+
}

commands/awww.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const host = 'www.reddit.com';
2+
const endpoint = '/r/awww/random.json'
3+
4+
const { authenticatedGet } = require('../lib/Internet');
5+
const log = require('log4js').getLogger('amy');
6+
7+
/**
8+
* Returns a random photo from /r/awww
9+
* @param {Client} client Discord server client
10+
* @param {Message} msg Command
11+
* @param {Array} args Arguments
12+
*/
13+
module.exports = async (client, msg, args) => {
14+
try {
15+
authenticatedGet(function (data) {
16+
if (data
17+
&& data.length > 0
18+
&& data[0]
19+
&& data[0].data
20+
&& data[0].data.children
21+
&& data[0].data.children.length > 0
22+
&& data[0].data.children[0].data
23+
&& data[0].data.children[0].data.url_overridden_by_dest) {
24+
const link = data[0].data.children[0].data.url_overridden_by_dest;
25+
if (link.startsWith('https://www.reddit.com')) {
26+
msg.channel.send(`Check out this Reddit gallery (auto-gallery coming soon!): ${link}`);
27+
} else {
28+
msg.channel.send(link);
29+
}
30+
} else {
31+
msg.channel.send("That didn't work... try again?");
32+
}
33+
}, host, endpoint, {}, {
34+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
35+
});
36+
} catch (err) {
37+
log.error(`While trying to grab a Reddit battlestation I got ${err}`);
38+
}
39+
}

commands/awwww.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Alias for awww command
3+
* @param {Client} client Discord server client
4+
* @param {Message} msg Command
5+
* @param {Array} args Command arguments
6+
*/
7+
module.exports = async (client, msg, args) => {
8+
require('./awww')(client, msg, args);
9+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amy",
3-
"version": "3.0.5",
3+
"version": "3.1.0",
44
"description": "Your personal assisstant, reimagined",
55
"author": "Gideon Tong <gideon@gideontong.com>",
66
"main": "index.js",

0 commit comments

Comments
 (0)