forked from replit-discord/repl-it-starboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarRemove.js
More file actions
70 lines (64 loc) · 2.25 KB
/
Copy pathstarRemove.js
File metadata and controls
70 lines (64 loc) · 2.25 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
const { Event } = require('klasa');
const { MessageEmbed } = require('discord.js');
module.exports = class extends Event {
constructor(...args) {
super(...args, {
name: 'starRemove',
event: 'messageReactionRemove',
emitter: 'client'
});
}
async run(react, user) {
let reaction = react.partial ? await react.fetch() : react;
let msg = reaction.message.partial
? await reaction.message.fetch()
: reaction.message;
if (msg.guild) {
if (!this.client.cachedData.get(msg.guild.id))
this.client.cachedData.set(
msg.guild.id,
await this.client.db.getGuild(msg.guild.id).catch(console.error)
);
let guildData = this.client.cachedData.get(msg.guild.id);
if (guildData) {
if (msg.guild.channels.cache.has(guildData.channel)) {
if (Object.keys(guildData.starred).includes(msg.id)) {
let stars = (await reaction.users.fetch())
.filter(u => u.id !== msg.author.id)
.map(v => v.id);
let message = await msg.guild.channels.cache
.get(guildData.channel)
.messages.fetch(guildData.starred[msg.id].embedId)
.catch(console.error);
if (message) {
let embed = new MessageEmbed()
.setTitle('View Message')
.addField('Author', msg.author, true)
.addField('Channel', msg.channel, true)
.setTimestamp(msg.editedTimestamp || msg.createdTimestamp)
.setThumbnail(msg.author.displayAvatarURL())
.setColor('YELLOW')
.setURL(msg.url)
.setFooter(`${stars.length} stars ( ${reaction.emoji} )`);
if (msg.content) embed.addField('Content', msg.content);
if (msg.attachments.size > 0)
embed.setImage(msg.attachments.first().url);
let data = {
stars: this.client.db.util.removeFromArray(user.id)
};
let temp = guildData.starred[msg.id].stars;
temp.push(...stars);
temp.slice(temp.indexOf(user.id), 1);
guildData.starred[msg.id].stars = [...new Set(temp)];
guildData.members[msg.author.id] -= 1;
this.client.cachedData.set(msg.guild.id, guildData);
await message.edit(embed);
await this.client.db.updateStar(msg.guild.id, msg.id, data);
await this.client.db.modifyStars(msg.guild.id, msg.author.id, -1);
}
}
}
}
}
}
};