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

Update to Knub30.0.0-beta.37 and Eris 0.15, first pass

This commit is contained in:
Dragory 2021-05-23 14:35:16 +03:00
parent 84da543205
commit f6be4f4af6
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
133 changed files with 6507 additions and 380 deletions

View file

@ -110,7 +110,8 @@ const defaultOptions = {
],
};
export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()("mod_actions", {
export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
name: "mod_actions",
showInDocs: true,
info: {
prettyName: "Mod actions",
@ -187,7 +188,7 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()("mod
},
},
onLoad(pluginData) {
afterLoad(pluginData) {
const { state, guild } = pluginData;
state.mutes = GuildMutes.getGuildInstance(guild.id);
@ -207,7 +208,7 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()("mod
outdatedTempbansLoop(pluginData);
},
onUnload(pluginData) {
beforeUnload(pluginData) {
pluginData.state.unloaded = true;
pluginData.state.events.removeAllListeners();
},

View file

@ -44,7 +44,7 @@ export const AddCaseCmd = modActionsCmd({
// 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, "can_act_as_other", { message: msg })) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
return;
}

View file

@ -54,7 +54,7 @@ export const BanCmd = modActionsCmd({
// 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, "can_act_as_other", { message: msg, channelId: msg.channel.id })) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
return;
}
@ -160,7 +160,8 @@ export const BanCmd = modActionsCmd({
return;
}
const deleteMessageDays = args["delete-days"] ?? pluginData.config.getForMessage(msg).ban_delete_message_days;
const deleteMessageDays =
args["delete-days"] ?? (await pluginData.config.getForMessage(msg)).ban_delete_message_days;
const banResult = await banUserId(
pluginData,
user.id,

View file

@ -53,7 +53,7 @@ export const ForcebanCmd = modActionsCmd({
// 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, "can_act_as_other", { message: msg })) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
return;
}

View file

@ -36,7 +36,7 @@ export const UnbanCmd = modActionsCmd({
// 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, "can_act_as_other", { message: msg, channelId: msg.channel.id })) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
return;
}

View file

@ -56,7 +56,7 @@ export const WarnCmd = modActionsCmd({
// 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, "can_act_as_other", { message: msg })) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
msg.channel.createMessage(errorMessage("You don't have permission to use -mod"));
return;
}

View file

@ -13,9 +13,9 @@ import { Case } from "../../../data/entities/Case";
* Create a BAN case automatically when a user is banned manually.
* Attempts to find the ban's details in the audit log.
*/
export const CreateBanCaseOnManualBanEvt = modActionsEvt(
"guildBanAdd",
async ({ pluginData, args: { guild, user } }) => {
export const CreateBanCaseOnManualBanEvt = modActionsEvt({
event: "guildBanAdd",
async listener({ pluginData, args: { guild, user } }) {
if (isEventIgnored(pluginData, IgnoredEventType.Ban, user.id)) {
clearIgnoredEvents(pluginData, IgnoredEventType.Ban, user.id);
return;
@ -39,7 +39,7 @@ export const CreateBanCaseOnManualBanEvt = modActionsEvt(
mod = await resolveUser(pluginData.client, modId);
const config = mod instanceof UnknownUser ? pluginData.config.get() : pluginData.config.getForUser(mod);
const config = mod instanceof UnknownUser ? pluginData.config.get() : await pluginData.config.getForUser(mod);
if (config.create_cases_for_manual_actions) {
reason = relevantAuditLogEntry.reason || "";
@ -72,4 +72,4 @@ export const CreateBanCaseOnManualBanEvt = modActionsEvt(
pluginData.state.events.emit("ban", user.id, reason);
},
);
});

View file

@ -14,9 +14,9 @@ import { Case } from "../../../data/entities/Case";
* Create a KICK case automatically when a user is kicked manually.
* Attempts to find the kick's details in the audit log.
*/
export const CreateKickCaseOnManualKickEvt = modActionsEvt(
"guildMemberRemove",
async ({ pluginData, args: { member } }) => {
export const CreateKickCaseOnManualKickEvt = modActionsEvt({
event: "guildMemberRemove",
async listener({ pluginData, args: { member } }) {
if (isEventIgnored(pluginData, IgnoredEventType.Kick, member.id)) {
clearIgnoredEvents(pluginData, IgnoredEventType.Kick, member.id);
return;
@ -42,7 +42,7 @@ export const CreateKickCaseOnManualKickEvt = modActionsEvt(
} else {
mod = await resolveUser(pluginData.client, kickAuditLogEntry.user.id);
const config = mod instanceof UnknownUser ? pluginData.config.get() : pluginData.config.getForUser(mod);
const config = mod instanceof UnknownUser ? pluginData.config.get() : await pluginData.config.getForUser(mod);
if (config.create_cases_for_manual_actions) {
const casesPlugin = pluginData.getPlugin(CasesPlugin);
@ -67,4 +67,4 @@ export const CreateKickCaseOnManualKickEvt = modActionsEvt(
pluginData.state.events.emit("kick", member.id, kickAuditLogEntry.reason || undefined);
}
},
);
});

View file

@ -13,9 +13,9 @@ import { Case } from "../../../data/entities/Case";
* Create an UNBAN case automatically when a user is unbanned manually.
* Attempts to find the unban's details in the audit log.
*/
export const CreateUnbanCaseOnManualUnbanEvt = modActionsEvt(
"guildBanRemove",
async ({ pluginData, args: { guild, user } }) => {
export const CreateUnbanCaseOnManualUnbanEvt = modActionsEvt({
event: "guildBanRemove",
async listener({ pluginData, args: { guild, user } }) {
if (isEventIgnored(pluginData, IgnoredEventType.Unban, user.id)) {
clearIgnoredEvents(pluginData, IgnoredEventType.Unban, user.id);
return;
@ -38,7 +38,7 @@ export const CreateUnbanCaseOnManualUnbanEvt = modActionsEvt(
mod = await resolveUser(pluginData.client, modId);
const config = mod instanceof UnknownUser ? pluginData.config.get() : pluginData.config.getForUser(mod);
const config = mod instanceof UnknownUser ? pluginData.config.get() : await pluginData.config.getForUser(mod);
if (config.create_cases_for_manual_actions) {
createdCase = await casesPlugin.createCase({
@ -69,4 +69,4 @@ export const CreateUnbanCaseOnManualUnbanEvt = modActionsEvt(
pluginData.state.events.emit("unban", user.id);
},
);
});

View file

@ -8,9 +8,9 @@ import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
/**
* Show an alert if a member with prior notes joins the server
*/
export const PostAlertOnMemberJoinEvt = modActionsEvt(
"guildMemberAdd",
async ({ pluginData, args: { guild, member } }) => {
export const PostAlertOnMemberJoinEvt = modActionsEvt({
event: "guildMemberAdd",
async listener({ pluginData, args: { guild, member } }) {
const config = pluginData.config.get();
if (!config.alert_on_rejoin) return;
@ -51,4 +51,4 @@ export const PostAlertOnMemberJoinEvt = modActionsEvt(
);
}
},
);
});

View file

@ -51,7 +51,7 @@ export async function actualKickMemberCmd(
// 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")) {
if (!(await hasPermission(await pluginData.config.getForMessage(msg), "can_act_as_other"))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
return;
}

View file

@ -1,4 +1,4 @@
import { Member, Message, TextChannel, User } from "eris";
import { GuildTextableChannel, Member, Message, TextChannel, User } from "eris";
import { asSingleLine, isDiscordRESTError, UnknownUser } from "../../../utils";
import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { GuildPluginData } from "knub";
@ -10,7 +10,6 @@ import { MutesPlugin } from "../../Mutes/MutesPlugin";
import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { logger } from "../../../logger";
import { GuildMessage } from "knub/dist/helpers";
/**
* The actual function run by both !mute and !forcemute.
@ -19,7 +18,7 @@ import { GuildMessage } from "knub/dist/helpers";
export async function actualMuteUserCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
user: User | UnknownUser,
msg: GuildMessage,
msg: Message<GuildTextableChannel>,
args: { time?: number; reason?: string; mod: Member; notify?: string; "notify-channel"?: TextChannel },
) {
// The moderator who did the action is the message author or, if used, the specified -mod
@ -27,7 +26,7 @@ export async function actualMuteUserCmd(
let pp: User | null = null;
if (args.mod) {
if (!hasPermission(pluginData, "can_act_as_other", { message: msg })) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
return;
}

View file

@ -18,7 +18,7 @@ export async function actualUnmuteCmd(
let pp: User | null = null;
if (args.mod) {
if (!hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id })) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
return;
}

View file

@ -1,6 +1,6 @@
import * as t from "io-ts";
import { tNullable, UserNotificationMethod, UserNotificationResult } from "../../utils";
import { BasePluginType, guildCommand, guildEventListener } from "knub";
import { BasePluginType, typedGuildCommand, typedGuildEventListener } from "knub";
import { GuildMutes } from "../../data/GuildMutes";
import { GuildCases } from "../../data/GuildCases";
import { GuildLogs } from "../../data/GuildLogs";
@ -148,5 +148,5 @@ export interface BanOptions {
export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban" | "unban";
export const modActionsCmd = guildCommand<ModActionsPluginType>();
export const modActionsEvt = guildEventListener<ModActionsPluginType>();
export const modActionsCmd = typedGuildCommand<ModActionsPluginType>();
export const modActionsEvt = typedGuildEventListener<ModActionsPluginType>();