import { BasePluginType, typedGlobalPlugin, GlobalPluginBlueprint, GlobalPluginData, typedGuildPlugin, GuildPluginBlueprint, GuildPluginData, } from "knub"; import * as t from "io-ts"; 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; }; } 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; } 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; } }