2020-07-28 21:34:01 +03:00
|
|
|
import * as t from "io-ts";
|
|
|
|
import { automodAction } from "../helpers";
|
|
|
|
import { LogType } from "../../../data/LogType";
|
2020-11-09 20:03:57 +02:00
|
|
|
import { asyncMap, nonNullish, resolveMember, tNullable, unique } from "../../../utils";
|
2020-07-28 21:34:01 +03:00
|
|
|
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
|
|
|
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
2021-04-02 19:36:40 +03:00
|
|
|
import { CaseArgs } from "../../Cases/types";
|
2020-07-28 21:34:01 +03:00
|
|
|
|
|
|
|
export const KickAction = automodAction({
|
|
|
|
configType: t.type({
|
|
|
|
reason: tNullable(t.string),
|
|
|
|
notify: tNullable(t.string),
|
|
|
|
notifyChannel: tNullable(t.string),
|
2021-04-28 22:39:49 +03:00
|
|
|
postInCaseLog: tNullable(t.boolean),
|
2021-05-03 19:40:59 +03:00
|
|
|
hide_case: tNullable(t.boolean),
|
2020-07-28 21:34:01 +03:00
|
|
|
}),
|
|
|
|
|
2020-07-30 01:45:14 +03:00
|
|
|
defaultConfig: {
|
|
|
|
notify: null, // Use defaults from ModActions
|
2021-05-03 18:49:52 +03:00
|
|
|
hide_case: false,
|
2020-07-30 01:45:14 +03:00
|
|
|
},
|
|
|
|
|
2020-07-28 21:51:58 +03:00
|
|
|
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
2020-07-28 21:34:01 +03:00
|
|
|
const reason = actionConfig.reason || "Kicked automatically";
|
2020-12-03 16:55:53 +02:00
|
|
|
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined;
|
2020-07-28 21:34:01 +03:00
|
|
|
|
2021-04-02 19:36:40 +03:00
|
|
|
const caseArgs: Partial<CaseArgs> = {
|
2020-07-28 21:34:01 +03:00
|
|
|
modId: pluginData.client.user.id,
|
2020-11-09 20:03:57 +02:00
|
|
|
extraNotes: matchResult.fullSummary ? [matchResult.fullSummary] : [],
|
2021-04-02 19:36:40 +03:00
|
|
|
automatic: true,
|
2021-04-28 22:39:49 +03:00
|
|
|
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined,
|
2021-05-03 19:40:59 +03:00
|
|
|
hide: Boolean(actionConfig.hide_case),
|
2020-07-28 21:34:01 +03:00
|
|
|
};
|
|
|
|
|
2020-11-09 20:03:57 +02:00
|
|
|
const userIdsToKick = unique(contexts.map(c => c.user?.id).filter(nonNullish));
|
2020-07-28 21:34:01 +03:00
|
|
|
const membersToKick = await asyncMap(userIdsToKick, id => resolveMember(pluginData.client, pluginData.guild, id));
|
|
|
|
|
|
|
|
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
|
|
|
for (const member of membersToKick) {
|
2020-11-09 20:03:57 +02:00
|
|
|
if (!member) continue;
|
2021-04-28 21:06:33 +02:00
|
|
|
await modActions.kickMember(member, reason, { contactMethods, caseArgs, isAutomodAction: true });
|
2020-07-28 21:34:01 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|