mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-20 16:25:03 +00:00
Allow automod to issue tempbans
This commit is contained in:
parent
c26ab2977f
commit
769888f7d2
6 changed files with 27 additions and 11 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),
|
||||
|
@ -20,6 +29,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;
|
||||
|
||||
|
@ -33,7 +43,7 @@ export const BanAction = automodAction({
|
|||
|
||||
const modActions = pluginData.getPlugin(ModActionsPlugin);
|
||||
for (const userId of userIdsToBan) {
|
||||
await modActions.banUserId(userId, reason, { contactMethods, caseArgs, deleteMessageDays });
|
||||
await modActions.banUserId(userId, reason, { contactMethods, caseArgs, deleteMessageDays }, duration);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -165,8 +165,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);
|
||||
|
|
|
@ -137,6 +137,7 @@ export interface BanOptions {
|
|||
caseArgs?: Partial<CaseArgs>;
|
||||
contactMethods?: UserNotificationMethod[];
|
||||
deleteMessageDays?: number;
|
||||
modId?: string;
|
||||
}
|
||||
|
||||
export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban" | "unban";
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"scripts": {
|
||||
"build": "rimraf dist && cross-env NODE_ENV=production webpack --config webpack.config.js",
|
||||
"build-debug": "rimraf dist && cross-env NODE_ENV=development webpack --config webpack.config.js",
|
||||
"watch": "cross-env NODE_ENV=development webpack-dev-server",
|
||||
"watch": "cross-env NODE_ENV=development webpack-dev-server --disable-host-check",
|
||||
"watch-build": "rimraf dist && NODE_ENV=development webpack --config webpack.config.js --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue