backup: guildBanAdd.js need more inspection

This commit is contained in:
Neko-Life 2021-08-01 20:27:09 +07:00
parent af01df4b07
commit 222ebfc6e3
3 changed files with 22 additions and 13 deletions

View file

@ -17,8 +17,9 @@ module.exports = async (GUILD, USER) => {
const emb = defaultEventLogEmbed(GUILD);
let audit;
if (GUILD.member(GUILD.client.user).hasPermission("VIEW_AUDIT_LOG")) {
audit = (await GUILD.fetchAuditLogs({ limit: 1, type: "MEMBER_BAN_ADD" })).entries.first();
console.log(audit);
const the = (await GUILD.fetchAuditLogs({ limit: 1, type: "MEMBER_BAN_ADD" })).entries.first();
console.log(the);
if (the.target.id === USER.id) audit = the;
emb.setDescription(audit?.reason || "No reason provided");
} else emb.setDescription("Unknown reason");

View file

@ -17,15 +17,16 @@ module.exports = async (memberold, membernew) => {
};
return membernew.user.setDb("cachedAvatarURL", membernew.user.DB.cachedAvatarURL);
}
let log, thumbMes = "";
let log, thumbMes = "", audit, auditPerm, nullReason = false;
const emb = defaultEventLogEmbed(membernew.guild), oldT = memberold.toJSON().displayAvatarURL;
const oldAV = membernew.user.DB.cachedAvatarURL || oldT;
if (oldAV) thumbMes += "This embed's thumbnail is the user's old avatar.\n";
let audit, auditPerm;
if (membernew.guild.DB.eventChannels?.memberRole) {
log = getChannel(membernew, membernew.guild.DB.eventChannels.memberRole);
if (membernew.guild.member(membernew.client.user).hasPermission("VIEW_AUDIT_LOG")) {
audit = (await membernew.guild.fetchAuditLogs({ limit: 1, type: "MEMBER_ROLE_UPDATE" })).entries.first();
console.log("FETCH UPDATE LOG", membernew.user.tag);
const the = (await membernew.guild.fetchAuditLogs({ limit: 1, type: "MEMBER_ROLE_UPDATE" })).entries.first();
if (the.target.id === memberold.id) audit = the;
auditPerm = true;
}
if (membernew.roles.cache.size > memberold.roles.cache.size) {
@ -53,26 +54,32 @@ module.exports = async (memberold, membernew) => {
log = getChannel(membernew, membernew.guild.DB.eventChannels.member);
if (membernew.displayName !== memberold.displayName) {
if (membernew.guild.member(membernew.client.user).hasPermission("VIEW_AUDIT_LOG")) {
audit = (await membernew.guild.fetchAuditLogs({ limit: 1, type: "MEMBER_UPDATE" })).entries.first();
console.log("FETCH NICK LOG", membernew.user.tag);
const the = (await membernew.guild.fetchAuditLogs({ limit: 1, type: "MEMBER_UPDATE" })).entries.first();
if (the.target.id === memberold.id) audit = the;
if (the.executor.id === memberold.id) nullReason = true;
auditPerm = true;
}
emb.addField("Current Nickname", "`" + membernew.displayName + "`")
.addField("Original Nickname", "`" + memberold.displayName + "`")
}
if (membernew.user.DB.cachedAvatarURL !== NEWAV) {
emb
.setImage(NEWAV)
nullReason = true;
emb.setImage(NEWAV)
.addField("Avatar", thumbMes + "The image below is the user's new avatar.");
if (oldAV) emb.setThumbnail(oldAV);
}
}
console.log(audit);
emb.setAuthor(emb.author.name, NEWAV)
.setTitle("Profile `" + memberold.user.tag + "` updated" +
(audit?.executor ? ` by \`${audit.executor.tag}\`` : ""))
.setColor(getColor("blue"));
if (auditPerm) {
emb.setDescription((audit?.reason || "No reason provided") + (emb.description ? "\n\n" + emb.description : ""));
} else emb.setDescription("Unknown reason\n\n" + emb.description);
if (!nullReason) {
if (auditPerm) {
emb.setDescription((audit?.reason || "No reason provided") + (emb.description ? "\n\n" + emb.description : ""));
} else emb.setDescription("Unknown reason\n\n" + (emb.description ? "\n\n" + emb.description : ""));
}
membernew.user.DB.cachedAvatarURL = NEWAV;
membernew.user.setDb("cachedAvatarURL", membernew.user.DB.cachedAvatarURL);
if (!emb.fields || emb.fields.length === 0) return;

View file

@ -20,10 +20,11 @@ module.exports = async (msg) => {
const emb = defaultEventLogEmbed(msg.guild);
let audit;
if (msg.guild.member(msg.client.user).hasPermission("VIEW_AUDIT_LOG")) {
audit = (await msg.guild.fetchAuditLogs({ limit: 1, type: "MESSAGE_DELETE" })).entries.first().executor;
const the = (await msg.guild.fetchAuditLogs({ limit: 1, type: "MESSAGE_DELETE" })).entries.first();
if (the.target.id === msg.id) audit = the;
}
emb.setColor(getColor("yellow"))
.setTitle((!msg.webhookID ? "Message " + msg.id : "Webhook " + msg.webhookID) + " deleted" + (audit ? ` by \`${audit.tag}\`` : ""))
.setTitle((!msg.webhookID ? "Message " + msg.id : "Webhook " + msg.webhookID) + " deleted" + (audit?.executor ? ` by \`${audit.executor.tag}\`` : ""))
.setDescription(msg.content.length > 0 ? msg.content : "`[EMPTY]`")
.setAuthor(emb.author.name, msg.author?.displayAvatarURL({ format: "png", size: 128, dynamic: true }))
.addField("Author", `<@!${msg.author?.id}>\n\`${msg.author?.tag}\`\n(${msg.author?.id})`, true)