1 |
import { MessageAttachment, MessageReaction, TextChannel, User } from "discord.js"; |
2 |
import DiscordClient from "../client/Client"; |
3 |
import MessageEmbed from "../client/MessageEmbed"; |
4 |
|
5 |
export default class Starboard { |
6 |
constructor(private client: DiscordClient) { |
7 |
|
8 |
} |
9 |
|
10 |
async handle(reaction: MessageReaction) { |
11 |
if (this.client.config.get('starboard').enabled) { |
12 |
let emoji = reaction.emoji.name; |
13 |
|
14 |
console.log(emoji); |
15 |
|
16 |
if (emoji === '⭐' && reaction.message.channel.id !== this.client.config.get('starboard').channel && reaction.count === this.client.config.get('starboard').reactions) { |
17 |
try { |
18 |
const channel = <TextChannel> await reaction.message.guild!.channels.fetch(this.client.config.get('starboard').channel); |
19 |
|
20 |
let props = { |
21 |
embeds: reaction.message.embeds || [] |
22 |
}; |
23 |
|
24 |
const msg = await channel.send({ |
25 |
embeds: [ |
26 |
...props.embeds, |
27 |
new MessageEmbed() |
28 |
.setAuthor({ |
29 |
name: reaction.message.author!.tag, |
30 |
iconURL: reaction.message.author!.displayAvatarURL(), |
31 |
}) |
32 |
.setDescription(reaction.message.content!) |
33 |
.addField('URL', `[Click here](${reaction.message.url})`) |
34 |
.setTimestamp() |
35 |
.setFooter({ |
36 |
text: reaction.message.id + '' |
37 |
}) |
38 |
], |
39 |
files: reaction.message.attachments.map(a => { |
40 |
return { |
41 |
name: a.name, |
42 |
attachment: a.proxyURL |
43 |
} as MessageAttachment |
44 |
}) |
45 |
}); |
46 |
|
47 |
await msg.react('⭐'); |
48 |
} |
49 |
catch (e) { |
50 |
console.log(e); |
51 |
} |
52 |
} |
53 |
} |
54 |
} |
55 |
}; |