import * as t from "io-ts"; import { BasePluginType, GlobalPluginBlueprint, GlobalPluginData, GuildPluginBlueprint, GuildPluginData, typedGlobalPlugin, typedGuildPlugin, } from "knub"; import { PluginOptions } from "knub/dist/config/configTypes"; import { Awaitable } from "knub/dist/utils"; import { getPluginConfigPreprocessor } from "../pluginUtils"; import { TMarkdown } from "../types"; /** * GUILD PLUGINS */ export interface ZeppelinGuildPluginBlueprint = GuildPluginData> extends GuildPluginBlueprint { configSchema: t.TypeC; showInDocs?: boolean; info?: { prettyName: string; description?: TMarkdown; usageGuide?: TMarkdown; configurationGuide?: TMarkdown; }; configPreprocessor?: ( options: PluginOptions, strict?: boolean, ) => Awaitable>; } export function zeppelinGuildPlugin( blueprint: TBlueprint, ): TBlueprint & { configPreprocessor: ZeppelinGuildPluginBlueprint["configPreprocessor"] }; export function zeppelinGuildPlugin(): < TBlueprint extends ZeppelinGuildPluginBlueprint> >( blueprint: TBlueprint, ) => TBlueprint & { configPreprocessor: ZeppelinGuildPluginBlueprint>["configPreprocessor"]; }; export function zeppelinGuildPlugin(...args) { if (args.length) { const blueprint = (typedGuildPlugin( ...(args as Parameters), ) as unknown) as ZeppelinGuildPluginBlueprint; blueprint.configPreprocessor = getPluginConfigPreprocessor(blueprint, blueprint.configPreprocessor); return blueprint; } else { return zeppelinGuildPlugin as (name, blueprint) => ZeppelinGuildPluginBlueprint; } } /** * GLOBAL PLUGINS */ export interface ZeppelinGlobalPluginBlueprint extends GlobalPluginBlueprint> { configSchema: t.TypeC; configPreprocessor?: (options: PluginOptions, strict?: boolean) => Awaitable>; } export function zeppelinGlobalPlugin( blueprint: TBlueprint, ): TBlueprint & { configPreprocessor: ZeppelinGlobalPluginBlueprint["configPreprocessor"] }; export function zeppelinGlobalPlugin(): < TBlueprint extends ZeppelinGlobalPluginBlueprint >( blueprint: TBlueprint, ) => TBlueprint & { configPreprocessor: ZeppelinGlobalPluginBlueprint["configPreprocessor"]; }; export function zeppelinGlobalPlugin(...args) { if (args.length) { const blueprint = (typedGlobalPlugin( ...(args as Parameters), ) as unknown) as ZeppelinGlobalPluginBlueprint; // @ts-ignore FIXME: Check the types here blueprint.configPreprocessor = getPluginConfigPreprocessor(blueprint, blueprint.configPreprocessor); return blueprint; } else { return zeppelinGlobalPlugin as (name, blueprint) => ZeppelinGlobalPluginBlueprint; } }