/[sudobot]/trunk/src/services/Starboard.ts
ViewVC logotype

Annotation of /trunk/src/services/Starboard.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 226 - (hide annotations)
Mon Jul 29 17:29:06 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2208 byte(s)
refactor: make all services inherit a base class
1 rakin 51 import { MessageAttachment, MessageReaction, TextChannel, User } from "discord.js";
2     import DiscordClient from "../client/Client";
3     import MessageEmbed from "../client/MessageEmbed";
4 rakin 226 import Service from "../utils/structures/Service";
5 rakin 33
6 rakin 226 export default class Starboard extends Service {
7 rakin 51 async handle(reaction: MessageReaction) {
8     if (this.client.config.get('starboard').enabled) {
9     let emoji = reaction.emoji.name;
10 rakin 33
11 rakin 51 console.log(emoji);
12 rakin 33
13 rakin 51 if (emoji === '⭐' && reaction.message.channel.id !== this.client.config.get('starboard').channel && reaction.count === this.client.config.get('starboard').reactions) {
14 rakin 33 try {
15 rakin 51 const channel = <TextChannel> await reaction.message.guild!.channels.fetch(this.client.config.get('starboard').channel);
16 rakin 33
17     let props = {
18     embeds: reaction.message.embeds || []
19 rakin 51 };
20 rakin 33
21     const msg = await channel.send({
22     embeds: [
23     ...props.embeds,
24     new MessageEmbed()
25     .setAuthor({
26 rakin 51 name: reaction.message.author!.tag,
27     iconURL: reaction.message.author!.displayAvatarURL(),
28 rakin 33 })
29 rakin 51 .setDescription(reaction.message.content!)
30 rakin 33 .addField('URL', `[Click here](${reaction.message.url})`)
31     .setTimestamp()
32     .setFooter({
33     text: reaction.message.id + ''
34     })
35     ],
36     files: reaction.message.attachments.map(a => {
37     return {
38     name: a.name,
39     attachment: a.proxyURL
40 rakin 51 } as MessageAttachment
41 rakin 33 })
42     });
43    
44     await msg.react('⭐');
45     }
46     catch (e) {
47     console.log(e);
48     }
49     }
50     }
51     }
52     };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26