2020-07-28 21:34:01 +03:00
|
|
|
import * as t from "io-ts";
|
|
|
|
import { automodAction } from "../helpers";
|
|
|
|
import { LogType } from "../../../data/LogType";
|
2020-07-29 22:58:14 +03:00
|
|
|
import { asyncMap, convertDelayStringToMS, resolveMember, tDelayString, tNullable, unique } from "../../../utils";
|
2020-07-28 21:34:01 +03:00
|
|
|
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
|
|
|
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
|
|
|
import { MutesPlugin } from "../../Mutes/MutesPlugin";
|
|
|
|
|
|
|
|
export const MuteAction = automodAction({
|
|
|
|
configType: t.type({
|
|
|
|
reason: tNullable(t.string),
|
|
|
|
duration: tNullable(tDelayString),
|
|
|
|
notify: tNullable(t.string),
|
|
|
|
notifyChannel: tNullable(t.string),
|
|
|
|
}),
|
|
|
|
|
2020-07-30 01:45:14 +03:00
|
|
|
defaultConfig: {
|
|
|
|
notify: null, // Use defaults from ModActions
|
|
|
|
},
|
|
|
|
|
2020-07-28 21:51:58 +03:00
|
|
|
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
2020-07-28 21:34:01 +03:00
|
|
|
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration) : null;
|
|
|
|
const reason = actionConfig.reason || "Muted automatically";
|
|
|
|
const contactMethods = resolveActionContactMethods(pluginData, actionConfig);
|
|
|
|
|
|
|
|
const caseArgs = {
|
|
|
|
modId: pluginData.client.user.id,
|
2020-07-30 01:45:14 +03:00
|
|
|
extraNotes: [matchResult.fullSummary],
|
2020-07-28 21:34:01 +03:00
|
|
|
};
|
|
|
|
|
2020-07-29 22:58:14 +03:00
|
|
|
const userIdsToMute = unique(contexts.map(c => c.user?.id).filter(Boolean));
|
2020-07-28 21:34:01 +03:00
|
|
|
|
|
|
|
const mutes = pluginData.getPlugin(MutesPlugin);
|
|
|
|
for (const userId of userIdsToMute) {
|
|
|
|
await mutes.muteUser(userId, duration, reason, { contactMethods, caseArgs });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|