Skip to content

Commit

Permalink
additional check for author
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot121 authored and Meta Construct committed Jan 4, 2025
1 parent f4a2374 commit 02e3361
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions app/services/Starboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,33 @@ export class Starboard extends Service {
this.sql = await this.container.getService("SQL");
this.bot = await this.container.getService("DiscordBot");

const filter = (btn: Discord.MessageComponentInteraction) =>
btn.customId.startsWith("starboard");
const filter = (btn: Discord.MessageComponentInteraction) =>
btn.customId.startsWith("starboard");

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

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

// additional check in case the username was changed somehow
if (originalAuthorID && originalAuthorID !== interaction.user.id) return;

try {
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}`
);
this.bot
.getTextChannel(this.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}`
);
}
});
}
} catch (error) {
console.error("[Starboard] Error deleting message:", error);
}
});
}

async isMsgStarred(msgId: string): Promise<boolean> {
Expand Down Expand Up @@ -191,7 +200,9 @@ export class Starboard extends Service {
new Discord.ButtonBuilder()
.setLabel("Delete")
.setStyle(Discord.ButtonStyle.Danger)
.setCustomId(`starboard:${msg.id}:${msg.channelId}`),
.setCustomId(
`starboard:${msg.id}:${msg.channelId}:${msg.author.id}`
),
]
: [])
),
Expand Down

0 comments on commit 02e3361

Please sign in to comment.