mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
ZeppelinPluginBlueprint.configSchema is now required. Validate deep partial config schema before running config preprocessor.
This commit is contained in:
parent
3265a2a8da
commit
f6d55f1060
10 changed files with 50 additions and 12 deletions
|
@ -1,9 +1,11 @@
|
|||
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { ChannelArchiverPluginType } from "./types";
|
||||
import { ArchiveChannelCmd } from "./commands/ArchiveChannelCmd";
|
||||
import * as t from "io-ts";
|
||||
|
||||
export const ChannelArchiverPlugin = zeppelinPlugin<ChannelArchiverPluginType>()("channel_archiver", {
|
||||
showInDocs: false,
|
||||
configSchema: t.type({}),
|
||||
|
||||
// prettier-ignore
|
||||
commands: [
|
||||
|
|
|
@ -2,8 +2,13 @@ import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
|
|||
import { GuildConfigReloaderPluginType } from "./types";
|
||||
import { Configs } from "../../data/Configs";
|
||||
import { reloadChangedGuilds } from "./functions/reloadChangedGuilds";
|
||||
import * as t from "io-ts";
|
||||
|
||||
export const GuildConfigReloaderPlugin = zeppelinPlugin<GuildConfigReloaderPluginType>()("guild_config_reloader", {
|
||||
showInDocs: false,
|
||||
|
||||
configSchema: t.type({}),
|
||||
|
||||
async onLoad(pluginData) {
|
||||
pluginData.state.guildConfigs = new Configs();
|
||||
pluginData.state.highestConfigId = await pluginData.state.guildConfigs.getHighestId();
|
||||
|
|
|
@ -3,10 +3,13 @@ import { PluginData } from "knub";
|
|||
import { AllowedGuilds } from "src/data/AllowedGuilds";
|
||||
import { GuildInfoSaverPluginType } from "./types";
|
||||
import { MINUTES } from "src/utils";
|
||||
import * as t from "io-ts";
|
||||
|
||||
export const GuildInfoSaverPlugin = zeppelinPlugin<GuildInfoSaverPluginType>()("guild_info_saver", {
|
||||
showInDocs: false,
|
||||
|
||||
configSchema: t.type({}),
|
||||
|
||||
onLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
const emojiRolePairs: TReactionRolePair[] = args.reactionRolePairs
|
||||
.trim()
|
||||
.split("\n")
|
||||
.map(v => v.split("=").map(v => v.trim())) // tslint:disable-line
|
||||
.map(v => v.split(/(\s|[=,])+/).map(v => v.trim())) // tslint:disable-line
|
||||
.map(
|
||||
(pair): TReactionRolePair => {
|
||||
const customEmojiMatch = pair[0].match(/^<a?:(.*?):(\d+)>$/);
|
||||
|
|
|
@ -14,7 +14,6 @@ export const RefreshReactionRolesCmd = reactionRolesCmd({
|
|||
async run({ message: msg, args, pluginData }) {
|
||||
const savedMessage = await pluginData.state.savedMessages.find(args.messageId);
|
||||
if (!savedMessage) {
|
||||
console.log("ah");
|
||||
sendErrorMessage(pluginData, msg.channel, "Unknown message");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,13 @@ import { UsernameHistory } from "src/data/UsernameHistory";
|
|||
import { Queue } from "src/Queue";
|
||||
import { UsernameSaverPluginType } from "./types";
|
||||
import { MessageCreateUpdateUsernameEvt, VoiceChannelJoinUpdateUsernameEvt } from "./events/UpdateUsernameEvts";
|
||||
import * as t from "io-ts";
|
||||
|
||||
export const UsernameSaverPlugin = zeppelinPlugin<UsernameSaverPluginType>()("username_saver", {
|
||||
showInDocs: false,
|
||||
|
||||
configSchema: t.type({}),
|
||||
|
||||
// prettier-ignore
|
||||
events: [
|
||||
MessageCreateUpdateUsernameEvt,
|
||||
|
|
|
@ -5,7 +5,7 @@ import { TMarkdown } from "../types";
|
|||
|
||||
export interface ZeppelinPluginBlueprint<TPluginType extends BasePluginType = BasePluginType>
|
||||
extends PluginBlueprint<TPluginType> {
|
||||
configSchema?: t.TypeC<any>;
|
||||
configSchema: t.TypeC<any>;
|
||||
showInDocs?: boolean;
|
||||
|
||||
info?: {
|
||||
|
@ -19,21 +19,24 @@ export interface ZeppelinPluginBlueprint<TPluginType extends BasePluginType = Ba
|
|||
export function zeppelinPlugin<TPartialBlueprint extends Omit<ZeppelinPluginBlueprint, "name">>(
|
||||
name: string,
|
||||
blueprint: TPartialBlueprint,
|
||||
): TPartialBlueprint & { name: string };
|
||||
): TPartialBlueprint & { name: string; configPreprocessor: ZeppelinPluginBlueprint["configPreprocessor"] };
|
||||
|
||||
export function zeppelinPlugin<TPluginType extends BasePluginType>(): <
|
||||
TPartialBlueprint extends Omit<ZeppelinPluginBlueprint<TPluginType>, "name">
|
||||
>(
|
||||
name: string,
|
||||
blueprint: TPartialBlueprint,
|
||||
) => TPartialBlueprint & { name: string; configPreprocessor: PluginBlueprint<TPluginType>["configPreprocessor"] };
|
||||
) => TPartialBlueprint & {
|
||||
name: string;
|
||||
configPreprocessor: ZeppelinPluginBlueprint<TPluginType>["configPreprocessor"];
|
||||
};
|
||||
|
||||
export function zeppelinPlugin(...args) {
|
||||
if (args.length) {
|
||||
const blueprint: ZeppelinPluginBlueprint = plugin(...(args as Parameters<typeof plugin>));
|
||||
const blueprint = (plugin(...(args as Parameters<typeof plugin>)) as unknown) as ZeppelinPluginBlueprint;
|
||||
blueprint.configPreprocessor = getPluginConfigPreprocessor(blueprint, blueprint.configPreprocessor);
|
||||
return blueprint;
|
||||
} else {
|
||||
return zeppelinPlugin;
|
||||
return zeppelinPlugin as (name, blueprint) => ZeppelinPluginBlueprint;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue