-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
184 lines (159 loc) · 7.62 KB
/
index.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
const Discord = require("discord.js");
const express = require('express');
const api = express();
const moment = require('moment-timezone');
const bot = new Discord.Client({
disableEveryone: true,
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
});
const helpCommands = require('./command/help');
const infoCommands = require('./command/info');
const supportCommands = require('./command/support');
const versionCommands = require('./command/version');
const testCommands = require('./command/test');
const timeCommands = require('./command/time');
const lfgCommands = require('./command/lfg');
const msgUtilities = require('./command/msgUtilities');
const feedbackCommands = require('./command/feedback');
const responses = require('./constant/responses');
const emojiHelper = require('./helper/emoji');
const channelHelper = require('./helper/channels');
// Fetch config information from Heroku config vars
const token = process.env.BOT_TOKEN;
const prefix = process.env.BOT_PREFIX;
const port = process.env.PORT || 80;
// Start up the API endpoint for the bot
api.use(function(req, res, next) {
// This puts a CORS header on all requests
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
api.get('/api/newVersion', async () => {
console.log('New Version ping recieved. Fetching details...');
channelHelper.setVoiceChannelTextToCurrentAppReleaseName(bot);
});
// Set the bot's timezone to the server's timezone (UTC)
moment.tz.setDefault();
bot.login(token);
bot.on("ready", async () => {
channelHelper.setVoiceChannelTextToCurrentAppReleaseName(bot);
// Console startup
console.log(`${bot.user.username} is online. Current Prefix: ${prefix}`);
// Set bot's status as "Listening to <prefix>help"
bot.user.setPresence({ status: 'online' });
bot.user.setActivity(`${prefix}help`, { type: 'LISTENING' });
});
bot.on("message", async message => {
//bot.on('voiceStateUpdate', (oldMember, newMember) => {
// console.log('Voice State');
// let newUserChannel = newMember.voiceChannel
// let oldUserChannel = oldMember.voiceChannel
// var Testchannel = bot.channels.get('625258484606435328');
// if (oldUserChannel === 674493680614244382 && newUserChannel !== 660828124002517022) {
// console.log('Join');
//Testchannel.send('has joined a voice channel');
// }
//else if (newUserChannel === 660828124002517022) {
//console.log('Leave');
//Testchannel.send('has left a voice channel');
// User leaves a voice channel
//}
//})
// Ignore messages by the bot itself
if (message.author.bot) return;
// Get the bot-specific emojis by name
const questionDrone = bot.emojis.find(emoji => emoji.name === "DroneQuestion");
const confuseDrone = bot.emojis.find(emoji => emoji.name === "DroneConfused");
const droneEyeBlue = bot.emojis.find(emoji => emoji.name === "DroneEyeBlue");
const droneEyeRed = bot.emojis.find(emoji => emoji.name === "DroneEyeRed");
// Make the bot react to all mentions of it
if (message.isMentioned(bot.user)) {
message.react(droneEyeBlue)
.then(console.log)
.catch(console.error);
}
// Now let's handle all messages, see if we get any commands
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
const amount = args.join(' ');
// This handles all DMs to the bot user
if (message.channel.type === "dm") {
console.log("Direct Message");
// The bot will forward all queries with the <prefix>help command to the faqchannel
if (cmd.toLowerCase() === `${prefix}modhelp`) helpCommands.directMessageHelp(bot, message, args);
else if (cmd.toLowerCase() === `${prefix}info`) infoCommands.infoResponse(message, prefix);
else if (cmd.toLowerCase() === `${prefix}feedback` || cmd.toLowerCase() === `${prefix}suggest`) feedbackCommands.directMessageFeedback(bot, message, args);
else infoCommands.defaultResponse(message, prefix); // Handle all non-recognized commands/msgs
return;
}
// Don't respond/react to msgs that don't start with the prefix and ignore empty commands
if (cmd.startsWith(prefix) == false) return;
if (cmd === prefix) return;
// Make the bot react to every command with the Question emoji,
await message.react(questionDrone);
let authorRoles = await message.member.roles;
let hasDevRole = authorRoles.some(role => role.name === 'Core Devs')
let hasJrDevRole = authorRoles.some(role => role.name === 'New Developer')
let hasModRole = authorRoles.some(role => role.name === 'Moderator')
if (hasDevRole === false) {
// Restricted to developer only
if (cmd === `${prefix}test` || cmd === `${prefix}version`) {
await emojiHelper.removeEmojiAsync(message, questionDrone.id);
await message.react(droneEyeRed);
return message.channel.send(responses.unauthorised);
}
}
if (hasJrDevRole === false) {
// Restricted to developer only
if (cmd === `${prefix}test` || cmd === `${prefix}version`) {
await emojiHelper.removeEmojiAsync(message, questionDrone.id);
await message.react(droneEyeRed);
return message.channel.send(responses.unauthorised);
}
}
if (hasModRole === false) {
// Restricted to mod only
if (cmd === `${prefix}echo` || cmd === `${prefix}clear`) {
await emojiHelper.removeEmojiAsync(message, questionDrone.id);
await message.react(droneEyeRed);
return message.channel.send(responses.unauthorised);
}
}
if (cmd === `${prefix}test`) testCommands.testMessage(message);
else if (cmd === `${prefix}version`) versionCommands.getCurrBotVer(message);
else if (cmd === `${prefix}links`) infoCommands.links(message);
else if (cmd === `${prefix}support`) supportCommands.links(message);
else if (cmd === `${prefix}faq`) infoCommands.faq(message);
else if (cmd === `${prefix}time`) {
if (message.content === cmd) timeCommands.currentTime(message, prefix);
else if (args.includes('set')) timeCommands.setUserTZone(message, prefix, messageArray.slice(2));
else if (args.includes('help')) timeCommands.timeFnsInfo(bot, message, prefix);
}
else if (cmd === `${prefix}supportticket`) supportCommands.ticket(message);
else if (cmd === `${prefix}help`) helpCommands.listOfCommands(message);
else if (cmd === `${prefix}translation`) infoCommands.translation(message);
else if (cmd === `${prefix}guides`) infoCommands.guides(message);
else if (cmd === `${prefix}freshdesk`) supportCommands.freshdesk(message);
else if (cmd === `${prefix}appversion`) infoCommands.appVersion(message);
else if (cmd === `${prefix}reply`) helpCommands.directResponse(message, bot, args);
else if (message.channel.id === '660827424195608586') {
if (cmd === `${prefix}lfg`) lfgCommands.lfgPing(message, args);
}
else if (cmd === `${prefix}echo`) msgUtilities.echoMessage(message, args);
else if (cmd === `${prefix}clear`) msgUtilities.clearMessages(message, amount);
else if (cmd === `${prefix}feedback` || cmd === `${prefix}suggest`) feedbackCommands.feedback(message, bot, args);
else if (cmd === `${prefix}communitylinks`) infoCommands.communityLinks(message);
else {
// If the message contained the prefix but was not a valid command,
// react with the corruptDrone emoji and inform of invalid command
// Remove previous atlas message reaction
await emojiHelper.removeEmojiAsync(message, questionDrone.id);
await message.react(confuseDrone);
return message.channel.send(responses.unrecognised);
}
});
api.listen(parseInt(port), () => {
console.log("Bot API Endpoint online.");
});