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