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

93 lines
3 KiB
TypeScript
Raw Normal View History

import {
BasePluginType,
globalPlugin,
GlobalPluginBlueprint,
GlobalPluginData,
guildPlugin,
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<TPartialBlueprint extends Omit<ZeppelinGuildPluginBlueprint, "name">>(
name: string,
blueprint: TPartialBlueprint,
): TPartialBlueprint & { name: string; configPreprocessor: ZeppelinGuildPluginBlueprint["configPreprocessor"] };
export function zeppelinGuildPlugin<TPluginType extends BasePluginType>(): <
TPartialBlueprint extends Omit<ZeppelinGuildPluginBlueprint<GuildPluginData<TPluginType>>, "name">
>(
name: string,
blueprint: TPartialBlueprint,
) => TPartialBlueprint & {
name: string;
configPreprocessor: ZeppelinGuildPluginBlueprint<GuildPluginData<TPluginType>>["configPreprocessor"];
};
export function zeppelinGuildPlugin(...args) {
if (args.length) {
const blueprint = (guildPlugin(
...(args as Parameters<typeof guildPlugin>),
) 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<TPartialBlueprint extends Omit<ZeppelinGlobalPluginBlueprint, "name">>(
name: string,
blueprint: TPartialBlueprint,
): TPartialBlueprint & { name: string; configPreprocessor: ZeppelinGlobalPluginBlueprint["configPreprocessor"] };
export function zeppelinGlobalPlugin<TPluginType extends BasePluginType>(): <
TPartialBlueprint extends Omit<ZeppelinGlobalPluginBlueprint<TPluginType>, "name">
>(
name: string,
blueprint: TPartialBlueprint,
) => TPartialBlueprint & {
name: string;
configPreprocessor: ZeppelinGlobalPluginBlueprint<TPluginType>["configPreprocessor"];
};
export function zeppelinGlobalPlugin(...args) {
if (args.length) {
const blueprint = (globalPlugin(
...(args as Parameters<typeof globalPlugin>),
) as unknown) as ZeppelinGlobalPluginBlueprint;
2020-07-27 20:42:10 +03:00
blueprint.configPreprocessor = getPluginConfigPreprocessor(blueprint, blueprint.configPreprocessor);
return blueprint;
} else {
return zeppelinGlobalPlugin as (name, blueprint) => ZeppelinGlobalPluginBlueprint;
}
}