3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Type fixes + circular dependency fix

This commit is contained in:
Dragory 2021-08-18 20:01:06 +03:00
parent e3b6b017a2
commit 59e75e0584
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
20 changed files with 70 additions and 83 deletions

View file

@ -24,7 +24,7 @@
"humanize-duration": "^3.15.0", "humanize-duration": "^3.15.0",
"io-ts": "^2.0.0", "io-ts": "^2.0.0",
"js-yaml": "^3.13.1", "js-yaml": "^3.13.1",
"knub": "^30.0.0-beta.41", "knub": "^30.0.0-beta.42",
"knub-command-manager": "^9.1.0", "knub-command-manager": "^9.1.0",
"last-commit-log": "^2.1.0", "last-commit-log": "^2.1.0",
"lodash.chunk": "^4.2.0", "lodash.chunk": "^4.2.0",
@ -3043,9 +3043,9 @@
} }
}, },
"node_modules/knub": { "node_modules/knub": {
"version": "30.0.0-beta.41", "version": "30.0.0-beta.42",
"resolved": "https://registry.npmjs.org/knub/-/knub-30.0.0-beta.41.tgz", "resolved": "https://registry.npmjs.org/knub/-/knub-30.0.0-beta.42.tgz",
"integrity": "sha512-tKHGG9vh62ZN0JIi2ULYHvJbR28WXhym8c9vRtyQCPQqJ1w3n7Fow9JXbh6BUTSD8QszWbvq1Ri22wbQtBEyNw==", "integrity": "sha512-y7nqQh1bzQniYwEftdv6S8Jp2qBvT5a7vn+3JeA0s0ADXobI+/rRVznpq8o0x2m0+E+EeKxo1Ch8F8Hy+VMX6w==",
"dependencies": { "dependencies": {
"discord-api-types": "^0.22.0", "discord-api-types": "^0.22.0",
"discord.js": "^13.0.1", "discord.js": "^13.0.1",
@ -8290,9 +8290,9 @@
} }
}, },
"knub": { "knub": {
"version": "30.0.0-beta.41", "version": "30.0.0-beta.42",
"resolved": "https://registry.npmjs.org/knub/-/knub-30.0.0-beta.41.tgz", "resolved": "https://registry.npmjs.org/knub/-/knub-30.0.0-beta.42.tgz",
"integrity": "sha512-tKHGG9vh62ZN0JIi2ULYHvJbR28WXhym8c9vRtyQCPQqJ1w3n7Fow9JXbh6BUTSD8QszWbvq1Ri22wbQtBEyNw==", "integrity": "sha512-y7nqQh1bzQniYwEftdv6S8Jp2qBvT5a7vn+3JeA0s0ADXobI+/rRVznpq8o0x2m0+E+EeKxo1Ch8F8Hy+VMX6w==",
"requires": { "requires": {
"discord-api-types": "^0.22.0", "discord-api-types": "^0.22.0",
"discord.js": "^13.0.1", "discord.js": "^13.0.1",

View file

@ -39,7 +39,7 @@
"humanize-duration": "^3.15.0", "humanize-duration": "^3.15.0",
"io-ts": "^2.0.0", "io-ts": "^2.0.0",
"js-yaml": "^3.13.1", "js-yaml": "^3.13.1",
"knub": "^30.0.0-beta.41", "knub": "^30.0.0-beta.42",
"knub-command-manager": "^9.1.0", "knub-command-manager": "^9.1.0",
"last-commit-log": "^2.1.0", "last-commit-log": "^2.1.0",
"lodash.chunk": "^4.2.0", "lodash.chunk": "^4.2.0",

View file

@ -19,7 +19,7 @@ export const LogAction = automodAction({
user, user,
users, users,
actionsTaken, actionsTaken,
matchSummary: matchResult.summary, matchSummary: matchResult.summary ?? "",
}); });
}, },
}); });

View file

@ -16,10 +16,6 @@ import { getRecentCasesByMod } from "./functions/getRecentCasesByMod";
import { getTotalCasesByMod } from "./functions/getTotalCasesByMod"; import { getTotalCasesByMod } from "./functions/getTotalCasesByMod";
import { postCaseToCaseLogChannel } from "./functions/postToCaseLogChannel"; import { postCaseToCaseLogChannel } from "./functions/postToCaseLogChannel";
import { CaseArgs, CaseNoteArgs, CasesPluginType, ConfigSchema } from "./types"; import { CaseArgs, CaseNoteArgs, CasesPluginType, ConfigSchema } from "./types";
import { LogsPlugin } from "../Logs/LogsPlugin";
// Workaround for circular dependency
const AnyTypedLogsPlugin = LogsPlugin as any;
const defaultOptions = { const defaultOptions = {
config: { config: {
@ -42,7 +38,11 @@ export const CasesPlugin = zeppelinGuildPlugin<CasesPluginType>()({
`), `),
}, },
dependencies: () => [TimeAndDatePlugin, AnyTypedLogsPlugin], dependencies: async () => [
TimeAndDatePlugin,
// The `as any` cast here is to prevent TypeScript from locking up from the circular dependency
((await import("../Logs/LogsPlugin")) as any).LogsPlugin,
],
configSchema: ConfigSchema, configSchema: ConfigSchema,
defaultOptions, defaultOptions,

View file

@ -108,10 +108,6 @@ import { logVoiceChannelLeave } from "./logFunctions/logVoiceChannelLeave";
import { logVoiceChannelMove } from "./logFunctions/logVoiceChannelMove"; import { logVoiceChannelMove } from "./logFunctions/logVoiceChannelMove";
import { logMemberTimedUnban } from "./logFunctions/logMemberTimedUnban"; import { logMemberTimedUnban } from "./logFunctions/logMemberTimedUnban";
import { logDmFailed } from "./logFunctions/logDmFailed"; import { logDmFailed } from "./logFunctions/logDmFailed";
import { CasesPlugin } from "../Cases/CasesPlugin";
// Workaround for circular dependency
const AnyTypedCasesPlugin = CasesPlugin as any;
const defaultOptions: PluginOptions<LogsPluginType> = { const defaultOptions: PluginOptions<LogsPluginType> = {
config: { config: {
@ -143,7 +139,11 @@ export const LogsPlugin = zeppelinGuildPlugin<LogsPluginType>()({
prettyName: "Logs", prettyName: "Logs",
}, },
dependencies: () => [TimeAndDatePlugin, AnyTypedCasesPlugin], dependencies: async () => [
TimeAndDatePlugin,
// The `as any` cast here is to prevent TypeScript from locking up from the circular dependency
((await import("../Cases/CasesPlugin")) as any).CasesPlugin,
],
configSchema: ConfigSchema, configSchema: ConfigSchema,
defaultOptions, defaultOptions,

View file

@ -23,7 +23,7 @@ export function logAutomodAction(pluginData: GuildPluginData<LogsPluginType>, da
user: userToTemplateSafeUser(data.user), user: userToTemplateSafeUser(data.user),
users: data.users.map(user => userToTemplateSafeUser(user)), users: data.users.map(user => userToTemplateSafeUser(user)),
actionsTaken: data.actionsTaken, actionsTaken: data.actionsTaken,
matchSummary: data.matchSummary, matchSummary: data.matchSummary ?? "",
}), }),
{ {
userId: data.user.id, userId: data.user.id,

View file

@ -17,7 +17,7 @@ export function logMemberRoleAdd(pluginData: GuildPluginData<LogsPluginType>, da
pluginData, pluginData,
LogType.MEMBER_ROLE_ADD, LogType.MEMBER_ROLE_ADD,
createTypedTemplateSafeValueContainer({ createTypedTemplateSafeValueContainer({
mod: userToTemplateSafeUser(data.mod), mod: data.mod ? userToTemplateSafeUser(data.mod) : null,
member: memberToTemplateSafeMember(data.member), member: memberToTemplateSafeMember(data.member),
roles: data.roles.map(r => r.name).join(", "), roles: data.roles.map(r => r.name).join(", "),
}), }),

View file

@ -17,7 +17,7 @@ export function logMemberRoleRemove(pluginData: GuildPluginData<LogsPluginType>,
pluginData, pluginData,
LogType.MEMBER_ROLE_REMOVE, LogType.MEMBER_ROLE_REMOVE,
createTypedTemplateSafeValueContainer({ createTypedTemplateSafeValueContainer({
mod: userToTemplateSafeUser(data.mod), mod: data.mod ? userToTemplateSafeUser(data.mod) : null,
member: memberToTemplateSafeMember(data.member), member: memberToTemplateSafeMember(data.member),
roles: data.roles.map(r => r.name).join(", "), roles: data.roles.map(r => r.name).join(", "),
}), }),

View file

@ -5,10 +5,11 @@ import { log } from "../util/log";
import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter"; import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter";
import { User } from "discord.js"; import { User } from "discord.js";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { UnknownUser } from "../../../utils";
interface LogMemberTimedUnmuteData { interface LogMemberTimedUnmuteData {
mod: User; mod: User;
user: User; user: User | UnknownUser;
time: string; time: string;
caseNumber: number; caseNumber: number;
reason: string; reason: string;
@ -25,6 +26,9 @@ export function logMemberTimedUnmute(pluginData: GuildPluginData<LogsPluginType>
caseNumber: data.caseNumber, caseNumber: data.caseNumber,
reason: data.reason, reason: data.reason,
}), }),
{}, {
userId: data.user.id,
bot: data.user instanceof User ? data.user.bot : false,
},
); );
} }

View file

@ -5,10 +5,11 @@ import { log } from "../util/log";
import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter"; import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter";
import { GuildMember, User } from "discord.js"; import { GuildMember, User } from "discord.js";
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { UnknownUser } from "../../../utils";
interface LogMemberUnmuteData { interface LogMemberUnmuteData {
mod: GuildMember; mod: User;
user: User; user: User | UnknownUser;
caseNumber: number; caseNumber: number;
reason: string; reason: string;
} }
@ -18,14 +19,14 @@ export function logMemberUnmute(pluginData: GuildPluginData<LogsPluginType>, dat
pluginData, pluginData,
LogType.MEMBER_UNMUTE, LogType.MEMBER_UNMUTE,
createTypedTemplateSafeValueContainer({ createTypedTemplateSafeValueContainer({
mod: memberToTemplateSafeMember(data.mod), mod: userToTemplateSafeUser(data.mod),
user: userToTemplateSafeUser(data.user), user: userToTemplateSafeUser(data.user),
caseNumber: data.caseNumber, caseNumber: data.caseNumber,
reason: data.reason, reason: data.reason,
}), }),
{ {
userId: data.user.id, userId: data.user.id,
bot: data.user.bot, bot: data.user instanceof User ? data.user.bot : false,
}, },
); );
} }

View file

@ -31,7 +31,7 @@ export function logMessageDeleteAuto(pluginData: GuildPluginData<LogsPluginType>
}), }),
{ {
userId: data.user.id, userId: data.user.id,
bot: data.user.bot, bot: data.user instanceof User ? data.user.bot : false,
channel: data.channel.id, channel: data.channel.id,
category: data.channel.parentId, category: data.channel.parentId,
}, },

View file

@ -119,7 +119,7 @@ export const BanCmd = modActionsCmd({
}); });
} else { } else {
pluginData.getPlugin(LogsPlugin).logMemberBan({ pluginData.getPlugin(LogsPlugin).logMemberBan({
mod, mod: mod.user,
user, user,
caseNumber: createdCase.case_number, caseNumber: createdCase.case_number,
reason, reason,

View file

@ -93,14 +93,14 @@ export async function unmuteUser(
user, user,
caseNumber: createdCase.case_number, caseNumber: createdCase.case_number,
time: timeUntilUnmute, time: timeUntilUnmute,
reason: caseArgs.reason, reason: caseArgs.reason ?? "",
}); });
} else { } else {
pluginData.getPlugin(LogsPlugin).logMemberUnmute({ pluginData.getPlugin(LogsPlugin).logMemberUnmute({
mod, mod,
user, user,
caseNumber: createdCase.case_number, caseNumber: createdCase.case_number,
reason: caseArgs.reason, reason: caseArgs.reason ?? "",
}); });
} }

View file

@ -192,7 +192,7 @@ export async function actualPostCmd(
date: postAt.format(timeAndDate.getDateFormat("date")), date: postAt.format(timeAndDate.getDateFormat("date")),
time: postAt.format(timeAndDate.getDateFormat("time")), time: postAt.format(timeAndDate.getDateFormat("time")),
repeatInterval: humanizeDuration(opts.repeat), repeatInterval: humanizeDuration(opts.repeat),
repeatDetails: repeatDetailsStr, repeatDetails: repeatDetailsStr ?? "",
}); });
} }

View file

@ -4,7 +4,7 @@ import moment from "moment-timezone";
import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger"; import { logger } from "../../../logger";
import { DBDateFormat, SECONDS } from "../../../utils"; import { DBDateFormat, SECONDS, verboseChannelMention, verboseUserMention } from "../../../utils";
import { PostPluginType } from "../types"; import { PostPluginType } from "../types";
import { postMessage } from "./postMessage"; import { postMessage } from "./postMessage";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
@ -38,9 +38,9 @@ export async function scheduledPostLoop(pluginData: GuildPluginData<PostPluginTy
}); });
} catch { } catch {
pluginData.getPlugin(LogsPlugin).logBotAlert({ pluginData.getPlugin(LogsPlugin).logBotAlert({
body: `Failed to post scheduled message by {userMention(author)} to {channelMention(channel)}`, body: `Failed to post scheduled message by ${verboseUserMention(author)} to ${verboseChannelMention(
channel, channel,
author, )}`,
}); });
logger.warn( logger.warn(
`Failed to post scheduled message to #${channel.name} (${channel.id}) on ${pluginData.guild.name} (${pluginData.guild.id})`, `Failed to post scheduled message to #${channel.name} (${channel.id}) on ${pluginData.guild.name} (${pluginData.guild.id})`,

View file

@ -49,24 +49,18 @@ export const ButtonInteractionEvt = reactionRolesEvt({
const group = cfg.button_groups[context.groupName]; const group = cfg.button_groups[context.groupName];
if (!group) { if (!group) {
await sendEphemeralReply(int, `A configuration error was encountered, please contact the Administrators!`); await sendEphemeralReply(int, `A configuration error was encountered, please contact the Administrators!`);
meta.pluginData meta.pluginData.getPlugin(LogsPlugin).logBotAlert({
.getPlugin(LogsPlugin) body: `**A configuration error occurred** on buttons for message ${int.message.id}, group **${context.groupName}** not found in config`,
.log( });
LogType.BOT_ALERT,
`**A configuration error occurred** on buttons for message ${int.message.id}, group **${context.groupName}** not found in config`,
);
return; return;
} }
// Verify that detected action is known by us // Verify that detected action is known by us
if (!(<any>Object).values(ButtonMenuActions).includes(context.action)) { if (!(<any>Object).values(ButtonMenuActions).includes(context.action)) {
await sendEphemeralReply(int, `A internal error was encountered, please contact the Administrators!`); await sendEphemeralReply(int, `A internal error was encountered, please contact the Administrators!`);
meta.pluginData meta.pluginData.getPlugin(LogsPlugin).logBotAlert({
.getPlugin(LogsPlugin) body: `**A internal error occurred** on buttons for message ${int.message.id}, action **${context.action}** is not known`,
.log( });
LogType.BOT_ALERT,
`**A internal error occurred** on buttons for message ${int.message.id}, action **${context.action}** is not known`,
);
return; return;
} }

View file

@ -18,12 +18,9 @@ export async function handleOpenMenu(
content: `A configuration error was encountered, please contact the Administrators!`, content: `A configuration error was encountered, please contact the Administrators!`,
ephemeral: true, ephemeral: true,
}); });
pluginData pluginData.getPlugin(LogsPlugin).logBotAlert({
.getPlugin(LogsPlugin) body: `**A configuration error occurred** on buttons for message ${int.message.id}, no menus found in config`,
.log( });
LogType.BOT_ALERT,
`**A configuration error occurred** on buttons for message ${int.message.id}, no menus found in config`,
);
return; return;
} }
@ -48,12 +45,9 @@ export async function handleOpenMenu(
content: `A configuration error was encountered, please contact the Administrators!`, content: `A configuration error was encountered, please contact the Administrators!`,
ephemeral: true, ephemeral: true,
}); });
pluginData pluginData.getPlugin(LogsPlugin).logBotAlert({
.getPlugin(LogsPlugin) body: `**A configuration error occurred** on buttons for message ${int.message.id}, menu **${context.roleOrMenu}** not found in config`,
.log( });
LogType.BOT_ALERT,
`**A configuration error occurred** on buttons for message ${int.message.id}, menu **${context.roleOrMenu}** not found in config`,
);
return; return;
} }
const rows = splitButtonsIntoRows(menuButtons, Object.values(group.button_menus[context.roleOrMenu])); // new MessageActionRow().addComponents(menuButtons); const rows = splitButtonsIntoRows(menuButtons, Object.values(group.button_menus[context.roleOrMenu])); // new MessageActionRow().addComponents(menuButtons);
@ -73,12 +67,9 @@ export async function handleModifyRole(
content: `A configuration error was encountered, please contact the Administrators!`, content: `A configuration error was encountered, please contact the Administrators!`,
ephemeral: true, ephemeral: true,
}); });
pluginData pluginData.getPlugin(LogsPlugin).logBotAlert({
.getPlugin(LogsPlugin) body: `**A configuration error occurred** on buttons for message ${int.message.id}, role **${context.roleOrMenu}** not found on server`,
.log( });
LogType.BOT_ALERT,
`**A configuration error occurred** on buttons for message ${int.message.id}, role **${context.roleOrMenu}** not found on server`,
);
return; return;
} }
@ -96,11 +87,8 @@ export async function handleModifyRole(
content: "A configuration error was encountered, please contact the Administrators!", content: "A configuration error was encountered, please contact the Administrators!",
ephemeral: true, ephemeral: true,
}); });
pluginData pluginData.getPlugin(LogsPlugin).logBotAlert({
.getPlugin(LogsPlugin) body: `**A configuration error occurred** on buttons for message ${int.message.id}, error: ${e}. We might be missing permissions!`,
.log( });
LogType.BOT_ALERT,
`**A configuration error occurred** on buttons for message ${int.message.id}, error: ${e}. We might be missing permissions!`,
);
} }
} }

View file

@ -54,10 +54,10 @@ export const AddRoleCmd = rolesCmd({
await args.member.roles.add(roleId); await args.member.roles.add(roleId);
pluginData.getPlugin(LogsPlugin).logMemberRoleAdd(LogType.MEMBER_ROLE_ADD, { pluginData.getPlugin(LogsPlugin).logMemberRoleAdd({
member: memberToTemplateSafeMember(args.member), mod: msg.author,
roles: role.name, member: args.member,
mod: userToTemplateSafeUser(msg.author), roles: [role],
}); });
sendSuccessMessage( sendSuccessMessage(

View file

@ -69,7 +69,7 @@ export const VcmoveCmd = utilityCmd({
return; return;
} }
const oldVoiceChannel = pluginData.guild.channels.cache.get(args.member.voice.channelId); const oldVoiceChannel = pluginData.guild.channels.cache.get(args.member.voice.channelId) as VoiceChannel;
try { try {
await args.member.edit({ await args.member.edit({
@ -83,7 +83,7 @@ export const VcmoveCmd = utilityCmd({
pluginData.getPlugin(LogsPlugin).logVoiceChannelForceMove({ pluginData.getPlugin(LogsPlugin).logVoiceChannelForceMove({
mod: msg.author, mod: msg.author,
member: args.member, member: args.member,
oldChannel: oldVoiceChannel!, oldChannel: oldVoiceChannel,
newChannel: channel, newChannel: channel,
}); });

View file

@ -6,7 +6,7 @@ import {
} from "../../../utils/templateSafeObjects"; } from "../../../utils/templateSafeObjects";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { renderTemplate, TemplateParseError } from "../../../templateFormatter"; import { renderTemplate, TemplateParseError } from "../../../templateFormatter";
import { createChunkedMessage, stripObjectToScalars } from "../../../utils"; import { createChunkedMessage, stripObjectToScalars, verboseChannelMention, verboseUserMention } from "../../../utils";
import { sendDM } from "../../../utils/sendDM"; import { sendDM } from "../../../utils/sendDM";
import { welcomeMessageEvt } from "../types"; import { welcomeMessageEvt } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
@ -68,9 +68,9 @@ export const SendWelcomeMessageEvt = welcomeMessageEvt({
await createChunkedMessage(channel, formatted); await createChunkedMessage(channel, formatted);
} catch { } catch {
pluginData.getPlugin(LogsPlugin).logBotAlert({ pluginData.getPlugin(LogsPlugin).logBotAlert({
body: `Failed send a welcome message for {userMention(member)} to {channelMention(channel)}`, body: `Failed send a welcome message for ${verboseUserMention(member.user)} to ${verboseChannelMention(
member, channel,
channel, )}`,
}); });
} }
} }