Skip to content

Commit d817987

Browse files
Techbot121Meta Construct
authored andcommitted
add delete button to highlight messages
1 parent e825fe9 commit d817987

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

app/services/Starboard.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ export class Starboard extends Service {
1616
constructor(container: Container) {
1717
super(container);
1818
this.sql = this.container.getService("SQL");
19+
20+
const bot = this.container.getService("DiscordBot");
21+
if (bot) {
22+
const filter = (btn: Discord.MessageComponentInteraction) =>
23+
btn.customId.startsWith("starboard");
24+
25+
bot.discord.on("interactionCreate", async interaction => {
26+
if (!interaction.isButton()) return;
27+
if (!filter(interaction)) return;
28+
if (interaction.message.author.username !== interaction.user.username) return;
29+
30+
const [, originalMsgID, originalChannelID] = interaction.customId.split(":");
31+
32+
const res = await interaction.message.delete().catch(console.error);
33+
if (res) {
34+
bot.getTextChannel(bot.config.channels.log)?.send(
35+
`Highlighted Message in ${interaction.channel} deleted by ${interaction.user} (${interaction.user.id}) -> https://discord.com/channels/${interaction.guildId}/${originalChannelID}/${originalMsgID}`
36+
);
37+
}
38+
});
39+
}
1940
}
2041

2142
async isMsgStarred(msgId: string): Promise<boolean> {
@@ -167,6 +188,12 @@ export class Starboard extends Service {
167188
style: Discord.ButtonStyle.Link,
168189
url: msg.url,
169190
},
191+
{
192+
type: Discord.ComponentType.Button,
193+
label: "Delete",
194+
style: Discord.ButtonStyle.Danger,
195+
customId: `starboard:${msg.id}:${msg.channelId}`,
196+
},
170197
],
171198
},
172199
],

0 commit comments

Comments
 (0)