Allow automod to issue tempbans (#189)
This commit is contained in:
parent
3d549b4e78
commit
903a2369c8
5 changed files with 36 additions and 15 deletions
|
@ -1,7 +1,15 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodAction } from "../helpers";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { asyncMap, nonNullish, resolveMember, tNullable, unique } from "../../../utils";
|
||||
import {
|
||||
asyncMap,
|
||||
convertDelayStringToMS,
|
||||
nonNullish,
|
||||
resolveMember,
|
||||
tDelayString,
|
||||
tNullable,
|
||||
unique,
|
||||
} from "../../../utils";
|
||||
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
||||
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
|
@ -9,6 +17,7 @@ import { CaseArgs } from "../../Cases/types";
|
|||
export const BanAction = automodAction({
|
||||
configType: t.type({
|
||||
reason: tNullable(t.string),
|
||||
duration: tNullable(tDelayString),
|
||||
notify: tNullable(t.string),
|
||||
notifyChannel: tNullable(t.string),
|
||||
deleteMessageDays: tNullable(t.number),
|
||||
|
@ -21,6 +30,7 @@ export const BanAction = automodAction({
|
|||
|
||||
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
||||
const reason = actionConfig.reason || "Kicked automatically";
|
||||
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : undefined;
|
||||
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined;
|
||||
const deleteMessageDays = actionConfig.deleteMessageDays || undefined;
|
||||
|
||||
|
@ -35,12 +45,17 @@ export const BanAction = automodAction({
|
|||
|
||||
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
||||
for (const userId of userIdsToBan) {
|
||||
await modActions.banUserId(userId, reason, {
|
||||
contactMethods,
|
||||
caseArgs,
|
||||
deleteMessageDays,
|
||||
isAutomodAction: true,
|
||||
});
|
||||
await modActions.banUserId(
|
||||
userId,
|
||||
reason,
|
||||
{
|
||||
contactMethods,
|
||||
caseArgs,
|
||||
deleteMessageDays,
|
||||
isAutomodAction: true,
|
||||
},
|
||||
duration,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -166,8 +166,8 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()("mod
|
|||
},
|
||||
|
||||
banUserId(pluginData) {
|
||||
return (userId: string, reason?: string, banOptions?: BanOptions) => {
|
||||
banUserId(pluginData, userId, reason, banOptions);
|
||||
return (userId: string, reason?: string, banOptions?: BanOptions, banTime?: number) => {
|
||||
banUserId(pluginData, userId, reason, banOptions, banTime);
|
||||
};
|
||||
},
|
||||
|
||||
|
|
|
@ -172,6 +172,7 @@ export const BanCmd = modActionsCmd({
|
|||
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
|
||||
},
|
||||
deleteMessageDays,
|
||||
modId: mod.id,
|
||||
},
|
||||
time,
|
||||
);
|
||||
|
@ -184,12 +185,6 @@ export const BanCmd = modActionsCmd({
|
|||
|
||||
let forTime = "";
|
||||
if (time && time > 0) {
|
||||
if (existingTempban) {
|
||||
pluginData.state.tempbans.updateExpiryTime(user.id, time, mod.id);
|
||||
} else {
|
||||
pluginData.state.tempbans.addTempban(user.id, time, mod.id);
|
||||
}
|
||||
|
||||
forTime = `for ${humanizeDuration(time)} `;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,16 @@ export async function banUserId(
|
|||
};
|
||||
}
|
||||
|
||||
const existingTempban = await pluginData.state.tempbans.findExistingTempbanForUserId(user.id);
|
||||
if (banTime && banTime > 0) {
|
||||
const selfId = pluginData.client.user.id;
|
||||
if (existingTempban) {
|
||||
pluginData.state.tempbans.updateExpiryTime(user.id, banTime, banOptions.modId ?? selfId);
|
||||
} else {
|
||||
pluginData.state.tempbans.addTempban(user.id, banTime, banOptions.modId ?? selfId);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a case for this action
|
||||
const modId = banOptions.caseArgs?.modId || pluginData.client.user.id;
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
|
|
|
@ -139,6 +139,7 @@ export interface BanOptions {
|
|||
caseArgs?: Partial<CaseArgs>;
|
||||
contactMethods?: UserNotificationMethod[];
|
||||
deleteMessageDays?: number;
|
||||
modId?: string;
|
||||
isAutomodAction?: boolean;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue