codePreviews: add react to delete

This commit is contained in:
Cynthia Foxwell 2023-05-12 13:55:24 -06:00
parent 7eb41af2df
commit 9462411e56
1 changed files with 37 additions and 0 deletions

View File

@ -144,3 +144,40 @@ events.add("messageCreate", "codePreviews", async function (msg) {
}
}
});
// TODO: maybe all command outputs should have this ability
events.add(
"messageReactionAdd",
"codePreviews",
async function (msg, reaction, reactor) {
if (!msg.guildID) return;
if (!(await hasFlag(msg.guildID, "codePreviews"))) return;
if (reaction.name != "\u274c") return;
let channel = msg.channel;
if (!channel.name) {
channel = hf.bot.getChannel(channel.id);
}
if (!msg.messageReference) {
msg = await channel.getMessage(msg.id);
}
if (!msg.messageReference) return;
const ref = await channel.getMessage(msg.messageReference.messageID);
if (!ref) return;
if (
ref.author.id != reactor.id ||
!channel.permissionsOf(reactor.id).has("manageMessages")
)
return;
if (
!REGEX_GITHUB.test(ref.content) &&
!REGEX_GITLAB.test(ref.content) &&
!REGEX_GITEA.test(ref.content)
)
return;
await msg.delete("Author requested code preview deletion");
}
);