-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
95 lines (76 loc) · 2.67 KB
/
index.js
File metadata and controls
95 lines (76 loc) · 2.67 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
const appRoot = require('app-root-path');
const fs = require("fs");
const Discord = require('discord.js');
const env = require(appRoot+'/config.json');
const client = new Discord.Client();
const lang = require(appRoot + '/lang/Language');
const PresenceSupevisor = require(appRoot+'/classes/PresenceSupervisor');
const Queue = require('bull');
let embedQueue = new Queue('embed', 'redis://'+env.redis_host+':'+env.redis_port);
// Getting every commands in the 'commands' folder
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync(appRoot+'/commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(appRoot+`/commands/${file}`);
// set a new item in the Collection
// with the key as the command name and the value as the exported module
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready!');
// Queue process to send embed in queue with the channel provided
embedQueue.process(async (job,done) =>{
// Get the channel
client.channels.fetch(job.data.channel_id)
.then((channel) => {
console.log("Sending embed to channel "+job.data.channel_id);
// Check if the embed was the end
if(job.data.end){
PresenceSupevisor.setNoResponseStudentToAbsent(job.data.period_id,() => {
channel.send({embed: job.data.embed});
done();
})
}else{
channel.send({embed: job.data.embed});
done();
}
})
});
});
client.login(env.token);
client.on('message', message => {
// Get message command and arguments
if (!message.content.startsWith(env.prefix) || message.author.bot) return;
//Check server
if(message.channel.type !== "dm"){
let guild_id = message.guild.id;
if(guild_id !== env.server_id){
// Not correct server
message.channel.send(lang.get('not_correct_server'))
return;
}
}
const args = message.content.slice(env.prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
//Check if the command is allowed in DM
if(message.channel.type === "dm" && !command.allowed_in_dm){
message.channel.send(lang.get('not_allowed_in_dm'));
return;
}
// Check if the command need arguments
if (command.args && !args.length) {
let reply = `You didn't provide any arguments, ${message.author}!`;
if (command.usage) {
reply += `\nThe proper usage would be: \`${env.prefix}${command.name} ${command.usage}\``;
}
return message.channel.send(reply);
}
try{
command.execute(message, args);
}catch(error){
console.log(error);
}
});