2020-07-28 21:34:01 +03:00
|
|
|
import * as t from "io-ts";
|
|
|
|
import { automodAction } from "../helpers";
|
2020-07-28 21:51:58 +03:00
|
|
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
|
|
|
import { LogType } from "../../../data/LogType";
|
2020-07-30 02:21:11 +03:00
|
|
|
import { stripObjectToScalars, unique } from "../../../utils";
|
2020-07-28 21:34:01 +03:00
|
|
|
|
|
|
|
export const LogAction = automodAction({
|
|
|
|
configType: t.boolean,
|
2020-07-30 01:45:14 +03:00
|
|
|
defaultConfig: true,
|
2020-07-28 21:34:01 +03:00
|
|
|
|
2020-07-28 21:51:58 +03:00
|
|
|
async apply({ pluginData, contexts, ruleName, matchResult }) {
|
2020-07-30 02:21:11 +03:00
|
|
|
const safeUsers = unique(contexts.map(c => c.user))
|
|
|
|
.filter(Boolean)
|
|
|
|
.map(user => stripObjectToScalars(user));
|
2020-07-28 21:51:58 +03:00
|
|
|
const safeUser = safeUsers[0];
|
2020-07-29 22:43:33 +03:00
|
|
|
const actionsTaken = Object.keys(pluginData.config.get().rules[ruleName].actions).join(", ");
|
2020-07-28 21:51:58 +03:00
|
|
|
|
|
|
|
pluginData.getPlugin(LogsPlugin).log(LogType.AUTOMOD_ACTION, {
|
|
|
|
rule: ruleName,
|
|
|
|
user: safeUser,
|
|
|
|
users: safeUsers,
|
|
|
|
actionsTaken,
|
|
|
|
matchSummary: matchResult.summary,
|
|
|
|
});
|
2020-07-28 21:34:01 +03:00
|
|
|
},
|
|
|
|
});
|