This repository was archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (51 loc) · 2.02 KB
/
index.js
File metadata and controls
57 lines (51 loc) · 2.02 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
const Discord = require('discord.js');
const fs = require('fs');
const Keyv = require('keyv');
const { prefix, discord_api_token, redis_connection_string } = require('./config.json');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
const canvas_access_tokens = new Keyv(redis_connection_string, { namespace: 'canvas_access_tokens' });
canvas_access_tokens.on('error', e => console.error('Keyv connection error:', e));
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity('everybody 😶', { type: 'WATCHING' });
});
client.on('message', async message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
console.log(message.author.username + ': ' + message.content);
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'token') {
client.commands.get('token').execute(message, args, canvas_access_tokens);
}
else {
const canvas_access_token = await canvas_access_tokens.get(message.author.id);
if (canvas_access_token === undefined) {
message.channel.send('First tell me your Canvas Access Token in a dm using: ```!token <canvas_access_token>```');
return;
}
if (command === 'courses') {
client.commands.get('courses').execute(message, canvas_access_token);
return;
}
if (command === 'favorites') {
client.commands.get('favorites').execute(message, canvas_access_token);
return;
}
if (command === 'name') {
client.commands.get('name').execute(message, canvas_access_token);
return;
}
if (command === 'profile') {
client.commands.get('profile').execute(message, canvas_access_token);
return;
}
message.channel.send('Error: command not found');
}
});
client.login(discord_api_token).catch((e) => console.error('Discord.js', e));