2020-07-28 21:34:01 +03:00
|
|
|
import * as t from "io-ts";
|
2021-04-28 21:42:54 +02:00
|
|
|
import {
|
2021-06-06 23:51:32 +02:00
|
|
|
convertDelayStringToMS,
|
|
|
|
nonNullish,
|
|
|
|
|
|
|
|
tDelayString,
|
|
|
|
tNullable,
|
|
|
|
unique
|
2021-04-28 21:42:54 +02:00
|
|
|
} from "../../../utils";
|
2021-04-02 19:36:40 +03:00
|
|
|
import { CaseArgs } from "../../Cases/types";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
|
|
|
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
|
|
|
import { automodAction } from "../helpers";
|
2020-07-28 21:34:01 +03:00
|
|
|
|
|
|
|
export const BanAction = automodAction({
|
|
|
|
configType: t.type({
|
|
|
|
reason: tNullable(t.string),
|
2021-04-28 21:42:54 +02:00
|
|
|
duration: tNullable(tDelayString),
|
2020-07-28 21:34:01 +03:00
|
|
|
notify: tNullable(t.string),
|
|
|
|
notifyChannel: tNullable(t.string),
|
|
|
|
deleteMessageDays: tNullable(t.number),
|
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";
|
2021-04-28 21:42:54 +02:00
|
|
|
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : undefined;
|
2020-12-03 16:55:53 +02:00
|
|
|
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined;
|
2020-11-09 20:03:57 +02:00
|
|
|
const deleteMessageDays = actionConfig.deleteMessageDays || undefined;
|
2020-07-28 21:34:01 +03:00
|
|
|
|
2021-04-02 19:36:40 +03:00
|
|
|
const caseArgs: Partial<CaseArgs> = {
|
2021-06-01 02:05:55 +02: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 userIdsToBan = unique(contexts.map(c => c.user?.id).filter(nonNullish));
|
2020-07-28 21:34:01 +03:00
|
|
|
|
|
|
|
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
|
|
|
for (const userId of userIdsToBan) {
|
2021-04-28 21:42:54 +02:00
|
|
|
await modActions.banUserId(
|
|
|
|
userId,
|
|
|
|
reason,
|
|
|
|
{
|
|
|
|
contactMethods,
|
|
|
|
caseArgs,
|
|
|
|
deleteMessageDays,
|
|
|
|
isAutomodAction: true,
|
|
|
|
},
|
|
|
|
duration,
|
|
|
|
);
|
2020-07-28 21:34:01 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|