diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..73ac8239 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "tabWidth": 4, + "useTabs": true, + "printWidth": 140 +} diff --git a/package-lock.json b/package-lock.json index 076f89c7..cdbef42d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2289,7 +2289,7 @@ }, "node_modules/fosscord-server-util": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#3bdbd9340edf4f3edd728624499dbcaaf08a25ed", + "resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#18498d6515e43eb764eb26c9ec3a35ce515c4257", "license": "ISC", "dependencies": { "jsonwebtoken": "^8.5.1", @@ -8151,7 +8151,7 @@ "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" }, "fosscord-server-util": { - "version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#3bdbd9340edf4f3edd728624499dbcaaf08a25ed", + "version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#18498d6515e43eb764eb26c9ec3a35ce515c4257", "from": "fosscord-server-util@github:fosscord/fosscord-server-util", "requires": { "jsonwebtoken": "^8.5.1", diff --git a/src/schema/Channel.ts b/src/schema/Channel.ts new file mode 100644 index 00000000..2e7d1214 --- /dev/null +++ b/src/schema/Channel.ts @@ -0,0 +1,51 @@ +import { Length } from "../util/instanceOf"; + +export const ChannelModifySchema = { + name: new Length(String, 2, 100), + type: Number, + $topic: new Length(String, 0, 1024), + $bitrate: Number, + $user_limit: Number, + $rate_limit_per_user: new Length(Number, 0, 21600), + $position: Number, + $permission_overwrites: [ + { + id: BigInt, + type: new Length(Number, 0, 1), // either 0 (role) or 1 (member) + allow: BigInt, + deny: BigInt, + }, + ], + $parent_id: BigInt, + $nsfw: Boolean, +}; + +export interface ChannelModifySchema { + name: string; + type: number; + topic?: string; + bitrate?: number; + user_limit?: number; + rate_limit_per_user?: Number; + position?: number; + permission_overwrites?: { + id: bigint; + type: number; + allow: bigint; + deny: bigint; + }[]; + parent_id?: bigint; + nsfw?: boolean; +} + +export const ChannelGuildPositionUpdateSchema = [ + { + id: BigInt, + $position: Number, + }, +]; + +export type ChannelGuildPositionUpdateSchema = { + id: bigint; + position?: number; +}[]; diff --git a/src/schema/Message.ts b/src/schema/Message.ts new file mode 100644 index 00000000..80897f9d --- /dev/null +++ b/src/schema/Message.ts @@ -0,0 +1,27 @@ +export const MessageCreateSchema = { + content: String, + nonce: Number, + tts: Boolean, + embed: {}, + allowed_mentions: [], + message_reference: { + message_id: BigInt, + channel_id: BigInt, + guild_id: BigInt, + fail_if_not_exists: Boolean, + }, +}; + +export interface MessageCreateSchema { + content: string; + nonce: number; + tts: boolean; + embed: {}; + allowed_mentions: []; + message_reference: { + message_id: bigint; + channel_id: bigint; + guild_id: bigint; + fail_if_not_exists: boolean; + }; +} diff --git a/src/util/Config.ts b/src/util/Config.ts index cfdb0d1e..cd225407 100644 --- a/src/util/Config.ts +++ b/src/util/Config.ts @@ -45,6 +45,7 @@ export interface DefaultOptions { ttsCharacters: number; maxReactions: number; maxAttachmentSize: number; + maxBulkDelete: number; }; channel: { maxPins: number; @@ -124,6 +125,7 @@ export const DefaultOptions: DefaultOptions = { ttsCharacters: 200, maxReactions: 20, maxAttachmentSize: 8388608, + maxBulkDelete: 100, }, channel: { maxPins: 50, diff --git a/src/util/Event.ts b/src/util/Event.ts index 31838583..43c51d5c 100644 --- a/src/util/Event.ts +++ b/src/util/Event.ts @@ -8,3 +8,5 @@ export async function emitEvent(payload: Omit) { return await new EventModel(obj).save(); } + +export async function emitAuditLog(payload: any) {} diff --git a/src/util/instanceOf.ts b/src/util/instanceOf.ts index b5b2f587..bbb30c12 100644 --- a/src/util/instanceOf.ts +++ b/src/util/instanceOf.ts @@ -114,35 +114,10 @@ export function instanceOf( } if (typeof type === "object") { - if (type?.constructor?.name != "Object") { - if (type instanceof Tuple) { - if ((type).types.some((x) => instanceOf(x, value, { path, optional, errors, req, ref }))) - return true; - throw new FieldError( - "BASE_TYPE_CHOICES", - req.t("common:field.BASE_TYPE_CHOICES", { types: type.types }) - ); - } else if (type instanceof Length) { - let length = type; - if (instanceOf(length.type, value, { path, optional, req, ref, errors }) !== true) return errors; - let val = ref.obj[ref.key]; - if ((type).check(val)) return true; - throw new FieldError( - "BASE_TYPE_BAD_LENGTH", - req.t("common:field.BASE_TYPE_BAD_LENGTH", { - length: `${type.min} - ${type.max}`, - }) - ); - } - if (value instanceof type) return true; - throw new FieldError("BASE_TYPE_CLASS", req.t("common:field.BASE_TYPE_CLASS", { type })); - } - if (typeof value !== "object") - throw new FieldError("BASE_TYPE_OBJECT", req.t("common:field.BASE_TYPE_OBJECT")); + if (typeof value !== "object") throw new FieldError("BASE_TYPE_OBJECT", req.t("common:field.BASE_TYPE_OBJECT")); if (Array.isArray(type)) { - if (!Array.isArray(value)) - throw new FieldError("BASE_TYPE_ARRAY", req.t("common:field.BASE_TYPE_ARRAY")); + if (!Array.isArray(value)) throw new FieldError("BASE_TYPE_ARRAY", req.t("common:field.BASE_TYPE_ARRAY")); if (!type.length) return true; // type array didn't specify any type return ( @@ -159,6 +134,24 @@ export function instanceOf( ); }) || errors ); + } else if (type?.constructor?.name != "Object") { + if (type instanceof Tuple) { + if ((type).types.some((x) => instanceOf(x, value, { path, optional, errors, req, ref }))) return true; + throw new FieldError("BASE_TYPE_CHOICES", req.t("common:field.BASE_TYPE_CHOICES", { types: type.types })); + } else if (type instanceof Length) { + let length = type; + if (instanceOf(length.type, value, { path, optional, req, ref, errors }) !== true) return errors; + let val = ref.obj[ref.key]; + if ((type).check(val)) return true; + throw new FieldError( + "BASE_TYPE_BAD_LENGTH", + req.t("common:field.BASE_TYPE_BAD_LENGTH", { + length: `${type.min} - ${type.max}`, + }) + ); + } + if (value instanceof type) return true; + throw new FieldError("BASE_TYPE_CLASS", req.t("common:field.BASE_TYPE_CLASS", { type })); } const diff = Object.keys(value).missing(