2021-06-06 23:51:32 +02:00
|
|
|
import * as t from "io-ts";
|
2020-11-09 20:03:57 +02:00
|
|
|
import {
|
2021-06-08 02:23:30 +02:00
|
|
|
BasePluginType,
|
|
|
|
GlobalPluginBlueprint,
|
|
|
|
GlobalPluginData,
|
|
|
|
GuildPluginBlueprint,
|
|
|
|
GuildPluginData,
|
|
|
|
typedGlobalPlugin,
|
|
|
|
typedGuildPlugin,
|
2020-11-09 20:03:57 +02:00
|
|
|
} from "knub";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { PluginOptions } from "knub/dist/config/configTypes";
|
|
|
|
import { Awaitable } from "knub/dist/utils";
|
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;
|
|
|
|
};
|
2021-05-23 18:10:23 +03:00
|
|
|
|
|
|
|
configPreprocessor?: (
|
|
|
|
options: PluginOptions<TPluginData["_pluginType"]>,
|
|
|
|
strict?: boolean,
|
|
|
|
) => Awaitable<PluginOptions<TPluginData["_pluginType"]>>;
|
2020-07-05 05:00:54 +03:00
|
|
|
}
|
|
|
|
|
2021-05-23 14:35:16 +03:00
|
|
|
export function zeppelinGuildPlugin<TBlueprint extends ZeppelinGuildPluginBlueprint>(
|
|
|
|
blueprint: TBlueprint,
|
|
|
|
): TBlueprint & { configPreprocessor: ZeppelinGuildPluginBlueprint["configPreprocessor"] };
|
2020-10-01 01:43:38 +03:00
|
|
|
|
|
|
|
export function zeppelinGuildPlugin<TPluginType extends BasePluginType>(): <
|
2021-05-23 14:35:16 +03:00
|
|
|
TBlueprint extends ZeppelinGuildPluginBlueprint<GuildPluginData<TPluginType>>
|
2020-10-01 01:43:38 +03:00
|
|
|
>(
|
2021-05-23 14:35:16 +03:00
|
|
|
blueprint: TBlueprint,
|
|
|
|
) => TBlueprint & {
|
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) {
|
2021-05-23 14:35:16 +03:00
|
|
|
const blueprint = (typedGuildPlugin(
|
|
|
|
...(args as Parameters<typeof typedGuildPlugin>),
|
2020-10-01 01:43:38 +03:00
|
|
|
) 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>;
|
2021-05-23 18:10:23 +03:00
|
|
|
configPreprocessor?: (options: PluginOptions<TPluginType>, strict?: boolean) => Awaitable<PluginOptions<TPluginType>>;
|
2020-10-01 01:43:38 +03:00
|
|
|
}
|
|
|
|
|
2021-05-23 14:35:16 +03:00
|
|
|
export function zeppelinGlobalPlugin<TBlueprint extends ZeppelinGlobalPluginBlueprint>(
|
|
|
|
blueprint: TBlueprint,
|
|
|
|
): TBlueprint & { 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>(): <
|
2021-05-23 14:35:16 +03:00
|
|
|
TBlueprint extends ZeppelinGlobalPluginBlueprint<TPluginType>
|
2020-07-22 22:08:20 +03:00
|
|
|
>(
|
2021-05-23 14:35:16 +03:00
|
|
|
blueprint: TBlueprint,
|
|
|
|
) => TBlueprint & {
|
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) {
|
2021-05-23 14:35:16 +03:00
|
|
|
const blueprint = (typedGlobalPlugin(
|
|
|
|
...(args as Parameters<typeof typedGlobalPlugin>),
|
2020-10-01 01:43:38 +03:00
|
|
|
) as unknown) as ZeppelinGlobalPluginBlueprint;
|
2021-05-23 14:35:16 +03:00
|
|
|
// @ts-ignore FIXME: Check the types here
|
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
|
|
|
}
|
|
|
|
}
|