-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
95 lines (82 loc) · 3.05 KB
/
index.js
File metadata and controls
95 lines (82 loc) · 3.05 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* eslint-disable no-console */
/* eslint-disable no-underscore-dangle */
const Discord = require('discord.js');
const client = new Discord.Client();
const arrMethods = require('./db/queries/arrayQueries');
const strMethods = require('./db/queries/stringQueries');
const objMethods = require('./db/queries/objectQueries');
const msgMethods = require('./db/queries/messageQueries');
const embedMethods = require('./methods/embed');
require('dotenv').config();
client.on('message', async (msg) => {
const queryMessage = msg.content.split(' ');
if (queryMessage[0] === '!a' || queryMessage[0] === '!array') {
try {
const methodRes = await arrMethods.search(queryMessage[1]);
const methodData = await methodRes.toJSON();
await msg.channel.send(methodData.url);
} catch (err) {
msg.channel.send(`Unable to find an array method called ${queryMessage[1]}.`);
}
}
if (queryMessage[0] === '!s' || queryMessage[0] === '!string') {
try {
const methodRes = await strMethods.search(queryMessage[1]);
const methodData = await methodRes.toJSON();
await msg.channel.send(methodData.url);
} catch (err) {
msg.channel.send(`Unable to find a string method called ${queryMessage[1]}.`);
}
}
if (queryMessage[0] === '!o' || queryMessage[0] === '!object') {
try {
const methodRes = await objMethods.search(queryMessage[1]);
const methodData = await methodRes.toJSON();
await msg.channel.send(methodData.url);
} catch (err) {
msg.channel.send(`Unable to find an object method called ${queryMessage[1]}.`);
}
}
if (queryMessage[0] === '!pr') {
const embedMsg = embedMethods.formatEmbed(msg, queryMessage[1]);
try {
const embed = await msg.channel.send(embedMsg);
await embed.react('693211024287072337');
await embed.react('693211024748314655');
} catch (err) {
console.log(err);
}
}
if (msg.channel.name !== 'bot-commands' && msg.channel.name !== 'slack-bld09' && msg.channel.name !== 'slack-bld08') {
try {
await msgMethods.insert(msg);
} catch (err) {
console.error(err);
}
}
});
client.on('messageReactionAdd', async (reaction) => {
if (reaction._emoji.name === 'issue' && reaction.count === 2) {
try {
const recievedEmbed = reaction.message.embeds[0];
const updatedEmbed = new Discord.MessageEmbed(recievedEmbed);
const username = updatedEmbed.title.split(' ').slice(0, 2).join(' ');
updatedEmbed.fields[1].value = 'In Progress';
updatedEmbed.fields[0].value = username.slice(0, username.length - 2);
await reaction.message.edit(updatedEmbed);
} catch (err) {
console.log(err);
}
}
if (reaction._emoji.name === 'issueClosed' && reaction.count === 2) {
try {
const recievedEmbed = reaction.message.embeds[0];
const updatedEmbed = new Discord.MessageEmbed(recievedEmbed);
updatedEmbed.fields[1].value = 'Completed';
await reaction.message.edit(updatedEmbed);
} catch (err) {
console.log(err);
}
}
});
client.login(process.env.BOT_TOKEN);