Skip to content

Commit

Permalink
Reorganize lilybird types (#20)
Browse files Browse the repository at this point in the history

Co-authored-by: Jozef Steinhübl <[email protected]>
  • Loading branch information
Didas-git and xhyrom authored May 8, 2024
1 parent 5edd3b6 commit 2640439
Show file tree
Hide file tree
Showing 103 changed files with 2,946 additions and 2,358 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cSpell.words": [
"astro",
"astrojs",
"bitfield",
"CDNURL",
"crosspost",
"CROSSPOSTED",
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 4 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export default tsEslint.config({
"@typescript-eslint/no-meaningless-void-operator": "warn",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-mixed-enums": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-non-null-assertion": "error",
Expand All @@ -203,7 +202,6 @@ export default tsEslint.config({
"@typescript-eslint/no-unsafe-member-access": "error",
"@typescript-eslint/no-unsafe-return": "error",
"@typescript-eslint/no-unsafe-unary-minus": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-useless-empty-export": "warn",
"@typescript-eslint/no-var-requires": "error",
Expand All @@ -229,6 +227,10 @@ export default tsEslint.config({
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/unified-signatures": "error",
"@typescript-eslint/no-namespace": [
"error",
{ allowDeclarations: true }
],
"@typescript-eslint/array-type": [
"warn",
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lilybird",
"version": "0.6.1",
"version": "0.7.0",
"description": "A bun-first discord client written in TS",
"main": "./dist/index.js",
"author": "DidaS",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/cache/manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import { CacheElementType } from "../enums/cache.js";
import type { CacheManagerStructure, ChannelStructure, GuildStructure, VoiceStateStructure } from "../typings/index.js";
import type { CacheManagerStructure, Channel, Guild, Voice } from "../typings/index.js";

export class CachingManager<G = GuildStructure, C = ChannelStructure, V = VoiceStateStructure> implements CacheManagerStructure {
export class CachingManager<G = Guild.Structure, C = Channel.Structure, V = Voice.StateStructure> implements CacheManagerStructure {
public readonly guilds = new Map<string, G>();
public readonly channels = new Map<string, C>();
public readonly voiceStates = new Map<string, V>();
Expand Down
13 changes: 7 additions & 6 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import type { DispatchFunction } from "#ws";
import type {
UpdatePresenceStructure,
CacheManagerStructure,
ApplicationStructure,
ParseCachingManager,
BaseClientOptions,
SelectiveCache,
ClientOptions,
DebugFunction,
Transformers,
Application,
Transformer
} from "./typings/index.js";

Expand All @@ -34,7 +34,7 @@ type GetUserType<T extends Transformers> = (T["userUpdate"] & {}) extends { hand
export interface Client<T extends Transformers> {
readonly user: GetUserType<T>;
readonly sessionId: string;
readonly application: ApplicationStructure;
readonly application: Application.Structure;
}

/*
Expand Down Expand Up @@ -176,12 +176,13 @@ export class Client<T extends Transformers = Transformers, C extends CacheManage
//#endregion
//#region User defined listeners
for (let i = 0, listenerEntries = Object.entries(listeners), { length } = listenerEntries; i < length; i++) {
const [name, handler] = listenerEntries[i] as [string, () => unknown];
if (name === "raw" || name === "ready") continue;
const [handlerName, handler] = listenerEntries[i] as [string, () => unknown];
if (handlerName === "raw" || handlerName === "ready") continue;
if (typeof handler === "undefined") continue;

const event = name.replace(/[A-Z]/, "_$&").toUpperCase() as GatewayEvent;
const transformer = transformers[name];
const name = `${handlerName[0].toUpperCase()}${handlerName.slice(1)}`;
const event: GatewayEvent = GatewayEvent[<never>name];
const transformer = transformers[handlerName];

this.#createListener(
builder,
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/enums/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ export const enum ApplicationRoleConnectionMetadataType {
BOOLEAN_EQUAL,
BOOLEAN_NOT_EQUAL
}

export const enum ApplicationIntegrationType {
GUILD_INSTALL,
USER_INSTALL
}
2 changes: 1 addition & 1 deletion packages/core/src/enums/auto-moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const enum AutoModerationTriggerType {
MENTION_SPAM
}

export const enum AutoModerationKeywordPresetTypes {
export const enum AutoModerationKeywordPresetType {
PROFANITY = 1,
SEXUAL_CONTENT,
SLURS
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/enums/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ export const enum DebugIdentifier {
AttemptingResume = "ATTEMPTING_RESUME",
UnknownCode = "UNKNOWN_CODE",
CompiledListeners = "LISTENERS",
RESTCall = "REST"
RESTCall = "REST_IN",
RESTError = "REST_ERROR"
}
10 changes: 7 additions & 3 deletions packages/core/src/enums/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const enum GatewayEvent {
export enum GatewayEvent {
Ready = "READY",
Resumed = "RESUMED",
ApplicationCommandPermissionsUpdate = "APPLICATION_COMMAND_PERMISSIONS_UPDATE",
Expand Down Expand Up @@ -59,7 +59,9 @@ export const enum GatewayEvent {
UserUpdate = "USER_UPDATE",
VoiceStateUpdate = "VOICE_STATE_UPDATE",
VoiceServerUpdate = "VOICE_SERVER_UPDATE",
WebhookUpdate = "WEBHOOK_UPDATE"
WebhookUpdate = "WEBHOOK_UPDATE",
MessagePollVoteAdd = "MESSAGE_POLL_VOTE_ADD",
MessagePollVoteRemove = "MESSAGE_POLL_VOTE_REMOVE"
}

export const enum GatewayOpCode {
Expand Down Expand Up @@ -95,7 +97,9 @@ export const enum Intents {
MESSAGE_CONTENT = 32768,
GUILD_SCHEDULED_EVENTS = 65536,
AUTO_MODERATION_CONFIGURATION = 1048576,
AUTO_MODERATION_EXECUTION = 2097152
AUTO_MODERATION_EXECUTION = 2097152,
GUILD_MESSAGE_POLLS = 16777216,
DIRECT_MESSAGE_POLLS = 33554432
}

export const enum GatewayCloseEventCode {
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/enums/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,20 @@ export const enum GuildNSFWLevel {
AGE_RESTRICTED
}

export const enum GuildMemberFlags {
export const enum GuildMemberFlag {
DID_REJOIN = 1,
COMPLETED_ONBOARDING,
BYPASSES_VERIFICATION = 4,
STARTED_ONBOARDING = 8
}

export const enum IntegrationType {
Twitch = "twitch",
Youtube = "youtube",
Discord = "discord",
GuildSubscription = "guild_subscription"
}

export const enum IntegrationExpireBehavior {
RemoveRole,
Role
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export * from "./guild.js";
export * from "./image.js";
export * from "./cache.js";
export * from "./user.js";
export * from "./team.js";
export * from "./poll.js";
5 changes: 2 additions & 3 deletions packages/core/src/enums/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const PermissionFlags = {
CREATE_GUILD_EXPRESSIONS: 8796093022208n,
CREATE_EVENTS: 17592186044416n,
USE_EXTERNAL_SOUNDS: 35184372088832n,
SEND_VOICE_MESSAGES: 70368744177664n
SEND_VOICE_MESSAGES: 70368744177664n,
SEND_POLLS: 562949953421312n
} as const;

export type PermissionFlag = (typeof PermissionFlags)[keyof typeof PermissionFlags];
6 changes: 6 additions & 0 deletions packages/core/src/enums/poll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @see {@link https://discord.com/developers/docs/resources/poll#layout-type}
*/
export const enum PollLayoutType {
DEFAULT = 1
}
5 changes: 5 additions & 0 deletions packages/core/src/enums/team.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const enum TeamMemberRole {
Admin = "admin",
Developer = "developer",
ReadOnly = "read_only"
}
Loading

0 comments on commit 2640439

Please sign in to comment.