mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
chore: run prettier
This commit is contained in:
parent
77ab2718e7
commit
873bf7eb99
54 changed files with 462 additions and 416 deletions
|
@ -1,10 +1,7 @@
|
|||
import { EventEmitter } from "events";
|
||||
import { PluginOptions } from "knub";
|
||||
import { GuildCounters } from "../../data/GuildCounters";
|
||||
import {
|
||||
CounterTrigger,
|
||||
parseCounterConditionString
|
||||
} from "../../data/entities/CounterTrigger";
|
||||
import { CounterTrigger, parseCounterConditionString } from "../../data/entities/CounterTrigger";
|
||||
import { mapToPublicFn } from "../../pluginUtils";
|
||||
import { MINUTES, convertDelayStringToMS, values } from "../../utils";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
|
|
|
@ -2,33 +2,45 @@ import { EventEmitter } from "events";
|
|||
import { BasePluginType } from "knub";
|
||||
import z from "zod";
|
||||
import { GuildCounters } from "../../data/GuildCounters";
|
||||
import { CounterTrigger, buildCounterConditionString, getReverseCounterComparisonOp, parseCounterConditionString } from "../../data/entities/CounterTrigger";
|
||||
import {
|
||||
CounterTrigger,
|
||||
buildCounterConditionString,
|
||||
getReverseCounterComparisonOp,
|
||||
parseCounterConditionString,
|
||||
} from "../../data/entities/CounterTrigger";
|
||||
import { zBoundedCharacters, zBoundedRecord, zDelayString } from "../../utils";
|
||||
import Timeout = NodeJS.Timeout;
|
||||
|
||||
const MAX_COUNTERS = 5;
|
||||
const MAX_TRIGGERS_PER_COUNTER = 5;
|
||||
|
||||
export const zTrigger = z.strictObject({
|
||||
// Dummy type because name gets replaced by the property key in transform()
|
||||
name: z.never().optional().transform(() => ""),
|
||||
pretty_name: zBoundedCharacters(0, 100).nullable().default(null),
|
||||
condition: zBoundedCharacters(1, 64).refine(
|
||||
(str) => parseCounterConditionString(str) !== null,
|
||||
{ message: "Invalid counter trigger condition" },
|
||||
),
|
||||
reverse_condition: zBoundedCharacters(1, 64).refine(
|
||||
(str) => parseCounterConditionString(str) !== null,
|
||||
{ message: "Invalid counter trigger reverse condition" },
|
||||
).optional(),
|
||||
})
|
||||
export const zTrigger = z
|
||||
.strictObject({
|
||||
// Dummy type because name gets replaced by the property key in transform()
|
||||
name: z
|
||||
.never()
|
||||
.optional()
|
||||
.transform(() => ""),
|
||||
pretty_name: zBoundedCharacters(0, 100).nullable().default(null),
|
||||
condition: zBoundedCharacters(1, 64).refine((str) => parseCounterConditionString(str) !== null, {
|
||||
message: "Invalid counter trigger condition",
|
||||
}),
|
||||
reverse_condition: zBoundedCharacters(1, 64)
|
||||
.refine((str) => parseCounterConditionString(str) !== null, {
|
||||
message: "Invalid counter trigger reverse condition",
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.transform((val, ctx) => {
|
||||
const ruleName = String(ctx.path[ctx.path.length - 2]).trim();
|
||||
|
||||
let reverseCondition = val.reverse_condition;
|
||||
if (! reverseCondition) {
|
||||
if (!reverseCondition) {
|
||||
const parsedCondition = parseCounterConditionString(val.condition)!;
|
||||
reverseCondition = buildCounterConditionString(getReverseCounterComparisonOp(parsedCondition[0]), parsedCondition[1]);
|
||||
reverseCondition = buildCounterConditionString(
|
||||
getReverseCounterComparisonOp(parsedCondition[0]),
|
||||
parsedCondition[1],
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -38,68 +50,65 @@ export const zTrigger = z.strictObject({
|
|||
};
|
||||
});
|
||||
|
||||
const zTriggerFromString = zBoundedCharacters(0, 100)
|
||||
.transform((val, ctx) => {
|
||||
const ruleName = String(ctx.path[ctx.path.length - 2]).trim();
|
||||
const parsedCondition = parseCounterConditionString(val);
|
||||
if (!parsedCondition) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Invalid counter trigger condition",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return {
|
||||
name: ruleName,
|
||||
pretty_name: null,
|
||||
condition: buildCounterConditionString(parsedCondition[0], parsedCondition[1]),
|
||||
reverse_condition: buildCounterConditionString(getReverseCounterComparisonOp(parsedCondition[0]), parsedCondition[1]),
|
||||
};
|
||||
});
|
||||
const zTriggerFromString = zBoundedCharacters(0, 100).transform((val, ctx) => {
|
||||
const ruleName = String(ctx.path[ctx.path.length - 2]).trim();
|
||||
const parsedCondition = parseCounterConditionString(val);
|
||||
if (!parsedCondition) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Invalid counter trigger condition",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return {
|
||||
name: ruleName,
|
||||
pretty_name: null,
|
||||
condition: buildCounterConditionString(parsedCondition[0], parsedCondition[1]),
|
||||
reverse_condition: buildCounterConditionString(
|
||||
getReverseCounterComparisonOp(parsedCondition[0]),
|
||||
parsedCondition[1],
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
const zTriggerInput = z.union([zTrigger, zTriggerFromString]);
|
||||
|
||||
export const zCounter = z.strictObject({
|
||||
// Typed as "never" because you are not expected to supply this directly.
|
||||
// The transform instead picks it up from the property key and the output type is a string.
|
||||
name: z.never().optional().transform((_, ctx) => {
|
||||
const ruleName = String(ctx.path[ctx.path.length - 2]).trim();
|
||||
if (! ruleName) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Counters must have names",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return ruleName;
|
||||
}),
|
||||
name: z
|
||||
.never()
|
||||
.optional()
|
||||
.transform((_, ctx) => {
|
||||
const ruleName = String(ctx.path[ctx.path.length - 2]).trim();
|
||||
if (!ruleName) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Counters must have names",
|
||||
});
|
||||
return z.NEVER;
|
||||
}
|
||||
return ruleName;
|
||||
}),
|
||||
pretty_name: zBoundedCharacters(0, 100).nullable().default(null),
|
||||
per_channel: z.boolean().default(false),
|
||||
per_user: z.boolean().default(false),
|
||||
initial_value: z.number().default(0),
|
||||
triggers: zBoundedRecord(
|
||||
z.record(
|
||||
zBoundedCharacters(0, 100),
|
||||
zTriggerInput,
|
||||
),
|
||||
1,
|
||||
MAX_TRIGGERS_PER_COUNTER,
|
||||
),
|
||||
decay: z.strictObject({
|
||||
amount: z.number(),
|
||||
every: zDelayString,
|
||||
}).nullable().default(null),
|
||||
triggers: zBoundedRecord(z.record(zBoundedCharacters(0, 100), zTriggerInput), 1, MAX_TRIGGERS_PER_COUNTER),
|
||||
decay: z
|
||||
.strictObject({
|
||||
amount: z.number(),
|
||||
every: zDelayString,
|
||||
})
|
||||
.nullable()
|
||||
.default(null),
|
||||
can_view: z.boolean().default(false),
|
||||
can_edit: z.boolean().default(false),
|
||||
can_reset_all: z.boolean().default(false),
|
||||
});
|
||||
|
||||
export const zCountersConfig = z.strictObject({
|
||||
counters: zBoundedRecord(
|
||||
z.record(zBoundedCharacters(0, 100), zCounter),
|
||||
0,
|
||||
MAX_COUNTERS,
|
||||
),
|
||||
counters: zBoundedRecord(z.record(zBoundedCharacters(0, 100), zCounter), 0, MAX_COUNTERS),
|
||||
can_view: z.boolean(),
|
||||
can_edit: z.boolean(),
|
||||
can_reset_all: z.boolean(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue