mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
automod: add triggers for mod actions
This commit is contained in:
parent
5ffc3e7cc4
commit
93912541b4
34 changed files with 412 additions and 3 deletions
|
@ -39,6 +39,10 @@ import { DeleteCaseCmd } from "./commands/DeleteCaseCmd";
|
|||
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
|
||||
import { GuildTempbans } from "../../data/GuildTempbans";
|
||||
import { outdatedTempbansLoop } from "./functions/outdatedTempbansLoop";
|
||||
import { EventEmitter } from "events";
|
||||
import { mapToPublicFn } from "../../pluginUtils";
|
||||
import { onModActionsEvent } from "./functions/onModActionsEvent";
|
||||
import { offModActionsEvent } from "./functions/offModActionsEvent";
|
||||
|
||||
const defaultOptions = {
|
||||
config: {
|
||||
|
@ -165,6 +169,12 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()("mod
|
|||
banUserId(pluginData, userId, reason, banOptions);
|
||||
};
|
||||
},
|
||||
|
||||
on: mapToPublicFn(onModActionsEvent),
|
||||
off: mapToPublicFn(offModActionsEvent),
|
||||
getEventEmitter(pluginData) {
|
||||
return () => pluginData.state.events;
|
||||
},
|
||||
},
|
||||
|
||||
onLoad(pluginData) {
|
||||
|
@ -179,10 +189,13 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()("mod
|
|||
state.outdatedTempbansTimeout = null;
|
||||
state.ignoredEvents = [];
|
||||
|
||||
state.events = new EventEmitter();
|
||||
|
||||
outdatedTempbansLoop(pluginData);
|
||||
},
|
||||
|
||||
onUnload(pluginData) {
|
||||
pluginData.state.unloaded = true;
|
||||
pluginData.state.events.removeAllListeners();
|
||||
},
|
||||
});
|
||||
|
|
|
@ -67,6 +67,7 @@ export const ForcebanCmd = modActionsCmd({
|
|||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, user.id);
|
||||
|
||||
try {
|
||||
// FIXME: Use banUserId()?
|
||||
await pluginData.guild.banMember(user.id, 1, reason != null ? encodeURIComponent(reason) : undefined);
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Failed to forceban member");
|
||||
|
@ -93,5 +94,7 @@ export const ForcebanCmd = modActionsCmd({
|
|||
caseNumber: createdCase.case_number,
|
||||
reason,
|
||||
});
|
||||
|
||||
pluginData.state.events.emit("ban", user.id, reason);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -75,6 +75,8 @@ export const MassbanCmd = modActionsCmd({
|
|||
reason: `Mass ban: ${banReason}`,
|
||||
postInCaseLogOverride: false,
|
||||
});
|
||||
|
||||
pluginData.state.events.emit("ban", userId, banReason);
|
||||
} catch (e) {
|
||||
failedBans.push(userId);
|
||||
}
|
||||
|
|
|
@ -49,5 +49,7 @@ export const NoteCmd = modActionsCmd({
|
|||
});
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, `Note added on **${userName}** (Case #${createdCase.case_number})`);
|
||||
|
||||
pluginData.state.events.emit("note", user.id, reason);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -112,5 +112,7 @@ export const WarnCmd = modActionsCmd({
|
|||
msg.channel,
|
||||
`Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${warnResult.case.case_number})${messageResultText}`,
|
||||
);
|
||||
|
||||
pluginData.state.events.emit("warn", user.id, reason);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -69,5 +69,7 @@ export const CreateBanCaseOnManualBanEvt = modActionsEvt(
|
|||
caseNumber: createdCase?.case_number ?? 0,
|
||||
reason,
|
||||
});
|
||||
|
||||
pluginData.state.events.emit("ban", user.id, reason);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -62,6 +62,8 @@ export const CreateKickCaseOnManualKickEvt = modActionsEvt(
|
|||
mod: mod ? stripObjectToScalars(mod) : null,
|
||||
caseNumber: createdCase?.case_number ?? 0,
|
||||
});
|
||||
|
||||
pluginData.state.events.emit("kick", member.id, kickAuditLogEntry.reason || undefined);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
@ -66,5 +66,7 @@ export const CreateUnbanCaseOnManualUnbanEvt = modActionsEvt(
|
|||
userId: user.id,
|
||||
caseNumber: createdCase?.case_number ?? 0,
|
||||
});
|
||||
|
||||
pluginData.state.events.emit("unban", user.id);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -127,6 +127,8 @@ export async function banUserId(
|
|||
banTime: banTime ? humanizeDuration(banTime) : null,
|
||||
});
|
||||
|
||||
pluginData.state.events.emit("ban", user.id, reason);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
case: createdCase,
|
||||
|
|
|
@ -85,6 +85,8 @@ export async function kickMember(
|
|||
reason,
|
||||
});
|
||||
|
||||
pluginData.state.events.emit("kick", member.id, reason);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
case: createdCase,
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { ModActionsEvents, ModActionsPluginType } from "../types";
|
||||
|
||||
export function offModActionsEvent<TEvent extends keyof ModActionsEvents>(
|
||||
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||
event: TEvent,
|
||||
listener: ModActionsEvents[TEvent],
|
||||
) {
|
||||
return pluginData.state.events.off(event, listener);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { ModActionsEvents, ModActionsPluginType } from "../types";
|
||||
|
||||
export function onModActionsEvent<TEvent extends keyof ModActionsEvents>(
|
||||
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||
event: TEvent,
|
||||
listener: ModActionsEvents[TEvent],
|
||||
) {
|
||||
return pluginData.state.events.on(event, listener);
|
||||
}
|
|
@ -9,6 +9,7 @@ import { CaseArgs } from "../Cases/types";
|
|||
import { TextChannel } from "eris";
|
||||
import { GuildTempbans } from "../../data/GuildTempbans";
|
||||
import Timeout = NodeJS.Timeout;
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
export const ConfigSchema = t.type({
|
||||
dm_on_warn: t.boolean,
|
||||
|
@ -45,6 +46,20 @@ export const ConfigSchema = t.type({
|
|||
});
|
||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||
|
||||
export interface ModActionsEvents {
|
||||
note: (userId: string, reason?: string) => void;
|
||||
warn: (userId: string, reason?: string) => void;
|
||||
kick: (userId: string, reason?: string) => void;
|
||||
ban: (userId: string, reason?: string) => void;
|
||||
unban: (userId: string, reason?: string) => void;
|
||||
// mute/unmute are in the Mutes plugin
|
||||
}
|
||||
|
||||
export interface ModActionsEventEmitter extends EventEmitter {
|
||||
on<U extends keyof ModActionsEvents>(event: U, listener: ModActionsEvents[U]): this;
|
||||
emit<U extends keyof ModActionsEvents>(event: U, ...args: Parameters<ModActionsEvents[U]>): boolean;
|
||||
}
|
||||
|
||||
export interface ModActionsPluginType extends BasePluginType {
|
||||
config: TConfigSchema;
|
||||
state: {
|
||||
|
@ -56,6 +71,8 @@ export interface ModActionsPluginType extends BasePluginType {
|
|||
unloaded: boolean;
|
||||
outdatedTempbansTimeout: Timeout | null;
|
||||
ignoredEvents: IIgnoredEvent[];
|
||||
|
||||
events: ModActionsEventEmitter;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -122,5 +139,7 @@ export interface BanOptions {
|
|||
deleteMessageDays?: number;
|
||||
}
|
||||
|
||||
export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban" | "unban";
|
||||
|
||||
export const modActionsCmd = guildCommand<ModActionsPluginType>();
|
||||
export const modActionsEvt = guildEventListener<ModActionsPluginType>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue