3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-19 07:20:00 +00:00
zeppelin/backend/src/plugins/ZeppelinPluginBlueprint.ts

88 lines
2.8 KiB
TypeScript
Raw Normal View History

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<TPluginData extends GuildPluginData<any> = GuildPluginData<any>>
extends GuildPluginBlueprint<TPluginData> {
configSchema: t.TypeC<any>;
showInDocs?: boolean;
info?: {
prettyName: string;
description?: TMarkdown;
usageGuide?: TMarkdown;
configurationGuide?: TMarkdown;
};
}
export function zeppelinGuildPlugin<TBlueprint extends ZeppelinGuildPluginBlueprint>(
blueprint: TBlueprint,
): TBlueprint & { configPreprocessor: ZeppelinGuildPluginBlueprint["configPreprocessor"] };
export function zeppelinGuildPlugin<TPluginType extends BasePluginType>(): <
TBlueprint extends ZeppelinGuildPluginBlueprint<GuildPluginData<TPluginType>>
>(
blueprint: TBlueprint,
) => TBlueprint & {
configPreprocessor: ZeppelinGuildPluginBlueprint<GuildPluginData<TPluginType>>["configPreprocessor"];
};
export function zeppelinGuildPlugin(...args) {
if (args.length) {
const blueprint = (typedGuildPlugin(
...(args as Parameters<typeof typedGuildPlugin>),
) as unknown) as ZeppelinGuildPluginBlueprint;
blueprint.configPreprocessor = getPluginConfigPreprocessor(blueprint, blueprint.configPreprocessor);
return blueprint;
} else {
return zeppelinGuildPlugin as (name, blueprint) => ZeppelinGuildPluginBlueprint;
}
}
/**
* GLOBAL PLUGINS
*/
export interface ZeppelinGlobalPluginBlueprint<TPluginType extends BasePluginType = BasePluginType>
extends GlobalPluginBlueprint<GlobalPluginData<TPluginType>> {
configSchema: t.TypeC<any>;
}
export function zeppelinGlobalPlugin<TBlueprint extends ZeppelinGlobalPluginBlueprint>(
blueprint: TBlueprint,
): TBlueprint & { configPreprocessor: ZeppelinGlobalPluginBlueprint["configPreprocessor"] };
export function zeppelinGlobalPlugin<TPluginType extends BasePluginType>(): <
TBlueprint extends ZeppelinGlobalPluginBlueprint<TPluginType>
>(
blueprint: TBlueprint,
) => TBlueprint & {
configPreprocessor: ZeppelinGlobalPluginBlueprint<TPluginType>["configPreprocessor"];
};
export function zeppelinGlobalPlugin(...args) {
if (args.length) {
const blueprint = (typedGlobalPlugin(
...(args as Parameters<typeof typedGlobalPlugin>),
) as unknown) as ZeppelinGlobalPluginBlueprint;
// @ts-ignore FIXME: Check the types here
2020-07-27 20:42:10 +03:00
blueprint.configPreprocessor = getPluginConfigPreprocessor(blueprint, blueprint.configPreprocessor);
return blueprint;
} else {
return zeppelinGlobalPlugin as (name, blueprint) => ZeppelinGlobalPluginBlueprint;
}
}