2020-11-09 20:03:57 +02:00
|
|
|
import {
|
|
|
|
BasePluginType,
|
|
|
|
globalPlugin,
|
|
|
|
GlobalPluginBlueprint,
|
|
|
|
GlobalPluginData,
|
|
|
|
guildPlugin,
|
|
|
|
GuildPluginBlueprint,
|
|
|
|
GuildPluginData,
|
|
|
|
} from "knub";
|
2020-07-05 05:00:54 +03:00
|
|
|
import * as t from "io-ts";
|
2020-07-22 22:56:21 +03:00
|
|
|
import { getPluginConfigPreprocessor } from "../pluginUtils";
|
2020-07-22 23:11:42 +03:00
|
|
|
import { TMarkdown } from "../types";
|
2020-07-05 05:00:54 +03:00
|
|
|
|
2020-10-01 01:43:38 +03:00
|
|
|
/**
|
|
|
|
* GUILD PLUGINS
|
|
|
|
*/
|
|
|
|
|
2020-11-09 20:03:57 +02:00
|
|
|
export interface ZeppelinGuildPluginBlueprint<TPluginData extends GuildPluginData<any> = GuildPluginData<any>>
|
|
|
|
extends GuildPluginBlueprint<TPluginData> {
|
2020-07-30 20:10:50 +03:00
|
|
|
configSchema: t.TypeC<any>;
|
2020-07-06 02:01:01 +03:00
|
|
|
showInDocs?: boolean;
|
2020-07-22 23:11:42 +03:00
|
|
|
|
|
|
|
info?: {
|
|
|
|
prettyName: string;
|
|
|
|
description?: TMarkdown;
|
|
|
|
usageGuide?: TMarkdown;
|
|
|
|
configurationGuide?: TMarkdown;
|
|
|
|
};
|
2020-07-05 05:00:54 +03:00
|
|
|
}
|
|
|
|
|
2020-10-01 01:43:38 +03:00
|
|
|
export function zeppelinGuildPlugin<TPartialBlueprint extends Omit<ZeppelinGuildPluginBlueprint, "name">>(
|
|
|
|
name: string,
|
|
|
|
blueprint: TPartialBlueprint,
|
|
|
|
): TPartialBlueprint & { name: string; configPreprocessor: ZeppelinGuildPluginBlueprint["configPreprocessor"] };
|
|
|
|
|
|
|
|
export function zeppelinGuildPlugin<TPluginType extends BasePluginType>(): <
|
2020-11-09 20:03:57 +02:00
|
|
|
TPartialBlueprint extends Omit<ZeppelinGuildPluginBlueprint<GuildPluginData<TPluginType>>, "name">
|
2020-10-01 01:43:38 +03:00
|
|
|
>(
|
|
|
|
name: string,
|
|
|
|
blueprint: TPartialBlueprint,
|
|
|
|
) => TPartialBlueprint & {
|
|
|
|
name: string;
|
2020-11-09 20:03:57 +02:00
|
|
|
configPreprocessor: ZeppelinGuildPluginBlueprint<GuildPluginData<TPluginType>>["configPreprocessor"];
|
2020-10-01 01:43:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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>
|
2020-11-09 20:03:57 +02:00
|
|
|
extends GlobalPluginBlueprint<GlobalPluginData<TPluginType>> {
|
2020-10-01 01:43:38 +03:00
|
|
|
configSchema: t.TypeC<any>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function zeppelinGlobalPlugin<TPartialBlueprint extends Omit<ZeppelinGlobalPluginBlueprint, "name">>(
|
2020-07-06 02:01:01 +03:00
|
|
|
name: string,
|
2020-07-22 22:08:20 +03:00
|
|
|
blueprint: TPartialBlueprint,
|
2020-10-01 01:43:38 +03:00
|
|
|
): TPartialBlueprint & { name: string; configPreprocessor: ZeppelinGlobalPluginBlueprint["configPreprocessor"] };
|
2020-07-22 22:08:20 +03:00
|
|
|
|
2020-10-01 01:43:38 +03:00
|
|
|
export function zeppelinGlobalPlugin<TPluginType extends BasePluginType>(): <
|
|
|
|
TPartialBlueprint extends Omit<ZeppelinGlobalPluginBlueprint<TPluginType>, "name">
|
2020-07-22 22:08:20 +03:00
|
|
|
>(
|
|
|
|
name: string,
|
|
|
|
blueprint: TPartialBlueprint,
|
2020-07-30 20:10:50 +03:00
|
|
|
) => TPartialBlueprint & {
|
|
|
|
name: string;
|
2020-10-01 01:43:38 +03:00
|
|
|
configPreprocessor: ZeppelinGlobalPluginBlueprint<TPluginType>["configPreprocessor"];
|
2020-07-30 20:10:50 +03:00
|
|
|
};
|
2020-07-22 22:08:20 +03:00
|
|
|
|
2020-10-01 01:43:38 +03:00
|
|
|
export function zeppelinGlobalPlugin(...args) {
|
2020-07-05 05:00:54 +03:00
|
|
|
if (args.length) {
|
2020-10-01 01:43:38 +03:00
|
|
|
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);
|
2020-07-05 05:00:54 +03:00
|
|
|
return blueprint;
|
|
|
|
} else {
|
2020-10-01 01:43:38 +03:00
|
|
|
return zeppelinGlobalPlugin as (name, blueprint) => ZeppelinGlobalPluginBlueprint;
|
2020-07-05 05:00:54 +03:00
|
|
|
}
|
|
|
|
}
|