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 * as t from "io-ts";
|
||||||
import { automodAction } from "../helpers";
|
import { automodAction } from "../helpers";
|
||||||
import { LogType } from "../../../data/LogType";
|
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 { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
||||||
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
||||||
import { CaseArgs } from "../../Cases/types";
|
import { CaseArgs } from "../../Cases/types";
|
||||||
|
@ -9,6 +17,7 @@ import { CaseArgs } from "../../Cases/types";
|
||||||
export const BanAction = automodAction({
|
export const BanAction = automodAction({
|
||||||
configType: t.type({
|
configType: t.type({
|
||||||
reason: tNullable(t.string),
|
reason: tNullable(t.string),
|
||||||
|
duration: tNullable(tDelayString),
|
||||||
notify: tNullable(t.string),
|
notify: tNullable(t.string),
|
||||||
notifyChannel: tNullable(t.string),
|
notifyChannel: tNullable(t.string),
|
||||||
deleteMessageDays: tNullable(t.number),
|
deleteMessageDays: tNullable(t.number),
|
||||||
|
@ -21,6 +30,7 @@ export const BanAction = automodAction({
|
||||||
|
|
||||||
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
async apply({ pluginData, contexts, actionConfig, matchResult }) {
|
||||||
const reason = actionConfig.reason || "Kicked automatically";
|
const reason = actionConfig.reason || "Kicked automatically";
|
||||||
|
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : undefined;
|
||||||
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined;
|
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined;
|
||||||
const deleteMessageDays = actionConfig.deleteMessageDays || undefined;
|
const deleteMessageDays = actionConfig.deleteMessageDays || undefined;
|
||||||
|
|
||||||
|
@ -35,12 +45,17 @@ export const BanAction = automodAction({
|
||||||
|
|
||||||
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
||||||
for (const userId of userIdsToBan) {
|
for (const userId of userIdsToBan) {
|
||||||
await modActions.banUserId(userId, reason, {
|
await modActions.banUserId(
|
||||||
|
userId,
|
||||||
|
reason,
|
||||||
|
{
|
||||||
contactMethods,
|
contactMethods,
|
||||||
caseArgs,
|
caseArgs,
|
||||||
deleteMessageDays,
|
deleteMessageDays,
|
||||||
isAutomodAction: true,
|
isAutomodAction: true,
|
||||||
});
|
},
|
||||||
|
duration,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -166,8 +166,8 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()("mod
|
||||||
},
|
},
|
||||||
|
|
||||||
banUserId(pluginData) {
|
banUserId(pluginData) {
|
||||||
return (userId: string, reason?: string, banOptions?: BanOptions) => {
|
return (userId: string, reason?: string, banOptions?: BanOptions, banTime?: number) => {
|
||||||
banUserId(pluginData, userId, reason, banOptions);
|
banUserId(pluginData, userId, reason, banOptions, banTime);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,7 @@ export const BanCmd = modActionsCmd({
|
||||||
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
|
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
|
||||||
},
|
},
|
||||||
deleteMessageDays,
|
deleteMessageDays,
|
||||||
|
modId: mod.id,
|
||||||
},
|
},
|
||||||
time,
|
time,
|
||||||
);
|
);
|
||||||
|
@ -184,12 +185,6 @@ export const BanCmd = modActionsCmd({
|
||||||
|
|
||||||
let forTime = "";
|
let forTime = "";
|
||||||
if (time && time > 0) {
|
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)} `;
|
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
|
// Create a case for this action
|
||||||
const modId = banOptions.caseArgs?.modId || pluginData.client.user.id;
|
const modId = banOptions.caseArgs?.modId || pluginData.client.user.id;
|
||||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||||
|
|
|
@ -139,6 +139,7 @@ export interface BanOptions {
|
||||||
caseArgs?: Partial<CaseArgs>;
|
caseArgs?: Partial<CaseArgs>;
|
||||||
contactMethods?: UserNotificationMethod[];
|
contactMethods?: UserNotificationMethod[];
|
||||||
deleteMessageDays?: number;
|
deleteMessageDays?: number;
|
||||||
|
modId?: string;
|
||||||
isAutomodAction?: boolean;
|
isAutomodAction?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue