mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 10:25:01 +00:00
almeida fixes
This commit is contained in:
parent
63ac8b89aa
commit
09022db460
3 changed files with 34 additions and 15 deletions
|
@ -47,6 +47,7 @@ import { BanOptions, ConfigSchema, KickOptions, ModActionsPluginType, WarnOption
|
||||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||||
import { onGuildEvent } from "../../data/GuildEvents";
|
import { onGuildEvent } from "../../data/GuildEvents";
|
||||||
import { clearTempban } from "./functions/clearTempban";
|
import { clearTempban } from "./functions/clearTempban";
|
||||||
|
import { ConfigPreprocessorFn } from "knub/dist/config/configTypes";
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
config: {
|
config: {
|
||||||
|
@ -113,6 +114,19 @@ const defaultOptions = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config preprocessor to fix values
|
||||||
|
*/
|
||||||
|
const configPreprocessor: ConfigPreprocessorFn<ModActionsPluginType> = (options) => {
|
||||||
|
if (options.config?.reason_aliases) {
|
||||||
|
options.config.reason_aliases = Object.fromEntries(
|
||||||
|
Object.entries(options.config.reason_aliases).map(([k, v]) => [k.toLowerCase(), v]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
};
|
||||||
|
|
||||||
export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
|
export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
|
||||||
name: "mod_actions",
|
name: "mod_actions",
|
||||||
showInDocs: true,
|
showInDocs: true,
|
||||||
|
@ -126,6 +140,7 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
|
||||||
dependencies: () => [TimeAndDatePlugin, CasesPlugin, MutesPlugin, LogsPlugin],
|
dependencies: () => [TimeAndDatePlugin, CasesPlugin, MutesPlugin, LogsPlugin],
|
||||||
configSchema: ConfigSchema,
|
configSchema: ConfigSchema,
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
|
configPreprocessor,
|
||||||
|
|
||||||
events: [CreateBanCaseOnManualBanEvt, CreateUnbanCaseOnManualUnbanEvt, PostAlertOnMemberJoinEvt],
|
events: [CreateBanCaseOnManualBanEvt, CreateUnbanCaseOnManualUnbanEvt, PostAlertOnMemberJoinEvt],
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { GuildMember, TextChannel, ThreadChannel } from "discord.js";
|
import { GuildMember, Message, TextChannel, ThreadChannel } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { hasPermission } from "knub/dist/helpers";
|
import { hasPermission } from "knub/dist/helpers";
|
||||||
|
import { GuildMessage } from "knub/dist/types";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||||
import { errorMessage, resolveMember, resolveUser } from "../../../utils";
|
import { errorMessage, resolveMember, resolveUser } from "../../../utils";
|
||||||
|
@ -14,7 +15,7 @@ import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs";
|
||||||
|
|
||||||
export async function actualKickMemberCmd(
|
export async function actualKickMemberCmd(
|
||||||
pluginData: GuildPluginData<ModActionsPluginType>,
|
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||||
msg,
|
msg: Message,
|
||||||
args: {
|
args: {
|
||||||
user: string;
|
user: string;
|
||||||
reason: string;
|
reason: string;
|
||||||
|
@ -25,8 +26,9 @@ export async function actualKickMemberCmd(
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const user = await resolveUser(pluginData.client, args.user);
|
const user = await resolveUser(pluginData.client, args.user);
|
||||||
if (!user.id) {
|
const channel = msg.channel as TextChannel;
|
||||||
sendErrorMessage(pluginData, msg.channel, `User not found`);
|
if (!user.id || !msg.member) {
|
||||||
|
sendErrorMessage(pluginData, channel, `User not found`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,9 +37,9 @@ export async function actualKickMemberCmd(
|
||||||
if (!memberToKick) {
|
if (!memberToKick) {
|
||||||
const banned = await isBanned(pluginData, user.id);
|
const banned = await isBanned(pluginData, user.id);
|
||||||
if (banned) {
|
if (banned) {
|
||||||
sendErrorMessage(pluginData, msg.channel, `User is banned`);
|
sendErrorMessage(pluginData, channel, `User is banned`);
|
||||||
} else {
|
} else {
|
||||||
sendErrorMessage(pluginData, msg.channel, `User not found on the server`);
|
sendErrorMessage(pluginData, channel, `User not found on the server`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -45,7 +47,7 @@ export async function actualKickMemberCmd(
|
||||||
|
|
||||||
// Make sure we're allowed to kick this member
|
// Make sure we're allowed to kick this member
|
||||||
if (!canActOn(pluginData, msg.member, memberToKick)) {
|
if (!canActOn(pluginData, msg.member, memberToKick)) {
|
||||||
sendErrorMessage(pluginData, msg.channel, "Cannot kick: insufficient permissions");
|
sendErrorMessage(pluginData, channel, "Cannot kick: insufficient permissions");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ export async function actualKickMemberCmd(
|
||||||
let mod = msg.member;
|
let mod = msg.member;
|
||||||
if (args.mod) {
|
if (args.mod) {
|
||||||
if (!(await hasPermission(await pluginData.config.getForMessage(msg), "can_act_as_other"))) {
|
if (!(await hasPermission(await pluginData.config.getForMessage(msg), "can_act_as_other"))) {
|
||||||
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
|
sendErrorMessage(pluginData, channel, "You don't have permission to use -mod");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,18 +66,18 @@ export async function actualKickMemberCmd(
|
||||||
try {
|
try {
|
||||||
contactMethods = readContactMethodsFromArgs(args);
|
contactMethods = readContactMethodsFromArgs(args);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
sendErrorMessage(pluginData, msg.channel, e.message);
|
sendErrorMessage(pluginData, channel, e.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = pluginData.config.get();
|
const config = pluginData.config.get();
|
||||||
const reason = parseReason(config, formatReasonWithAttachments(args.reason, msg.attachments));
|
const reason = parseReason(config, formatReasonWithAttachments(args.reason, [...msg.attachments.values()]));
|
||||||
|
|
||||||
const kickResult = await kickMember(pluginData, memberToKick, reason, {
|
const kickResult = await kickMember(pluginData, memberToKick, reason, {
|
||||||
contactMethods,
|
contactMethods,
|
||||||
caseArgs: {
|
caseArgs: {
|
||||||
modId: mod.id,
|
modId: mod.id,
|
||||||
ppId: mod.id !== msg.author.id ? msg.author.id : null,
|
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -86,7 +88,7 @@ export async function actualKickMemberCmd(
|
||||||
try {
|
try {
|
||||||
await memberToKick.ban({ days: 1, reason: "kick -clean" });
|
await memberToKick.ban({ days: 1, reason: "kick -clean" });
|
||||||
} catch {
|
} catch {
|
||||||
sendErrorMessage(pluginData, msg.channel, "Failed to ban the user to clean messages (-clean)");
|
sendErrorMessage(pluginData, channel, "Failed to ban the user to clean messages (-clean)");
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, memberToKick.id);
|
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, memberToKick.id);
|
||||||
|
@ -95,7 +97,7 @@ export async function actualKickMemberCmd(
|
||||||
try {
|
try {
|
||||||
await pluginData.guild.bans.remove(memberToKick.id, "kick -clean");
|
await pluginData.guild.bans.remove(memberToKick.id, "kick -clean");
|
||||||
} catch {
|
} catch {
|
||||||
sendErrorMessage(pluginData, msg.channel, "Failed to unban the user after banning them (-clean)");
|
sendErrorMessage(pluginData, channel, "Failed to unban the user after banning them (-clean)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,5 +110,5 @@ export async function actualKickMemberCmd(
|
||||||
let response = `Kicked **${memberToKick.user.tag}** (Case #${kickResult.case.case_number})`;
|
let response = `Kicked **${memberToKick.user.tag}** (Case #${kickResult.case.case_number})`;
|
||||||
|
|
||||||
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
|
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
|
||||||
sendSuccessMessage(pluginData, msg.channel, response);
|
sendSuccessMessage(pluginData, channel, response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
import { TConfigSchema } from "../types";
|
||||||
|
|
||||||
const MAX_REASON_LENGTH = 512;
|
const MAX_REASON_LENGTH = 512;
|
||||||
|
|
||||||
export function parseReason(config: any, reason: string): string {
|
export function parseReason(config: TConfigSchema, reason: string): string {
|
||||||
if (!reason) return reason;
|
if (!reason) return reason;
|
||||||
if (config?.reason_aliases) {
|
if (config?.reason_aliases) {
|
||||||
reason = config.reason_aliases![reason.toLowerCase()] ?? reason;
|
reason = config.reason_aliases![reason.toLowerCase()] ?? reason;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue