-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
67 lines (59 loc) · 1.64 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const axios = require('axios');
const Discord = require("discord.js");
const dotenv = require("dotenv");
const last = require('lodash/last');
const replace = require('lodash/replace');
const split = require('lodash/split');
const trim = require('lodash/trim');
const client = new Discord.Client();
dotenv.config();
const suggestion = new Discord.MessageEmbed()
.setColor('blue')
.setURL('https://forms.gle/pGrDA4miGey162aa9')
.setTitle('Suggest Acronyms Here');
client.on("ready", () => {
console.log(`Logged in as ${client.user.username}!`);
});
client.on("message", msg => {
if (msg.author.id === client.user.id) {
//Don't respond to yourself, lol.
return;
}
if (msg.mentions.users.has(client.user.id)) {
//Reduce to just the capital letter acronym
const command = replace(trim(last(split(msg.content, '>'))), /[^\w\s]/gi, '').toUpperCase();
if (command === "HELP") {
msg.channel.startTyping();
axios
.get(`${process.env.ACRONYM_API_URL}.json`)
.then(res => {
msg.channel.send(`I know about: ${Object.keys(res.data)}`);
})
.catch(err => {
console.error(err.message);
})
.finally(() => {
msg.channel.stopTyping();
})
} else {
msg.channel.startTyping();
axios
.get(`${process.env.ACRONYM_API_URL}/${command}.json`)
.then(res => {
if (res.data === null) {
msg.channel.send("💥 Nothin.");
msg.channel.send(suggestion);
return
}
msg.channel.send(`🤔 ${res.data}?`);
})
.catch(err => {
console.error(err.message);
})
.finally(() => {
msg.channel.stopTyping();
})
}
}
});
client.login(process.env.DISCORD_BOT_TOKEN);