This repository has been archived by the owner on May 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
88 lines (74 loc) · 2.63 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
const App = require('./app');
const app = new App();
app.discordClient.login(process.env.TOKEN);
app.discordClient.once('ready', () => {
//get all messages
try {
let channels = app.discordClient.channels.cache.filter(c => c.type == 'text').array();
for (let channel of channels) {
channel.fetch()
.then(c => {
c.messages.fetch();
}).catch(err => {console.error(err)});
}
app.discordClient.user.setActivity("_help", {type: "WATCHING"});
}
catch (err) {
console.error(err);
}
console.log(`discordClient loged in as ${app.discordClient.user.username} ${app.discordClient.user}`);
});
app.discordClient.on('messageReactionAdd', (reaction, user) => {
if (user.bot || user === reaction.message.author || reaction.message.author.bot) return;
var change;
if (app.config.upvoteEmoji.includes(reaction.emoji.name)) {
change = [1, 1, 0]
}
else if (app.config.downvoteEmoji.includes(reaction.emoji.name)) {
change = [-1, 0, 1]
}
else return;
app.vote_reaction.updateUserData(
app,
reaction.message.guild.id,
reaction.message.channel.id,
{_id: reaction.message.author.id},
{$inc: {score: change[0], upvotes: change[1], downvotes: change[2]}},
reaction.message.member
);
});
app.discordClient.on('messageReactionRemove', (reaction, user) => {
if (user.bot || user === reaction.message.author || reaction.message.author.bot) return;
var change;
if (app.config.upvoteEmoji == reaction.emoji.name) {
change = [-1, -1, 0]
}
else if (app.config.downvoteEmoji == reaction.emoji.name) {
change = [1, 0, -1]
}
else return;
app.vote_reaction.updateUserData(
app,
reaction.message.guild.id,
reaction.message.channel.id,
{_id: reaction.message.author.id},
{$inc: {score: change[0], upvotes: change[1], downvotes: change[2]}},
reaction.message.member
);
});
app.discordClient.on('message', message => {
if (!message.content.startsWith(app.config.prefix) || message.author.bot) return;
const args = message.content.slice(app.config.prefix.length).split(/ +/);
const commandName = args.shift().toLowerCase();
// check if command exists, check for aliases
const command = app.commands.get(commandName)
|| app.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
try {
command.execute(message, args, app);
}
catch (err) {
console.log(message.content);
console.error(err);
};
});