3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Start move to configAccessibleObjects, exclude perm overrides from logs

configAccessibleObjects are used to guarantee backwards compatibility and consistency.
Perm overrides from our own plugins are ignored as to not spam logs through bot managed slowmode or companion channels
This commit is contained in:
Dark 2021-07-06 05:23:47 +02:00
parent dda19de6e6
commit d2dd103175
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
28 changed files with 259 additions and 75 deletions

View file

@ -1,5 +1,6 @@
import { channelToConfigAccessibleChannel } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
import { differenceToString, getScalarDifference } from "../../../utils";
import { logsEvt } from "../types";
export const LogsChannelCreateEvt = logsEvt({
@ -7,7 +8,7 @@ export const LogsChannelCreateEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_CREATE, {
channel: stripObjectToScalars(meta.args.channel),
channel: channelToConfigAccessibleChannel(meta.args.channel),
});
},
});
@ -17,7 +18,7 @@ export const LogsChannelDeleteEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_DELETE, {
channel: stripObjectToScalars(meta.args.channel),
channel: channelToConfigAccessibleChannel(meta.args.channel),
});
},
});
@ -29,10 +30,14 @@ export const LogsChannelUpdateEvt = logsEvt({
const diff = getScalarDifference(meta.args.oldChannel, meta.args.newChannel);
const differenceString = differenceToString(diff);
meta.pluginData.state.guildLogs.log(LogType.CHANNEL_UPDATE, {
oldChannel: stripObjectToScalars(meta.args.oldChannel),
newChannel: stripObjectToScalars(meta.args.newChannel),
differenceString,
});
meta.pluginData.state.guildLogs.log(
LogType.CHANNEL_UPDATE,
{
oldChannel: channelToConfigAccessibleChannel(meta.args.oldChannel),
newChannel: channelToConfigAccessibleChannel(meta.args.newChannel),
differenceString,
},
meta.args.newChannel.id,
);
},
});

View file

@ -1,6 +1,6 @@
import { GuildAuditLogs } from "discord.js";
import { userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars, UnknownUser } from "../../../utils";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { logsEvt } from "../types";
@ -16,13 +16,13 @@ export const LogsGuildBanAddEvt = logsEvt({
GuildAuditLogs.Actions.MEMBER_BAN_ADD as number,
user.id,
);
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
pluginData.state.guildLogs.log(
LogType.MEMBER_BAN,
{
mod: stripObjectToScalars(mod),
user: stripObjectToScalars(user),
mod: mod ? userToConfigAccessibleUser(mod) : {},
user: userToConfigAccessibleUser(user),
},
user.id,
);
@ -41,12 +41,12 @@ export const LogsGuildBanRemoveEvt = logsEvt({
GuildAuditLogs.Actions.MEMBER_BAN_REMOVE as number,
user.id,
);
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
pluginData.state.guildLogs.log(
LogType.MEMBER_UNBAN,
{
mod: stripObjectToScalars(mod),
mod: mod ? userToConfigAccessibleUser(mod) : {},
userId: user.id,
},
user.id,

View file

@ -1,5 +1,6 @@
import humanizeDuration from "humanize-duration";
import moment from "moment-timezone";
import { memberToConfigAccessibleMember } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars } from "../../../utils";
import { CasesPlugin } from "../../Cases/CasesPlugin";
@ -46,7 +47,7 @@ export const LogsGuildMemberAddEvt = logsEvt({
}
pluginData.state.guildLogs.log(LogType.MEMBER_JOIN_WITH_PRIOR_RECORDS, {
member: stripObjectToScalars(member, ["user", "roles"]),
member: memberToConfigAccessibleMember(member),
recentCaseSummary,
});
}

View file

@ -1,5 +1,5 @@
import { memberToConfigAccessibleMember } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars } from "../../../utils";
import { logsEvt } from "../types";
export const LogsGuildMemberRemoveEvt = logsEvt({
@ -7,7 +7,7 @@ export const LogsGuildMemberRemoveEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.MEMBER_LEAVE, {
member: stripObjectToScalars(meta.args.member, ["user", "roles"]),
member: memberToConfigAccessibleMember(meta.args.member),
});
},
});

View file

@ -1,5 +1,6 @@
import { roleToConfigAccessibleRole } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
import { differenceToString, getScalarDifference } from "../../../utils";
import { logsEvt } from "../types";
export const LogsRoleCreateEvt = logsEvt({
@ -7,7 +8,7 @@ export const LogsRoleCreateEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.ROLE_CREATE, {
role: stripObjectToScalars(meta.args.role),
role: roleToConfigAccessibleRole(meta.args.role),
});
},
});
@ -17,7 +18,7 @@ export const LogsRoleDeleteEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.ROLE_DELETE, {
role: stripObjectToScalars(meta.args.role),
role: roleToConfigAccessibleRole(meta.args.role),
});
},
});
@ -30,8 +31,8 @@ export const LogsRoleUpdateEvt = logsEvt({
const differenceString = differenceToString(diff);
meta.pluginData.state.guildLogs.log(LogType.ROLE_UPDATE, {
newRole: stripObjectToScalars(meta.args.newRole),
oldRole: stripObjectToScalars(meta.args.oldRole),
newRole: roleToConfigAccessibleRole(meta.args.newRole),
oldRole: roleToConfigAccessibleRole(meta.args.oldRole),
differenceString,
});
},

View file

@ -1,3 +1,4 @@
import { channelToConfigAccessibleChannel, stageToConfigAccessibleStage } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { differenceToString, getScalarDifference, stripObjectToScalars } from "../../../utils";
import { logsEvt } from "../types";
@ -8,10 +9,11 @@ export const LogsStageInstanceCreateEvt = logsEvt({
async listener(meta) {
const stageChannel =
meta.args.stageInstance.channel ??
(await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelId));
(await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelId))!;
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_CREATE, {
stageInstance: stripObjectToScalars(meta.args.stageInstance),
stageChannel: stripObjectToScalars(stageChannel),
stageInstance: stageToConfigAccessibleStage(meta.args.stageInstance),
stageChannel: channelToConfigAccessibleChannel(stageChannel),
});
},
});
@ -22,10 +24,11 @@ export const LogsStageInstanceDeleteEvt = logsEvt({
async listener(meta) {
const stageChannel =
meta.args.stageInstance.channel ??
(await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelId));
(await meta.pluginData.guild.channels.fetch(meta.args.stageInstance.channelId))!;
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_DELETE, {
stageInstance: stripObjectToScalars(meta.args.stageInstance),
stageChannel: stripObjectToScalars(stageChannel),
stageInstance: stageToConfigAccessibleStage(meta.args.stageInstance),
stageChannel: channelToConfigAccessibleChannel(stageChannel),
});
},
});
@ -36,15 +39,15 @@ export const LogsStageInstanceUpdateEvt = logsEvt({
async listener(meta) {
const stageChannel =
meta.args.newStageInstance.channel ??
(await meta.pluginData.guild.channels.fetch(meta.args.newStageInstance.channelId));
(await meta.pluginData.guild.channels.fetch(meta.args.newStageInstance.channelId))!;
const diff = getScalarDifference(meta.args.oldStageInstance, meta.args.newStageInstance);
const differenceString = differenceToString(diff);
meta.pluginData.state.guildLogs.log(LogType.STAGE_INSTANCE_UPDATE, {
oldStageInstance: stripObjectToScalars(meta.args.oldStageInstance),
newStageInstance: stripObjectToScalars(meta.args.newStageInstance),
stageChannel: stripObjectToScalars(stageChannel),
oldStageInstance: stageToConfigAccessibleStage(meta.args.oldStageInstance),
newStageInstance: stageToConfigAccessibleStage(meta.args.newStageInstance),
stageChannel: channelToConfigAccessibleChannel(stageChannel),
differenceString,
});
},

View file

@ -1,3 +1,4 @@
import { channelToConfigAccessibleChannel } from "../../../utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars, getScalarDifference, differenceToString } from "../../../utils";
import { logsEvt } from "../types";
@ -7,7 +8,7 @@ export const LogsThreadCreateEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.THREAD_CREATE, {
thread: stripObjectToScalars(meta.args.thread),
thread: channelToConfigAccessibleChannel(meta.args.thread),
});
},
});
@ -17,7 +18,7 @@ export const LogsThreadDeleteEvt = logsEvt({
async listener(meta) {
meta.pluginData.state.guildLogs.log(LogType.THREAD_DELETE, {
thread: stripObjectToScalars(meta.args.thread),
thread: channelToConfigAccessibleChannel(meta.args.thread),
});
},
});
@ -29,10 +30,14 @@ export const LogsThreadUpdateEvt = logsEvt({
const diff = getScalarDifference(meta.args.oldThread, meta.args.newThread, ["messageCount", "archiveTimestamp"]);
const differenceString = differenceToString(diff);
meta.pluginData.state.guildLogs.log(LogType.THREAD_UPDATE, {
oldThread: stripObjectToScalars(meta.args.oldThread),
newThread: stripObjectToScalars(meta.args.newThread),
differenceString,
});
meta.pluginData.state.guildLogs.log(
LogType.THREAD_UPDATE,
{
oldThread: channelToConfigAccessibleChannel(meta.args.oldThread),
newThread: channelToConfigAccessibleChannel(meta.args.newThread),
differenceString,
},
meta.args.newThread.id,
);
},
});

View file

@ -1,8 +1,8 @@
import { GuildAuditLogs } from "discord.js";
import diff from "lodash.difference";
import isEqual from "lodash.isequal";
import { memberToConfigAccessibleMember, userToConfigAccessibleUser } from "src/utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars, UnknownUser } from "../../../utils";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { logsEvt } from "../types";
@ -16,7 +16,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
if (!oldMember) return;
const logMember = stripObjectToScalars(member, ["user", "roles"]);
const logMember = memberToConfigAccessibleMember(member);
if (member.nickname !== oldMember.nickname) {
pluginData.state.guildLogs.log(LogType.MEMBER_NICK_CHANGE, {
@ -52,7 +52,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
GuildAuditLogs.Actions.MEMBER_ROLE_UPDATE as number,
member.id,
);
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : new UnknownUser();
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
if (addedRoles.length && removedRoles.length) {
// Roles added *and* removed
@ -68,7 +68,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name)
.join(", "),
mod: stripObjectToScalars(mod),
mod: mod ? userToConfigAccessibleUser(mod) : {},
},
member.id,
);
@ -82,7 +82,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name)
.join(", "),
mod: stripObjectToScalars(mod),
mod: mod ? userToConfigAccessibleUser(mod) : {},
},
member.id,
);
@ -96,7 +96,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
.map(r => r.name)
.join(", "),
mod: stripObjectToScalars(mod),
mod: mod ? userToConfigAccessibleUser(mod) : {},
},
member.id,
);

View file

@ -1,3 +1,4 @@
import { channelToConfigAccessibleChannel, memberToConfigAccessibleMember } from "src/utils/configAccessibleObjects";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars } from "../../../utils";
import { logsEvt } from "../types";
@ -10,25 +11,23 @@ export const LogsVoiceStateUpdateEvt = logsEvt({
const newChannel = meta.args.newState.channel;
const member = meta.args.newState.member ?? meta.args.oldState.member!;
if (!newChannel) {
if (!newChannel && oldChannel) {
// Leave evt
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_LEAVE, {
member: stripObjectToScalars(member, ["user", "roles"]),
oldChannel: stripObjectToScalars(oldChannel),
newChannel: stripObjectToScalars(newChannel),
member: memberToConfigAccessibleMember(member),
oldChannel: channelToConfigAccessibleChannel(oldChannel!),
});
} else if (!oldChannel) {
} else if (!oldChannel && newChannel) {
// Join Evt
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_JOIN, {
member: stripObjectToScalars(member, ["user", "roles"]),
oldChannel: stripObjectToScalars(oldChannel),
newChannel: stripObjectToScalars(newChannel),
member: memberToConfigAccessibleMember(member),
newChannel: channelToConfigAccessibleChannel(newChannel),
});
} else {
meta.pluginData.state.guildLogs.log(LogType.VOICE_CHANNEL_MOVE, {
member: stripObjectToScalars(member, ["user", "roles"]),
oldChannel: stripObjectToScalars(oldChannel),
newChannel: stripObjectToScalars(newChannel),
member: memberToConfigAccessibleMember(member),
oldChannel: channelToConfigAccessibleChannel(oldChannel!),
newChannel: channelToConfigAccessibleChannel(newChannel!),
});
}
},