mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 04:45:02 +00:00
Migrate ModActions to new Plugin structure !!mutes dont work!!
This commit is contained in:
parent
ebcb28261b
commit
fd56664984
29 changed files with 1213 additions and 16 deletions
107
backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts
Normal file
107
backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts
Normal file
|
@ -0,0 +1,107 @@
|
|||
import { Member, TextChannel } from "eris";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import { IgnoredEventType, ModActionsPluginType } from "../types";
|
||||
import { errorMessage, resolveUser, resolveMember } from "src/utils";
|
||||
import { PluginData } from "knub";
|
||||
import { sendErrorMessage, canActOn, sendSuccessMessage } from "src/pluginUtils";
|
||||
import { hasPermission } from "knub/dist/helpers";
|
||||
import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs";
|
||||
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
|
||||
import { kickMember } from "./kickMember";
|
||||
import { ignoreEvent } from "./ignoreEvent";
|
||||
import { isBanned } from "./isBanned";
|
||||
|
||||
export async function actualKickMemberCmd(
|
||||
pluginData: PluginData<ModActionsPluginType>,
|
||||
msg,
|
||||
args: {
|
||||
user: string;
|
||||
reason: string;
|
||||
mod: Member;
|
||||
notify?: string;
|
||||
"notify-channel"?: TextChannel;
|
||||
clean?: boolean;
|
||||
},
|
||||
) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
|
||||
const memberToKick = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
if (!memberToKick) {
|
||||
const banned = await isBanned(pluginData, user.id);
|
||||
if (banned) {
|
||||
sendErrorMessage(pluginData, msg.channel, `User is banned`);
|
||||
} else {
|
||||
sendErrorMessage(pluginData, msg.channel, `User not found on the server`);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we're allowed to kick this member
|
||||
if (!canActOn(pluginData, msg.member, memberToKick)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Cannot kick: insufficient permissions");
|
||||
return;
|
||||
}
|
||||
|
||||
// The moderator who did the action is the message author or, if used, the specified -mod
|
||||
let mod = msg.member;
|
||||
if (args.mod) {
|
||||
if (!hasPermission(pluginData.config.getForMessage(msg), "can_act_as_other")) {
|
||||
sendErrorMessage(pluginData, msg.channel, "No permission for -mod");
|
||||
return;
|
||||
}
|
||||
|
||||
mod = args.mod;
|
||||
}
|
||||
|
||||
let contactMethods;
|
||||
try {
|
||||
contactMethods = readContactMethodsFromArgs(args);
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
|
||||
|
||||
const kickResult = await kickMember(pluginData, memberToKick, reason, {
|
||||
contactMethods,
|
||||
caseArgs: {
|
||||
modId: mod.id,
|
||||
ppId: mod.id !== msg.author.id ? msg.author.id : null,
|
||||
},
|
||||
});
|
||||
|
||||
if (args.clean) {
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, memberToKick.id);
|
||||
ignoreEvent(pluginData, IgnoredEventType.Ban, memberToKick.id);
|
||||
|
||||
try {
|
||||
await memberToKick.ban(1);
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Failed to ban the user to clean messages (-clean)");
|
||||
}
|
||||
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, memberToKick.id);
|
||||
ignoreEvent(pluginData, IgnoredEventType.Unban, memberToKick.id);
|
||||
|
||||
try {
|
||||
await pluginData.guild.unbanMember(memberToKick.id);
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Failed to unban the user after banning them (-clean)");
|
||||
}
|
||||
}
|
||||
|
||||
if (kickResult.status === "failed") {
|
||||
msg.channel.createMessage(errorMessage(`Failed to kick user`));
|
||||
return;
|
||||
}
|
||||
|
||||
// Confirm the action to the moderator
|
||||
let response = `Kicked **${memberToKick.user.username}#${memberToKick.user.discriminator}** (Case #${kickResult.case.case_number})`;
|
||||
|
||||
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
|
||||
sendSuccessMessage(pluginData, msg.channel, response);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
import { PluginData } from "knub";
|
||||
import { ModActionsPluginType } from "../types";
|
||||
import { User, Message, Member } from "eris";
|
||||
import { UnknownUser, asSingleLine } from "src/utils";
|
||||
import { sendErrorMessage, sendSuccessMessage, hasPermission } from "src/pluginUtils";
|
||||
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
|
||||
import { MutesPlugin } from "src/plugins/Mutes/MutesPlugin";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
|
||||
export async function actualUnmuteCmd(
|
||||
pluginData: PluginData<ModActionsPluginType>,
|
||||
user: User | UnknownUser,
|
||||
msg: Message,
|
||||
args: { time?: number; reason?: string; mod?: Member },
|
||||
) {
|
||||
// The moderator who did the action is the message author or, if used, the specified -mod
|
||||
let mod = msg.author;
|
||||
let pp = null;
|
||||
|
||||
if (args.mod) {
|
||||
if (!hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id })) {
|
||||
sendErrorMessage(pluginData, msg.channel, "No permission for -mod");
|
||||
return;
|
||||
}
|
||||
|
||||
mod = args.mod.user;
|
||||
pp = msg.author;
|
||||
}
|
||||
|
||||
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
|
||||
|
||||
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
|
||||
const result = await mutesPlugin.unmuteUser(user.id, args.time, {
|
||||
modId: mod.id,
|
||||
ppId: pp && pp.id,
|
||||
reason,
|
||||
});
|
||||
|
||||
// Confirm the action to the moderator
|
||||
if (args.time) {
|
||||
const timeUntilUnmute = args.time && humanizeDuration(args.time);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
asSingleLine(`
|
||||
Unmuting **${user.username}#${user.discriminator}**
|
||||
in ${timeUntilUnmute} (Case #${result.case.case_number})
|
||||
`),
|
||||
);
|
||||
} else {
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
asSingleLine(`
|
||||
Unmuted **${user.username}#${user.discriminator}**
|
||||
(Case #${result.case.case_number})
|
||||
`),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import { PluginData } from "knub";
|
||||
import { IgnoredEventType, ModActionsPluginType } from "../types";
|
||||
|
||||
export function clearIgnoredEvent(
|
||||
export function clearIgnoredEvents(
|
||||
pluginData: PluginData<ModActionsPluginType>,
|
||||
type: IgnoredEventType,
|
||||
userId: string,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { PluginData } from "knub";
|
||||
import { IgnoredEventType, ModActionsPluginType } from "../types";
|
||||
import { SECONDS } from "../../../utils";
|
||||
import { clearIgnoredEvent } from "./clearIgnoredEvents";
|
||||
import { clearIgnoredEvents } from "./clearIgnoredEvents";
|
||||
|
||||
const DEFAULT_TIMEOUT = 15 * SECONDS;
|
||||
|
||||
|
@ -15,6 +15,6 @@ export function ignoreEvent(
|
|||
|
||||
// Clear after expiry (15sec by default)
|
||||
setTimeout(() => {
|
||||
clearIgnoredEvent(pluginData, type, userId);
|
||||
clearIgnoredEvents(pluginData, type, userId);
|
||||
}, timeout);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue