Skip to content

Commit

Permalink
feat: add message rule types
Browse files Browse the repository at this point in the history
  • Loading branch information
virtual-designer committed Aug 22, 2023
1 parent 4963231 commit b6be033
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/types/GuildConfigSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { z } from "zod";
import { isSnowflake } from "../utils/utils";
import { MessageRuleSchema } from "./MessageRuleSchema";

const zSnowflake = z.custom<string>(data => {
return typeof data === "string" && isSnowflake(data);
Expand Down Expand Up @@ -255,6 +256,13 @@ export const GuildConfigSchema = z.object({
disabled_channels: z.array(zSnowflake).default([]),
blocked_hashes: z.record(z.string(), z.string().nullable()).default({})
})
.optional(),
message_rules: z
.object({
enabled: z.boolean().default(false),
rules: z.array(MessageRuleSchema).default([]),
global_disabled_channels: z.array(zSnowflake).default([])
})
.optional()
});

Expand Down
41 changes: 41 additions & 0 deletions src/types/MessageRuleSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { z } from "zod";

export const MessageRuleAction = z.enum(["delete", "verbal_warn", "warn", "mute", "clear"]);

const hasStringArrayData = {
data: z.array(z.string()).default([])
};

const Common = {
actions: z.array(MessageRuleAction).default([]),
verbal_warning_reason: z.string().optional(),
warning_reason: z.string().optional(),
mute_reason: z.string().optional(),
common_reason: z.string().optional(),
mute_duration: z.number().int().default(-1)
};

export const BlockedDomainRule = z
.object({
type: z.literal("blocked_domain"),
scan_links_only: z.boolean().default(false)
})
.extend(Common)
.extend(hasStringArrayData);

export const BlockedMimeTypeRule = z
.object({
type: z.literal("blocked_mime_type")
})
.extend(Common)
.extend(hasStringArrayData);

export const BlockedFileExtensionRule = z
.object({
type: z.literal("blocked_file_extension")
})
.extend(Common)
.extend(hasStringArrayData);

export const MessageRuleSchema = z.union([BlockedDomainRule, BlockedMimeTypeRule, BlockedFileExtensionRule]);
export type MessageRuleType = z.infer<typeof MessageRuleSchema>;

0 comments on commit b6be033

Please sign in to comment.