Skip to content

Commit

Permalink
add delete button to highlight messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot121 authored and Meta Construct committed Dec 25, 2024
1 parent e825fe9 commit d817987
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/services/Starboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ export class Starboard extends Service {
constructor(container: Container) {
super(container);
this.sql = this.container.getService("SQL");

const bot = this.container.getService("DiscordBot");
if (bot) {
const filter = (btn: Discord.MessageComponentInteraction) =>
btn.customId.startsWith("starboard");

bot.discord.on("interactionCreate", async interaction => {
if (!interaction.isButton()) return;
if (!filter(interaction)) return;
if (interaction.message.author.username !== interaction.user.username) return;

const [, originalMsgID, originalChannelID] = interaction.customId.split(":");

const res = await interaction.message.delete().catch(console.error);
if (res) {
bot.getTextChannel(bot.config.channels.log)?.send(
`Highlighted Message in ${interaction.channel} deleted by ${interaction.user} (${interaction.user.id}) -> https://discord.com/channels/${interaction.guildId}/${originalChannelID}/${originalMsgID}`
);
}
});
}
}

async isMsgStarred(msgId: string): Promise<boolean> {
Expand Down Expand Up @@ -167,6 +188,12 @@ export class Starboard extends Service {
style: Discord.ButtonStyle.Link,
url: msg.url,
},
{
type: Discord.ComponentType.Button,
label: "Delete",
style: Discord.ButtonStyle.Danger,
customId: `starboard:${msg.id}:${msg.channelId}`,
},
],
},
],
Expand Down

0 comments on commit d817987

Please sign in to comment.