Release/1.0.0 #14

Merged
AstroGD merged 21 commits from release/1.0.0 into main 2022-11-29 03:21:57 +01:00
Showing only changes of commit 5eb56efb79 - Show all commits

View File

@ -1,5 +1,5 @@
import client from "../client"; import client from "../client";
import { Events } from "discord.js"; import { AuditLogEvent, Events, GuildAuditLogsEntry, PermissionFlagsBits, User } from "discord.js";
import { getGuildSetting } from "../tools/data"; import { getGuildSetting } from "../tools/data";
import { Badword, database } from "../data"; import { Badword, database } from "../data";
import { IsNull } from "typeorm"; import { IsNull } from "typeorm";
@ -39,6 +39,33 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
if (found === null) return; if (found === null) return;
let responsibleUser: User | null;
try {
const clientMember = await guild.members.fetchMe();
const canSeeAuditLog = clientMember.permissions.has(PermissionFlagsBits.ViewAuditLog);
const auditLogs = canSeeAuditLog ? await guild.fetchAuditLogs({
type: AuditLogEvent.ChannelUpdate,
limit: 50
}) : undefined;
const change = auditLogs?.entries.filter((entry) => {
if (entry.target.id !== newChannel.id) return false;
return entry.changes.filter((change) => {
return change.key === "name" && change.new === newChannel.name;
}).length > 0;
}).reduce<null | GuildAuditLogsEntry<AuditLogEvent.ChannelUpdate, "Update", "Channel", AuditLogEvent.ChannelUpdate>>((unknown, curr) => {
if (!unknown) return curr;
const prev = unknown as GuildAuditLogsEntry<AuditLogEvent.ChannelUpdate, "Update", "Channel", AuditLogEvent.ChannelUpdate>
return curr.createdTimestamp > prev.createdTimestamp ? curr : prev;
}, null);
responsibleUser = change?.executor || null;
} catch (error) {
responsibleUser = null;
}
const logChannel = settings.notificationChannelID ? await getGuildChannel(guild.id, settings.notificationChannelID) : null; const logChannel = settings.notificationChannelID ? await getGuildChannel(guild.id, settings.notificationChannelID) : null;
try { try {
@ -51,6 +78,9 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
embed.addFields({ embed.addFields({
name: "Detected banned word:", name: "Detected banned word:",
value: `||${found}||` value: `||${found}||`
}, {
name: "Channel renamed by:",
value: responsibleUser ? `${responsibleUser.tag} (${responsibleUser.id})` : "`Couldn't detect responsible user :(`"
}); });
logChannel.send({ logChannel.send({
@ -68,6 +98,9 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
name: "Detected banned word:", name: "Detected banned word:",
value: `||${found}||`, value: `||${found}||`,
inline: true inline: true
}, {
name: "Channel renamed by:",
value: responsibleUser ? `${responsibleUser.tag} (${responsibleUser.id})` : "`Couldn't detect responsible user :(`"
}); });
logChannel.send({ logChannel.send({