3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Finish preliminary rework, ready to test

This commit is contained in:
Dark 2021-06-02 04:07:50 +02:00
parent 57893e7f76
commit d0a1beb809
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
177 changed files with 854 additions and 707 deletions

View file

@ -9,6 +9,7 @@ import { MutesPlugin } from "../../Mutes/MutesPlugin";
import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { logger } from "../../../logger";
import { User, Message, TextChannel, GuildMember } from "discord.js";
/**
* The actual function run by both !mute and !forcemute.
@ -17,16 +18,16 @@ import { logger } from "../../../logger";
export async function actualMuteUserCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
user: User | UnknownUser,
msg: Message<GuildTextableChannel>,
args: { time?: number; reason?: string; mod: Member; notify?: string; "notify-channel"?: TextChannel },
msg: Message,
args: { time?: number; reason?: string; mod: GuildMember; notify?: string; "notify-channel"?: TextChannel },
) {
// The moderator who did the action is the message author or, if used, the specified -mod
let mod: Member = msg.member;
let mod: GuildMember = msg.member!;
let pp: User | null = null;
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
sendErrorMessage(pluginData, msg.channel as TextChannel, "You don't have permission to use -mod");
return;
}
@ -35,7 +36,7 @@ export async function actualMuteUserCmd(
}
const timeUntilUnmute = args.time && humanizeDuration(args.time);
const reason = args.reason ? formatReasonWithAttachments(args.reason, msg.attachments) : undefined;
const reason = args.reason ? formatReasonWithAttachments(args.reason, msg.attachments.array()) : undefined;
let muteResult: MuteResult;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
@ -44,7 +45,7 @@ export async function actualMuteUserCmd(
try {
contactMethods = readContactMethodsFromArgs(args);
} catch (e) {
sendErrorMessage(pluginData, msg.channel, e.message);
sendErrorMessage(pluginData, msg.channel as TextChannel, e.message);
return;
}
@ -58,16 +59,16 @@ export async function actualMuteUserCmd(
});
} catch (e) {
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
sendErrorMessage(pluginData, msg.channel, "Could not mute the user: no mute role set in config");
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not mute the user: no mute role set in config");
} else if (isDiscordRESTError(e) && e.code === 10007) {
sendErrorMessage(pluginData, msg.channel, "Could not mute the user: unknown member");
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not mute the user: unknown member");
} else {
logger.error(`Failed to mute user ${user.id}: ${e.stack}`);
if (user.id == null) {
// tslint-disable-next-line:no-console
console.trace("[DEBUG] Null user.id for mute");
}
sendErrorMessage(pluginData, msg.channel, "Could not mute the user");
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not mute the user");
}
return;
@ -102,5 +103,5 @@ export async function actualMuteUserCmd(
}
if (muteResult.notifyResult.text) response += ` (${muteResult.notifyResult.text})`;
sendSuccessMessage(pluginData, msg.channel, response);
sendSuccessMessage(pluginData, msg.channel as TextChannel, response);
}