Move schemas to /src/util/schemas

This commit is contained in:
Madeline
2022-09-26 22:08:14 +10:00
parent 186f28516c
commit 849b257db7
94 changed files with 463 additions and 508 deletions
+60
View File
@@ -0,0 +1,60 @@
import { Activity, Status } from "@fosscord/util";
export const ActivitySchema = {
afk: Boolean,
status: String,
$activities: [
{
name: String,
type: Number,
$url: String,
$created_at: Date,
$timestamps: {
$start: Number,
$end: Number,
},
$application_id: String,
$details: String,
$state: String,
$emoji: {
$name: String,
$id: String,
$animated: Boolean,
},
$party: {
$id: String,
$size: [Number, Number],
},
$assets: {
$large_image: String,
$large_text: String,
$small_image: String,
$small_text: String,
},
$secrets: {
$join: String,
$spectate: String,
$match: String,
},
$instance: Boolean,
$flags: String,
$id: String,
$sync_id: String,
$metadata: { // spotify
$context_uri: String,
album_id: String,
artist_ids: [String],
},
$session_id: String,
},
],
$since: Number, // unix time (in milliseconds) of when the client went idle, or null if the client is not idle
};
export interface ActivitySchema {
afk: boolean;
status: Status;
activities?: Activity[];
since?: number; // unix time (in milliseconds) of when the client went idle, or null if the client is not idle
}
@@ -0,0 +1,3 @@
export interface BackupCodesChallengeSchema {
password: string;
}
+4
View File
@@ -0,0 +1,4 @@
export interface BanCreateSchema {
delete_message_days?: string;
reason?: string;
};
+7
View File
@@ -0,0 +1,7 @@
export interface BanModeratorSchema {
id: string;
user_id: string;
guild_id: string;
executor_id: string;
reason?: string | undefined;
};
+8
View File
@@ -0,0 +1,8 @@
export interface BanRegistrySchema {
id: string;
user_id: string;
guild_id: string;
executor_id: string;
ip?: string;
reason?: string | undefined;
};
+3
View File
@@ -0,0 +1,3 @@
export interface BulkDeleteSchema {
messages: string[];
}
+30
View File
@@ -0,0 +1,30 @@
import { ChannelPermissionOverwriteType, ChannelType } from "@fosscord/util";
export interface ChannelModifySchema {
/**
* @maxLength 100
*/
name?: string;
type?: ChannelType;
topic?: string;
icon?: string | null;
bitrate?: number;
user_limit?: number;
rate_limit_per_user?: number;
position?: number;
permission_overwrites?: {
id: string;
type: ChannelPermissionOverwriteType;
allow: string;
deny: string;
}[];
parent_id?: string;
id?: string; // is not used (only for guild create)
nsfw?: boolean;
rtc_region?: string;
default_auto_archive_duration?: number;
default_reaction_emoji?: string | null;
flags?: number;
default_thread_rate_limit_per_user?: number;
video_quality_mode?: number;
}
@@ -0,0 +1,5 @@
export interface CodesVerificationSchema {
key: string;
nonce: string;
regenerate?: boolean;
}
@@ -0,0 +1,4 @@
export interface DmChannelCreateSchema {
name?: string;
recipients: string[];
}
+6
View File
@@ -0,0 +1,6 @@
export interface EmojiCreateSchema {
name?: string;
image: string;
require_colons?: boolean | null;
roles?: string[];
}
+4
View File
@@ -0,0 +1,4 @@
export interface EmojiModifySchema {
name?: string;
roles?: string[];
}
+14
View File
@@ -0,0 +1,14 @@
import { ChannelModifySchema } from ".";
export interface GuildCreateSchema {
/**
* @maxLength 100
*/
name?: string;
region?: string;
icon?: string | null;
channels?: ChannelModifySchema[];
guild_template_code?: string;
system_channel_id?: string;
rules_channel_id?: string;
}
@@ -0,0 +1,4 @@
export interface GuildTemplateCreateSchema {
name: string;
avatar?: string | null;
}
@@ -0,0 +1,10 @@
export interface GuildUpdateWelcomeScreenSchema {
welcome_channels?: {
channel_id: string;
description: string;
emoji_id?: string;
emoji_name?: string;
}[];
enabled?: boolean;
description?: string;
}
+106
View File
@@ -0,0 +1,106 @@
import { ActivitySchema } from "@fosscord/util";
export const IdentifySchema = {
token: String,
$intents: BigInt, // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt
$properties: Object,
// {
// // discord uses $ in the property key for bots, so we need to double prefix it, because instanceOf treats $ (prefix) as a optional key
// $os: String,
// $os_arch: String,
// $browser: String,
// $device: String,
// $$os: String,
// $$browser: String,
// $$device: String,
// $browser_user_agent: String,
// $browser_version: String,
// $os_version: String,
// $referrer: String,
// $$referrer: String,
// $referring_domain: String,
// $$referring_domain: String,
// $referrer_current: String,
// $referring_domain_current: String,
// $release_channel: String,
// $client_build_number: Number,
// $client_event_source: String,
// $client_version: String,
// $system_locale: String,
// $window_manager: String,
// $distro: String,
// },
$presence: ActivitySchema,
$compress: Boolean,
$large_threshold: Number,
$shard: [BigInt, BigInt],
$guild_subscriptions: Boolean,
$capabilities: Number,
$client_state: {
$guild_hashes: Object,
$highest_last_message_id: String || Number,
$read_state_version: Number,
$user_guild_settings_version: Number,
$user_settings_version: undefined,
$useruser_guild_settings_version: undefined,
},
$clientState: {
$guildHashes: Object,
$highestLastMessageId: String || Number,
$readStateVersion: Number,
$useruserGuildSettingsVersion: undefined,
$userGuildSettingsVersion: undefined,
},
$v: Number,
$version: Number,
};
export interface IdentifySchema {
token: string;
properties: {
// bruh discord really uses $ in the property key, so we need to double prefix it, because instanceOf treats $ (prefix) as a optional key
os?: string;
os_atch?: string;
browser?: string;
device?: string;
$os?: string;
$browser?: string;
$device?: string;
browser_user_agent?: string;
browser_version?: string;
os_version?: string;
referrer?: string;
referring_domain?: string;
referrer_current?: string;
referring_domain_current?: string;
release_channel?: "stable" | "dev" | "ptb" | "canary";
client_build_number?: number;
client_event_source?: any;
client_version?: string;
system_locale?: string;
};
intents?: bigint; // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt
presence?: ActivitySchema;
compress?: boolean;
large_threshold?: number;
largeThreshold?: number;
shard?: [bigint, bigint];
guild_subscriptions?: boolean;
capabilities?: number;
client_state?: {
guild_hashes?: any;
highest_last_message_id?: string | number;
read_state_version?: number;
user_guild_settings_version?: number;
user_settings_version?: number;
useruser_guild_settings_version?: number;
};
clientState?: {
guildHashes?: any;
highestLastMessageId?: string | number;
readStateVersion?: number;
userGuildSettingsVersion?: number;
useruserGuildSettingsVersion?: number;
};
v?: number;
}
+11
View File
@@ -0,0 +1,11 @@
export interface InviteCreateSchema {
target_user_id?: string;
target_type?: string;
validate?: string; // ? what is this
max_age?: number;
max_uses?: number;
temporary?: boolean;
unique?: boolean;
target_user?: string;
target_user_type?: number;
}
+19
View File
@@ -0,0 +1,19 @@
export interface LazyRequestSchema {
guild_id: string;
channels?: Record<string, [number, number][]>;
activities?: boolean;
threads?: boolean;
typing?: true;
members?: any[];
thread_member_lists?: any[];
}
export const LazyRequestSchema = {
guild_id: String,
$activities: Boolean,
$channels: Object,
$typing: Boolean,
$threads: Boolean,
$members: [] as any[],
$thread_member_lists: [] as any[],
};
+8
View File
@@ -0,0 +1,8 @@
export interface LoginSchema {
login: string;
password: string;
undelete?: boolean;
captcha_key?: string;
login_source?: string;
gift_code_sku_id?: string;
}
+4
View File
@@ -0,0 +1,4 @@
export interface MemberChangeSchema {
roles?: string[];
nick?: string;
}
@@ -0,0 +1,3 @@
export interface MemberNickChangeSchema {
nick: string;
}
@@ -0,0 +1,4 @@
export interface MessageAcknowledgeSchema {
manual?: boolean;
mention_count?: number;
}
+33
View File
@@ -0,0 +1,33 @@
import { Embed } from "@fosscord/util";
export interface MessageCreateSchema {
type?: number;
content?: string;
nonce?: string;
channel_id?: string;
tts?: boolean;
flags?: string;
embeds?: Embed[];
embed?: Embed;
// TODO: ^ embed is deprecated in favor of embeds (https://discord.com/developers/docs/resources/channel#message-object)
allowed_mentions?: {
parse?: string[];
roles?: string[];
users?: string[];
replied_user?: boolean;
};
message_reference?: {
message_id: string;
channel_id: string;
guild_id?: string;
fail_if_not_exists?: boolean;
};
payload_json?: string;
file?: any;
/**
TODO: we should create an interface for attachments
TODO: OpenWAAO<-->attachment-style metadata conversion
**/
attachments?: any[];
sticker_ids?: string[];
}
+4
View File
@@ -0,0 +1,4 @@
export interface MfaCodesSchema {
password: string;
regenerate?: boolean;
}
@@ -0,0 +1,15 @@
export interface ModifyGuildStickerSchema {
/**
* @minLength 2
* @maxLength 30
*/
name: string;
/**
* @maxLength 100
*/
description?: string;
/**
* @maxLength 200
*/
tags: string;
}
+6
View File
@@ -0,0 +1,6 @@
export interface PruneSchema {
/**
* @min 0
*/
days: number;
}
+4
View File
@@ -0,0 +1,4 @@
export interface PurgeSchema {
before: string;
after: string;
}
+27
View File
@@ -0,0 +1,27 @@
export interface RegisterSchema {
/**
* @minLength 2
* @maxLength 32
*/
username: string;
/**
* @minLength 1
* @maxLength 72
*/
password?: string;
consent: boolean;
/**
* @TJS-format email
*/
email?: string;
fingerprint?: string;
invite?: string;
/**
* @TJS-type string
*/
date_of_birth?: Date; // "2000-04-03"
gift_code_sku_id?: string;
captcha_key?: string;
promotional_email_opt_in?: boolean;
}
@@ -0,0 +1,4 @@
export interface RelationshipPostSchema {
discriminator: string;
username: string;
}
@@ -0,0 +1,5 @@
import { RelationshipType } from "@fosscord/util";
export interface RelationshipPutSchema {
type?: RelationshipType;
}
+10
View File
@@ -0,0 +1,10 @@
export interface RoleModifySchema {
name?: string;
permissions?: string;
color?: number;
hoist?: boolean; // whether the role should be displayed separately in the sidebar
mentionable?: boolean; // whether the role should be mentionable
position?: number;
icon?: string;
unicode_emoji?: string;
}
+19
View File
@@ -0,0 +1,19 @@
export interface SelectProtocolSchema {
protocol: "webrtc" | "udp";
data:
| string
| {
address: string;
port: number;
mode: string;
};
sdp?: string;
codecs?: {
name: "opus" | "VP8" | "VP9" | "H264";
type: "audio" | "video";
priority: number;
payload_type: number;
rtx_payload_type?: number | null;
}[];
rtc_connection_id?: string; // uuid
}
+4
View File
@@ -0,0 +1,4 @@
export interface TemplateCreateSchema {
name: string;
description?: string;
}
+4
View File
@@ -0,0 +1,4 @@
export interface TemplateModifySchema {
name: string;
description?: string;
}
+3
View File
@@ -0,0 +1,3 @@
export interface TotpDisableSchema {
code: string;
}
+5
View File
@@ -0,0 +1,5 @@
export interface TotpEnableSchema {
password: string;
code?: string;
secret?: string;
}
+6
View File
@@ -0,0 +1,6 @@
export interface TotpSchema {
code: string,
ticket: string,
gift_code_sku_id?: string | null,
login_source?: string | null,
}
+19
View File
@@ -0,0 +1,19 @@
export interface UserModifySchema {
/**
* @minLength 1
* @maxLength 100
*/
username?: string;
avatar?: string | null;
/**
* @maxLength 1024
*/
bio?: string;
accent_color?: number;
banner?: string | null;
password?: string;
new_password?: string;
code?: string;
email?: string;
discriminator?: string;
}
+7
View File
@@ -0,0 +1,7 @@
export interface VanityUrlSchema {
/**
* @minLength 1
* @maxLength 20
*/
code?: string;
}
+12
View File
@@ -0,0 +1,12 @@
export interface VoiceIdentifySchema {
server_id: string;
user_id: string;
session_id: string;
token: string;
video?: boolean;
streams?: {
type: string;
rid: string;
quality: number;
}[];
}
@@ -0,0 +1,22 @@
//TODO need more testing when community guild and voice stage channel are working
export interface VoiceStateUpdateSchema {
guild_id?: string;
channel_id?: string;
self_mute: boolean;
self_deaf: boolean;
self_video?: boolean;
preferred_region?: string;
request_to_speak_timestamp?: Date;
suppress?: boolean;
}
export const VoiceStateUpdateSchema = {
$guild_id: String,
$channel_id: String,
self_mute: Boolean,
self_deaf: Boolean,
$self_video: Boolean, //required in docs but bots don't always send it
$preferred_region: String,
$request_to_speak_timestamp: Date,
$suppress: Boolean,
};
+17
View File
@@ -0,0 +1,17 @@
export interface VoiceVideoSchema {
audio_ssrc: number;
video_ssrc: number;
rtx_ssrc?: number;
user_id?: string;
streams?: {
type: "video" | "audio";
rid: string;
ssrc: number;
active: boolean;
quality: number;
rtx_ssrc: number;
max_bitrate: number;
max_framerate: number;
max_resolution: { type: string; width: number; height: number; };
}[];
}
+8
View File
@@ -0,0 +1,8 @@
// TODO: webhooks
export interface WebhookCreateSchema {
/**
* @maxLength 80
*/
name: string;
avatar: string;
}
+4
View File
@@ -0,0 +1,4 @@
export interface WidgetModifySchema {
enabled: boolean; // whether the widget is enabled
channel_id: string; // the widget channel id
}
+40 -1
View File
@@ -1,2 +1,41 @@
export * from "./Validator";
export * from "./voice";
export * from "./SelectProtocolSchema";
export * from "./LoginSchema";
export * from "./RegisterSchema";
export * from "./TotpSchema";
export * from "./BackupCodesChallengeSchema";
export * from "./ChannelModifySchema";
export * from "./InviteCreateSchema";
export * from "./PurgeSchema";
export * from "./WebhookCreateSchema";
export * from "./MessageCreateSchema";
export * from "./MessageAcknowledgeSchema";
export * from "./GuildCreateSchema";
export * from "./BanCreateSchema";
export * from "./BanModeratorSchema";
export * from "./BanRegistrySchema";
export * from "./EmojiCreateSchema";
export * from "./EmojiModifySchema";
export * from "./ModifyGuildStickerSchema";
export * from "./TemplateCreateSchema";
export * from "./TemplateModifySchema";
export * from "./VanityUrlSchema";
export * from "./GuildUpdateWelcomeScreenSchema";
export * from "./WidgetModifySchema";
export * from "./MemberChangeSchema";
export * from "./RoleModifySchema";
export * from "./GuildTemplateCreateSchema";
export * from "./DmChannelCreateSchema";
export * from "./UserModifySchema";
export * from "./RelationshipPostSchema";
export * from "./RelationshipPutSchema";
export * from "./CodesVerificationSchema";
export * from "./MfaCodesSchema";
export * from "./TotpDisableSchema";
export * from "./TotpEnableSchema";
export * from "./VoiceIdentifySchema";
export * from "./VoiceStateUpdateSchema";
export * from "./VoiceVideoSchema";
export * from "./IdentifySchema";
export * from "./ActivitySchema";
export * from "./LazyRequestSchema";
-69
View File
@@ -1,69 +0,0 @@
export interface VoiceVideoSchema {
audio_ssrc: number;
video_ssrc: number;
rtx_ssrc?: number;
user_id?: string;
streams?: {
type: "video" | "audio";
rid: string;
ssrc: number;
active: boolean;
quality: number;
rtx_ssrc: number;
max_bitrate: number;
max_framerate: number;
max_resolution: { type: string; width: number; height: number; };
}[];
}
export const VoiceStateUpdateSchema = {
$guild_id: String,
$channel_id: String,
self_mute: Boolean,
self_deaf: Boolean,
self_video: Boolean
};
//TODO need more testing when community guild and voice stage channel are working
export interface VoiceStateUpdateSchema {
channel_id: string;
guild_id?: string;
suppress?: boolean;
request_to_speak_timestamp?: Date;
self_mute?: boolean;
self_deaf?: boolean;
self_video?: boolean;
}
export interface VoiceIdentifySchema {
server_id: string;
user_id: string;
session_id: string;
token: string;
video?: boolean;
streams?: {
type: string;
rid: string;
quality: number;
}[];
}
export interface SelectProtocolSchema {
protocol: "webrtc" | "udp";
data:
| string
| {
address: string;
port: number;
mode: string;
};
sdp?: string;
codecs?: {
name: "opus" | "VP8" | "VP9" | "H264";
type: "audio" | "video";
priority: number;
payload_type: number;
rtx_payload_type?: number | null;
}[];
rtc_connection_id?: string; // uuid
}