Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
add models
Browse files Browse the repository at this point in the history
Signed-off-by: Ruairi <[email protected]>
  • Loading branch information
splatterxl committed Jun 20, 2023
1 parent 3dd4e2c commit d920e9d
Show file tree
Hide file tree
Showing 99 changed files with 3,389 additions and 589 deletions.
546 changes: 546 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ plugins:
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.2.0.cjs
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"packages/*"
],
"devDependencies": {
"@changesets/cli": "^2.22.0"
"@changesets/cli": "^2.26.1"
}
}
24 changes: 12 additions & 12 deletions packages/fuwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@
"dependencies": {
"@fuwa/rest": "workspace:^",
"@fuwa/ws": "workspace:^",
"@sapphire/async-queue": "1.3.1",
"@types/ws": "8.5.3",
"discord-api-types": "0.32.0",
"@sapphire/async-queue": "1.5.0",
"@types/ws": "8.5.5",
"discord-api-types": "0.37.46",
"lodash.snakecase": "4.1.1",
"ws": "8.6.0"
"ws": "8.13.0"
},
"devDependencies": {
"@splatterxl/tsconfig": "1.1.1",
"@types/node": "17.0.33",
"@typescript-eslint/eslint-plugin": "5.22.0",
"@typescript-eslint/parser": "5.23.0",
"@types/node": "20.3.1",
"@typescript-eslint/eslint-plugin": "5.60.0",
"@typescript-eslint/parser": "5.60.0",
"cz-conventional-changelog": "3.3.0",
"eslint": "8.15.0",
"prettier": "2.6",
"standard-version": "9.3.2",
"typedoc": "0.22.15",
"typescript": "4.6.4"
"eslint": "8.43.0",
"prettier": "2.8.8",
"standard-version": "9.5.0",
"typedoc": "0.24.8",
"typescript": "5.1.3"
},
"config": {
"commitizen": {
Expand Down
4 changes: 2 additions & 2 deletions packages/fuwa/src/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { GatewayManager, GatewayShard } from '@fuwa/ws';
import { Snowflake } from 'discord-api-types/globals';
import EventEmitter from 'events';
import { HttpMethod } from 'undici/types/dispatcher';
import Dispatcher from 'undici/types/dispatcher';
import { workerData } from 'worker_threads';
import { DefaultLogger } from '../logging/DefaultLogger.js';
import { DisabledLogger } from '../logging/DisabledLogger.js';
Expand Down Expand Up @@ -320,7 +320,7 @@ export class Client extends EventEmitter {
return this.http
.queue<any>({
route: route.join('/'),
method: prop.toUpperCase() as HttpMethod,
method: prop.toUpperCase() as Dispatcher.HttpMethod,
...options,
})
.then((d: any) => (json ? consumeJSON(d) : d)) as any;
Expand Down
6 changes: 3 additions & 3 deletions packages/fuwa/typings/client/Client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export interface ClientEvents {
];
messageUpdate: [old: Message, new: Message];
}
export declare type APIRequestOptions<D = any> = Omit<APIRequest<D>, 'route'>;
export declare type APIProxy = {
export type APIRequestOptions<D = any> = Omit<APIRequest<D>, 'route'>;
export type APIProxy = {
[key: string]: APIProxy;
} & {
get: APIProxyExecuteRequest<true>;
Expand All @@ -82,5 +82,5 @@ export declare type APIProxy = {
patch: APIProxyExecuteRequest;
delete: APIProxyExecuteRequest<true>;
} & ((...args: any[]) => APIProxy);
declare type APIProxyExecuteRequest<O = false> = <T, D = any, Json = true>(options?: O extends true ? Omit<APIRequestOptions<D>, 'body' | 'files'> : APIRequestOptions<D>, json?: Json) => Promise<Json extends true ? T : Response<T>>;
type APIProxyExecuteRequest<O = false> = <T, D = any, Json = true>(options?: O extends true ? Omit<APIRequestOptions<D>, 'body' | 'files'> : APIRequestOptions<D>, json?: Json) => Promise<Json extends true ? T : Response<T>>;
export {};
2 changes: 1 addition & 1 deletion packages/fuwa/typings/client/ClientOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export interface ClientOptions {
compress?: boolean;
etf?: boolean;
}
export declare type ClientOptionsIntents = number | Intents | (number | Intents)[];
export type ClientOptionsIntents = number | Intents | (number | Intents)[];
export declare function resolveIntents(intents: ClientOptionsIntents): Intents;
export declare const DefaultClientOptions: ClientOptions;
2 changes: 1 addition & 1 deletion packages/fuwa/typings/logging/DefaultLogger.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ILogger } from './ILogger.js';
import { LoggerOptions, LogLevel } from './LoggerOptions.js';
declare type TLoggerOptions = Required<LoggerOptions> & {
type TLoggerOptions = Required<LoggerOptions> & {
level: LogLevel[];
};
export declare class DefaultLogger implements ILogger {
Expand Down
2 changes: 1 addition & 1 deletion packages/fuwa/typings/logging/ILogger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export interface ILogger {
trace(...data: any[]): void;
kleur(): KleurFactory;
}
export declare type KleurFactory = {
export type KleurFactory = {
[k: string]: KleurFactory;
} & (() => KleurFactory) & ((str: string) => string);
2 changes: 1 addition & 1 deletion packages/fuwa/typings/logging/LoggerOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface LoggerOptions {
colors?: boolean | KleurFactory;
level?: LogLevel | LogLevel[];
}
export declare type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'trace';
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'trace';
export declare const DefaultLoggerOptions: LoggerOptions;
export declare function DefaultKleurFactory(): any;
export declare function hasKleur(): boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/fuwa/typings/sharding/ShardingManager.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="node" />
/// <reference types="node" />
import { RESTClient } from '@fuwa/rest';
import { ChildProcess } from 'child_process';
import { APIGatewayBotInfo } from 'discord-api-types/v10';
Expand Down
2 changes: 1 addition & 1 deletion packages/fuwa/typings/structures/Channel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export declare class Channel<T extends APIChannel = APIChannel> extends BaseStru
isTextBased(): this is TextChannel;
isVoiceBased(): this is GuildVoiceChannel;
}
export declare type Channels<T = GuildChannels | Channel | DMChannel, D = APIChannel> = T & {
export type Channels<T = GuildChannels | Channel | DMChannel, D = APIChannel> = T & {
id: Snowflake;
_deserialise(data: D): T;
};
Expand Down
10 changes: 5 additions & 5 deletions packages/fuwa/typings/structures/Guild.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export declare class Guild extends BaseStructure<APIGuild | APIUnavailableGuild>
systemChannelId: Snowflake | null;
systemChannelFlags: GuildSystemChannelFlags | null;
publicUpdatesChannelId: Snowflake | null;
get afkChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | null | undefined;
get systemChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | null | undefined;
get widgetChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | null | undefined;
get rulesChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | null | undefined;
get publicUpdatesChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | null | undefined;
get afkChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | import("./GuildVoiceChannel").GuildVoiceChannel | null | undefined;
get systemChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | import("./GuildVoiceChannel").GuildVoiceChannel | null | undefined;
get widgetChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | import("./GuildVoiceChannel").GuildVoiceChannel | null | undefined;
get rulesChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | import("./GuildVoiceChannel").GuildVoiceChannel | null | undefined;
get publicUpdatesChannel(): GuildChannel<APIGuildChannel<GuildChannelType>> | import("./GuildVoiceChannel").GuildVoiceChannel | null | undefined;
channels: GuildChannelManager;
get shardId(): number;
get shard(): import("@fuwa/ws").GatewayShard | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/fuwa/typings/structures/GuildChannel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export declare class GuildChannel<T extends APIGuildChannel<GuildChannelType> =
get delete(): (reason?: string | undefined) => Promise<void>;
toJSON(): T;
}
export declare type GuildChannels = GuildChannel | GuildTextChannel | GuildVoiceChannel;
export type GuildChannels = GuildChannel | GuildTextChannel | GuildVoiceChannel;
import { GuildTextChannel } from './GuildTextChannel.js';
import { GuildVoiceChannel } from './GuildVoiceChannel.js';
2 changes: 1 addition & 1 deletion packages/fuwa/typings/structures/MessageEmbed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export declare class MessageEmbed {
static snake(data: DeepPartial<IMessageEmbed & APIEmbed>): APIEmbed;
}
export declare const EmbedType: typeof import("discord-api-types/v10").EmbedType;
export declare type EmbedType = typeof EmbedType[keyof typeof EmbedType];
export type EmbedType = typeof EmbedType[keyof typeof EmbedType];
export interface EmbedImage {
url: string;
proxyURL?: string | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export declare class GuildManager extends BaseManager<Guild> {
delete(id: Snowflake): Promise<void>;
leave(id: Snowflake): Promise<void>;
}
export declare type CreateGuildOptions = CreateEntityOptions & Omit<RESTPostAPIGuildsJSONBody, 'name'>;
export type CreateGuildOptions = CreateEntityOptions & Omit<RESTPostAPIGuildsJSONBody, 'name'>;
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ export declare class BaseTextChannelInGuild extends GuildChannel implements Base
get createMessage(): (data: string | MessagePayloadData | MessagePayload, cache?: boolean) => Promise<import("../Message").Message<TextChannel>>;
}
export declare const BaseTextChannel: new (client: Client) => BaseTextChannel;
export declare type TextChannel = DMChannel | GuildTextChannel | GuildVoiceChannel;
export type TextChannel = DMChannel | GuildTextChannel | GuildVoiceChannel;
2 changes: 1 addition & 1 deletion packages/fuwa/typings/util/resolvables/FileResolvable.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="node" />
import { File } from '@fuwa/rest';
export declare type FileResolvable = string | Buffer;
export type FileResolvable = string | Buffer;
export declare function resolveFile(file: FileResolvable): Promise<ResolvedFile>;
export interface ResolvedFile {
mimeType: string;
Expand Down
26 changes: 13 additions & 13 deletions packages/fuwa/typings/util/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ export interface CreateEntityOptions {
reason?: string;
cache?: boolean;
}
export declare type ArgumentType<T> = T extends (...args: infer A) => any ? A : never;
export declare type FirstArrayValue<T> = T extends [infer U, ...any[]] ? U : never;
export declare type Null<T, Exceptions = never> = {
export type ArgumentType<T> = T extends (...args: infer A) => any ? A : never;
export type FirstArrayValue<T> = T extends [infer U, ...any[]] ? U : never;
export type Null<T, Exceptions = never> = {
[P in keyof T]: Exceptions extends P ? T[P] : NonNullable<T[P]> | null;
};
export declare type SnakeToCamel<T extends string | symbol | number> = T extends `${infer U}_${infer V}` ? `${U}${Capitalize<SnakeToCamel<V>>}` : T;
declare type SplitChars<T extends string | symbol | number> = T extends `${infer Head}${infer Tail}` ? [Head, ...SplitChars<Tail>] : [];
declare type JoinChars<T extends ReadonlyArray<string>> = T extends [] ? '' : T extends [infer Head, ...infer Tail] ? Head extends string ? Tail extends string[] ? `${Head}${JoinChars<Tail>}` : '' : '' : '';
declare type UpperChars = SplitChars<'ABCDEFGHIJKLMNOPQRSTUVWXYZ'>[number];
declare type PrefixAndLowercaseCapital<T extends string> = T extends UpperChars ? `_${Lowercase<T>}` : T;
declare type PrefixAndLowercaseCapitals<T extends string[]> = {
export type SnakeToCamel<T extends string | symbol | number> = T extends `${infer U}_${infer V}` ? `${U}${Capitalize<SnakeToCamel<V>>}` : T;
type SplitChars<T extends string | symbol | number> = T extends `${infer Head}${infer Tail}` ? [Head, ...SplitChars<Tail>] : [];
type JoinChars<T extends ReadonlyArray<string>> = T extends [] ? '' : T extends [infer Head, ...infer Tail] ? Head extends string ? Tail extends string[] ? `${Head}${JoinChars<Tail>}` : '' : '' : '';
type UpperChars = SplitChars<'ABCDEFGHIJKLMNOPQRSTUVWXYZ'>[number];
type PrefixAndLowercaseCapital<T extends string> = T extends UpperChars ? `_${Lowercase<T>}` : T;
type PrefixAndLowercaseCapitals<T extends string[]> = {
[Index in keyof T]: T[Index] extends string ? PrefixAndLowercaseCapital<T[Index]> : T[Index];
};
export declare type CamelToSnake<T extends string | symbol | number> = JoinChars<PrefixAndLowercaseCapitals<SplitChars<T>>>;
export declare type CamelCase<T> = T extends Record<string, any> ? {
export type CamelToSnake<T extends string | symbol | number> = JoinChars<PrefixAndLowercaseCapitals<SplitChars<T>>>;
export type CamelCase<T> = T extends Record<string, any> ? {
[P in SnakeToCamel<keyof T>]: CamelCase<T[CamelToSnake<P>]>;
} : T;
export declare type SnakeCase<T> = T extends Record<string, any> ? {
export type SnakeCase<T> = T extends Record<string, any> ? {
[P in CamelToSnake<keyof T>]: SnakeCase<T[SnakeToCamel<P>]>;
} : T;
export declare type DeepPartial<T> = T extends object ? {
export type DeepPartial<T> = T extends object ? {
[P in keyof T]?: DeepPartial<T[P]>;
} : T;
export declare function omit(obj: any, keys: string[]): any;
Expand Down
1 change: 1 addition & 0 deletions packages/model/__test__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ws from '../../ws';
2 changes: 1 addition & 1 deletion packages/model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
},
"homepage": "https://github.com/fuwa-org/fuwa#readme",
"dependencies": {
"discord-api-types": "^0.32.1"
"discord-api-types": "^0.37.46"
}
}
4 changes: 4 additions & 0 deletions packages/model/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const Constants = {
ApplicationInstallUrl: (query: string) =>
`https://discord.com/api/oauth2/authorize?${query}`,
};
13 changes: 13 additions & 0 deletions packages/model/src/structures/BaseStructure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export abstract class BaseStructure<T> {
constructor(public _data?: T) {
Object.defineProperty(this, '_data', {
enumerable: false,
});
}
abstract toJSON(): T;

public static toJSON(data: any): any {
if (data.toJSON && typeof data.toJSON === 'function') return data.toJSON();
else return {};
}
}
54 changes: 54 additions & 0 deletions packages/model/src/structures/Role.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { APIRole, Snowflake } from 'discord-api-types/v10';
import { BaseStructure } from './BaseStructure';

export class Role extends BaseStructure<APIRole> {
id: Snowflake;
name: string;
color: number;
hoist: boolean;
icon: string | null;

unicodeEmoji: string | null;

position: number;
permissions: string;
managed: boolean;
mentionable: boolean;

// TODO: role tags
tags = null;

constructor(data: APIRole) {
super(data);

this.id = data.id;
this.name = data.name;
this.color = data.color;
this.hoist = data.hoist;
this.icon = data.icon ?? null;

this.unicodeEmoji = data.unicode_emoji ?? null;
this.position = data.position;
this.permissions = data.permissions;
this.managed = data.managed;
this.mentionable = data.mentionable;

// TODO
// this.tags = data.tags;
}

toJSON(): APIRole {
return {
id: this.id,
name: this.name,
color: this.color,
hoist: this.hoist,
icon: this.icon,
unicode_emoji: this.unicodeEmoji,
position: this.position,
permissions: this.permissions,
managed: this.managed,
mentionable: this.mentionable,
};
}
}
6 changes: 6 additions & 0 deletions packages/model/src/structures/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { APIUser } from 'discord-api-types/v10';
import { BaseStructure } from './BaseStructure';

export class User extends BaseStructure<APIUser> {
constructor(data: APIUser) {}
}
Loading

0 comments on commit d920e9d

Please sign in to comment.