Add postInCaseLog option for mod action Automod actions; allow forcing case log even when log_automatic_actions is disabled

This commit is contained in:
Dragory 2021-04-28 22:39:49 +03:00
parent aa43f05173
commit 45e81848a7
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
7 changed files with 18 additions and 13 deletions

View file

@ -12,6 +12,7 @@ export const BanAction = automodAction({
notify: tNullable(t.string), notify: tNullable(t.string),
notifyChannel: tNullable(t.string), notifyChannel: tNullable(t.string),
deleteMessageDays: tNullable(t.number), deleteMessageDays: tNullable(t.number),
postInCaseLog: tNullable(t.boolean),
}), }),
defaultConfig: { defaultConfig: {
@ -27,6 +28,7 @@ export const BanAction = automodAction({
modId: pluginData.client.user.id, modId: pluginData.client.user.id,
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [], extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
automatic: true, automatic: true,
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,
}; };
const userIdsToBan = unique(contexts.map(c => c.user?.id).filter(nonNullish)); const userIdsToBan = unique(contexts.map(c => c.user?.id).filter(nonNullish));

View file

@ -11,6 +11,7 @@ export const KickAction = automodAction({
reason: tNullable(t.string), reason: tNullable(t.string),
notify: tNullable(t.string), notify: tNullable(t.string),
notifyChannel: tNullable(t.string), notifyChannel: tNullable(t.string),
postInCaseLog: tNullable(t.boolean),
}), }),
defaultConfig: { defaultConfig: {
@ -25,6 +26,7 @@ export const KickAction = automodAction({
modId: pluginData.client.user.id, modId: pluginData.client.user.id,
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [], extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
automatic: true, automatic: true,
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,
}; };
const userIdsToKick = unique(contexts.map(c => c.user?.id).filter(nonNullish)); const userIdsToKick = unique(contexts.map(c => c.user?.id).filter(nonNullish));

View file

@ -25,6 +25,7 @@ export const MuteAction = automodAction({
notifyChannel: tNullable(t.string), notifyChannel: tNullable(t.string),
remove_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])), remove_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])),
restore_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])), restore_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])),
postInCaseLog: tNullable(t.boolean),
}), }),
defaultConfig: { defaultConfig: {
@ -42,6 +43,7 @@ export const MuteAction = automodAction({
modId: pluginData.client.user.id, modId: pluginData.client.user.id,
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [], extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
automatic: true, automatic: true,
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,
}; };
const userIdsToMute = unique(contexts.map(c => c.user?.id).filter(nonNullish)); const userIdsToMute = unique(contexts.map(c => c.user?.id).filter(nonNullish));

View file

@ -11,6 +11,7 @@ export const WarnAction = automodAction({
reason: tNullable(t.string), reason: tNullable(t.string),
notify: tNullable(t.string), notify: tNullable(t.string),
notifyChannel: tNullable(t.string), notifyChannel: tNullable(t.string),
postInCaseLog: tNullable(t.boolean),
}), }),
defaultConfig: { defaultConfig: {
@ -25,6 +26,7 @@ export const WarnAction = automodAction({
modId: pluginData.client.user.id, modId: pluginData.client.user.id,
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [], extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
automatic: true, automatic: true,
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,
}; };
const userIdsToWarn = unique(contexts.map(c => c.user?.id).filter(nonNullish)); const userIdsToWarn = unique(contexts.map(c => c.user?.id).filter(nonNullish));

View file

@ -62,11 +62,11 @@ export async function createCase(pluginData: GuildPluginData<CasesPluginType>, a
const config = pluginData.config.get(); const config = pluginData.config.get();
if ( const shouldPostToCaseLogChannel =
config.case_log_channel && args.postInCaseLogOverride === true ||
(!args.automatic || config.log_automatic_actions) && ((!args.automatic || config.log_automatic_actions) && args.postInCaseLogOverride !== false);
args.postInCaseLogOverride !== false
) { if (config.case_log_channel && shouldPostToCaseLogChannel) {
await postCaseToCaseLogChannel(pluginData, createdCase); await postCaseToCaseLogChannel(pluginData, createdCase);
} }

View file

@ -47,7 +47,10 @@ export async function createCaseNote(pluginData: GuildPluginData<CasesPluginType
} }
const modConfig = pluginData.config.getForUser(mod); const modConfig = pluginData.config.getForUser(mod);
if ((!args.automatic || modConfig.log_automatic_actions) && args.postInCaseLogOverride !== false) { if (
args.postInCaseLogOverride === true ||
((!args.automatic || modConfig.log_automatic_actions) && args.postInCaseLogOverride !== false)
) {
await postCaseToCaseLogChannel(pluginData, theCase.id); await postCaseToCaseLogChannel(pluginData, theCase.id);
} }
} }

View file

@ -188,8 +188,6 @@ export async function muteUser(
if (theCase) { if (theCase) {
// Update old case // Update old case
// Since mutes can often have multiple notes (extraNotes), we won't post each case note individually,
// but instead we'll post the entire case afterwards
const noteDetails = [`Mute updated to ${muteTime ? timeUntilUnmute : "indefinite"}`]; const noteDetails = [`Mute updated to ${muteTime ? timeUntilUnmute : "indefinite"}`];
const reasons = reason ? [reason] : []; const reasons = reason ? [reason] : [];
if (muteOptions.caseArgs?.extraNotes) { if (muteOptions.caseArgs?.extraNotes) {
@ -201,13 +199,9 @@ export async function muteUser(
modId: muteOptions.caseArgs?.modId, modId: muteOptions.caseArgs?.modId,
body: noteReason, body: noteReason,
noteDetails, noteDetails,
postInCaseLogOverride: false, postInCaseLogOverride: muteOptions.caseArgs?.postInCaseLogOverride,
}); });
} }
if (muteOptions.caseArgs?.postInCaseLogOverride !== false) {
casesPlugin.postCaseToCaseLogChannel(existingMute!.case_id);
}
} else { } else {
// Create new case // Create new case
const noteDetails = [`Muted ${muteTime ? `for ${timeUntilUnmute}` : "indefinitely"}`]; const noteDetails = [`Muted ${muteTime ? `for ${timeUntilUnmute}` : "indefinitely"}`];