mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Various Knub 30 and type fixes
This commit is contained in:
parent
eb703face3
commit
177fc40780
4 changed files with 20 additions and 16 deletions
|
@ -1,16 +1,19 @@
|
|||
import * as t from "io-ts";
|
||||
import { IPluginOptions } from "knub";
|
||||
import { pipe } from "fp-ts/lib/pipeable";
|
||||
import { fold } from "fp-ts/lib/Either";
|
||||
import { PathReporter } from "io-ts/lib/PathReporter";
|
||||
import { guildPlugins } from "./plugins/availablePlugins";
|
||||
import { ZeppelinPluginClass } from "./plugins/ZeppelinPluginClass";
|
||||
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
|
||||
import { ZeppelinPlugin } from "./plugins/ZeppelinPlugin";
|
||||
import { getPluginName } from "knub/dist/plugins/pluginUtils";
|
||||
import { IZeppelinGuildConfig } from "./types";
|
||||
import { PluginOptions } from "knub";
|
||||
|
||||
const pluginNameToClass = new Map<string, typeof ZeppelinPluginClass>();
|
||||
for (const pluginClass of guildPlugins) {
|
||||
// @ts-ignore
|
||||
pluginNameToClass.set(pluginClass.pluginName, pluginClass);
|
||||
const pluginNameToPlugin = new Map<string, ZeppelinPlugin>();
|
||||
for (const plugin of guildPlugins) {
|
||||
const pluginName = getPluginName(plugin);
|
||||
pluginNameToPlugin.set(pluginName, plugin);
|
||||
}
|
||||
|
||||
const guildConfigRootSchema = t.type({
|
||||
|
@ -33,14 +36,16 @@ export function validateGuildConfig(config: any): string[] | null {
|
|||
const validationResult = decodeAndValidateStrict(partialGuildConfigRootSchema, config);
|
||||
if (validationResult instanceof StrictValidationError) return validationResult.getErrors();
|
||||
|
||||
if (config.plugins) {
|
||||
for (const [pluginName, pluginOptions] of Object.entries(config.plugins)) {
|
||||
if (!pluginNameToClass.has(pluginName)) {
|
||||
const guildConfig = config as IZeppelinGuildConfig;
|
||||
|
||||
if (guildConfig.plugins) {
|
||||
for (const [pluginName, pluginOptions] of Object.entries(guildConfig.plugins)) {
|
||||
if (!pluginNameToPlugin.has(pluginName)) {
|
||||
return [`Unknown plugin: ${pluginName}`];
|
||||
}
|
||||
|
||||
const pluginClass = pluginNameToClass.get(pluginName);
|
||||
let pluginErrors = pluginClass.validateOptions(pluginOptions);
|
||||
const plugin = pluginNameToPlugin.get(pluginName);
|
||||
let pluginErrors = plugin.configPreprocessor(pluginOptions as PluginOptions<any>);
|
||||
if (pluginErrors) {
|
||||
pluginErrors = pluginErrors.map(err => `${pluginName}: ${err}`);
|
||||
return pluginErrors;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import EventEmitter from "events";
|
||||
import * as events from "events";
|
||||
import { LogType } from "./LogType";
|
||||
|
||||
// Use the same instance for the same guild, even if a new instance is created
|
||||
|
@ -9,7 +9,7 @@ interface IIgnoredLog {
|
|||
ignoreId: any;
|
||||
}
|
||||
|
||||
export class GuildLogs extends EventEmitter {
|
||||
export class GuildLogs extends events.EventEmitter {
|
||||
protected guildId: string;
|
||||
protected ignoredLogs: IIgnoredLog[];
|
||||
|
||||
|
|
|
@ -4,4 +4,4 @@ import { ZeppelinPluginBlueprint } from "./ZeppelinPluginBlueprint";
|
|||
// prettier-ignore
|
||||
export type ZeppelinPlugin =
|
||||
| typeof ZeppelinPluginClass
|
||||
| ZeppelinPluginBlueprint;
|
||||
| ZeppelinPluginBlueprint<any>;
|
||||
|
|
|
@ -9,7 +9,6 @@ import {
|
|||
GuildAuditLog,
|
||||
GuildAuditLogEntry,
|
||||
GuildChannel,
|
||||
Invite,
|
||||
Member,
|
||||
Message,
|
||||
MessageContent,
|
||||
|
@ -28,7 +27,7 @@ const fsp = fs.promises;
|
|||
|
||||
import https from "https";
|
||||
import tmp from "tmp";
|
||||
import { logger, waitForReaction } from "knub";
|
||||
import { logger, helpers } from "knub";
|
||||
import { SavedMessage } from "./data/entities/SavedMessage";
|
||||
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
|
||||
import { either } from "fp-ts/lib/Either";
|
||||
|
@ -1072,7 +1071,7 @@ export async function resolveInvite(code: string): Promise<ChannelInvite | null>
|
|||
|
||||
export async function confirm(bot: Client, channel: TextableChannel, userId: string, content: MessageContent) {
|
||||
const msg = await channel.createMessage(content);
|
||||
const reply = await waitForReaction(bot, msg, ["✅", "❌"], userId);
|
||||
const reply = await helpers.waitForReaction(bot, msg, ["✅", "❌"], userId);
|
||||
msg.delete().catch(noop);
|
||||
return reply && reply.name === "✅";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue