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 * 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),
|
||||||
|
@ -20,6 +29,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;
|
||||||
|
|
||||||
|
@ -33,7 +43,7 @@ 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, { contactMethods, caseArgs, deleteMessageDays });
|
await modActions.banUserId(userId, reason, { contactMethods, caseArgs, deleteMessageDays }, duration);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -165,8 +165,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);
|
||||||
|
|
|
@ -137,6 +137,7 @@ export interface BanOptions {
|
||||||
caseArgs?: Partial<CaseArgs>;
|
caseArgs?: Partial<CaseArgs>;
|
||||||
contactMethods?: UserNotificationMethod[];
|
contactMethods?: UserNotificationMethod[];
|
||||||
deleteMessageDays?: number;
|
deleteMessageDays?: number;
|
||||||
|
modId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban" | "unban";
|
export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban" | "unban";
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rimraf dist && cross-env NODE_ENV=production webpack --config webpack.config.js",
|
"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",
|
"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"
|
"watch-build": "rimraf dist && NODE_ENV=development webpack --config webpack.config.js --watch"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue