Skip to content

Commit

Permalink
🚸 feat: idk there're so many changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Helloyunho committed Sep 5, 2023
1 parent 0c101fd commit aa1de8d
Show file tree
Hide file tree
Showing 21 changed files with 205 additions and 81 deletions.
1 change: 1 addition & 0 deletions framework/src/client/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import type { Message } from "../structures/mod.ts";
// ...this is gonna be very painful to fix
export type ClientEvents = {
messageCreate: [Message];
ready: [];
};
2 changes: 2 additions & 0 deletions framework/src/client/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GuildsManager } from "../managers/guilds.ts";
import { UsersManager } from "../managers/users.ts";
import { RolesManager } from "../managers/roles.ts";
import { EmojisManager } from "../managers/emojis.ts";
import { User } from "../structures/mod.ts";

export interface ClientOptions extends APIManagerOptions {
intents?: number;
Expand All @@ -20,6 +21,7 @@ export class Client extends EventEmitter<ClientEvents> {
gateway: ShardedGateway;
rest: RESTClient;
token: string;
user?: User; // it's empty until the ready event is fired
channels = new ChannelsManager(this);
guilds = new GuildsManager(this);
users = new UsersManager(this);
Expand Down
2 changes: 2 additions & 0 deletions framework/src/gateway/mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { GatewayHandler } from "../../types/gateway.ts";
import messageCreate from "./messageCreate.ts";
import ready from "./ready.ts";

// deno-lint-ignore no-explicit-any
export const GatewayHandlers: { [K: string]: GatewayHandler<any> } = {
MESSAGE_CREATE: messageCreate,
READY: ready,
};
21 changes: 21 additions & 0 deletions framework/src/gateway/ready.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { GatewayReadyPayload } from "../../../types/mod.ts";
import { GatewayHandler } from "../../types/gateway.ts";
import type { Client } from "../client/mod.ts";
import { User } from "../structures/mod.ts";

const ready: GatewayHandler<"READY"> = (
client: Client,
d: [number, GatewayReadyPayload],
) => {
const user = new User(client, d[1].user);
client.user = user;
client.users.set(user.id, d[1].user);

d[1].guilds.forEach((g) => {
client.guilds.set(g.id, g);
});

client.emit("ready");
};

export default ready;
10 changes: 8 additions & 2 deletions framework/src/structures/channels/DMBasedChannel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import type { DMBasedChannelPayload } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";
import { User } from "../users/mod.ts";
import { TextChannel } from "./textChannel.ts";

export class DMBasedChannel<P extends DMBasedChannelPayload>
extends TextChannel<P> {
export class DMBasedChannel extends TextChannel {
payload: DMBasedChannelPayload;
constructor(client: Client, payload: DMBasedChannelPayload) {
super(client, payload);
this.payload = payload;
}

get recipients(): User[] {
return this.payload.recipients.map((r) => new User(this.client, r));
}
Expand Down
9 changes: 8 additions & 1 deletion framework/src/structures/channels/DMChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import type { DMChannelPayload } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";
import { DMBasedChannel } from "./DMBasedChannel.ts";

export class DMChannel extends DMBasedChannel<DMChannelPayload> {
export class DMChannel extends DMBasedChannel {
payload: DMChannelPayload;
constructor(client: Client, payload: DMChannelPayload) {
super(client, payload);
this.payload = payload;
}

get recipient() {
return this.payload.recipients[0];
}
Expand Down
6 changes: 3 additions & 3 deletions framework/src/structures/channels/channel.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { ChannelPayload, ChannelType } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";

export class Channel<P extends ChannelPayload> {
export class Channel {
client: Client;
payload: P;
payload: ChannelPayload;

constructor(client: Client, payload: P) {
constructor(client: Client, payload: ChannelPayload) {
this.client = client;
this.payload = payload;
}
Expand Down
9 changes: 8 additions & 1 deletion framework/src/structures/channels/groupDMChannel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import type { GroupDMChannelPayload } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";
import { User } from "../users/mod.ts";
import { DMBasedChannel } from "./DMBasedChannel.ts";

export class GroupDMChannel extends DMBasedChannel<GroupDMChannelPayload> {
export class GroupDMChannel extends DMBasedChannel {
payload: GroupDMChannelPayload;
constructor(client: Client, payload: GroupDMChannelPayload) {
super(client, payload);
this.payload = payload;
}

get name(): string {
return this.payload.name;
}
Expand Down
13 changes: 11 additions & 2 deletions framework/src/structures/channels/guildAnnouncementChannel.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import type { GuildAnnouncementChannelPayload } from "../../../../types/mod.ts";
import { Mixin } from "../../../deps.ts";
import type { Client } from "../../client/mod.ts";
import { GuildTextBasedChannel } from "./guildTextBasedChannel.ts";
import { GuildThreadAvailableChannel } from "./guildThreadAvailableChannel.ts";

export class GuildAnnouncementChannel extends Mixin(
GuildTextBasedChannel<GuildAnnouncementChannelPayload>,
GuildThreadAvailableChannel<GuildAnnouncementChannelPayload>,
GuildTextBasedChannel,
GuildThreadAvailableChannel,
) {
payload: GuildAnnouncementChannelPayload;
constructor(
client: Client,
payload: GuildAnnouncementChannelPayload,
) {
super(client, payload);
this.payload = payload;
}
}
9 changes: 8 additions & 1 deletion framework/src/structures/channels/guildCategory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import type { GuildCategoryPayload } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";
import { GuildChannel } from "./guildChannel.ts";

export class GuildCategory extends GuildChannel<GuildCategoryPayload> {}
export class GuildCategory extends GuildChannel {
payload: GuildCategoryPayload;
constructor(client: Client, payload: GuildCategoryPayload) {
super(client, payload);
this.payload = payload;
}
}
9 changes: 8 additions & 1 deletion framework/src/structures/channels/guildChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Channel } from "./channel.ts";
import type { GuildChannelPayload } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";

export class GuildChannel extends Channel {
payload: GuildChannelPayload;
constructor(client: Client, payload: GuildChannelPayload) {
super(client, payload);
this.payload = payload;
}

export class GuildChannel<P extends GuildChannelPayload> extends Channel<P> {
get guildID(): string {
return this.payload.guild_id;
}
Expand Down
49 changes: 29 additions & 20 deletions framework/src/structures/channels/guildForumChannel.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import type { GuildForumChannelPayload } from "../../../../types/mod.ts";
import { Mixin } from "../../../deps.ts";
import type { GuildForumTag } from "../../../types/forum.ts";
import type { Client } from "../../client/mod.ts";
import { Emoji } from "../emojis/mod.ts";
import { GuildTextBasedChannel } from "./guildTextBasedChannel.ts";
import { GuildThreadAvailableChannel } from "./guildThreadAvailableChannel.ts";

export class GuildForumChannel extends Mixin(
GuildThreadAvailableChannel<GuildForumChannelPayload>,
GuildTextBasedChannel<GuildForumChannelPayload>,
GuildThreadAvailableChannel,
GuildTextBasedChannel,
) {
payload: GuildForumChannelPayload;
constructor(client: Client, payload: GuildForumChannelPayload) {
super(client, payload);
this.payload = payload;
}

get defaultReactionEmoji(): Emoji | undefined {
if (this.payload.default_reaction_emoji) {
if (this.payload.default_reaction_emoji.emoji_id !== null) {
Expand All @@ -30,25 +37,27 @@ export class GuildForumChannel extends Mixin(
get defaultForumLayout() {
return this.payload.default_auto_archive_duration;
}
get availableTags(): GuildForumTag {
let result: Emoji;
get availableTags(): GuildForumTag[] {
return this.payload.available_tags.map((t) => {
let result: Emoji;

if (this.payload.available_tags.emoji_id !== null) {
result = this.client.emojis.get(
this.payload.available_tags.emoji_id,
)!;
} else if (this.payload.available_tags.emoji_name !== null) {
result = new Emoji(this.client, {
id: null,
name: this.payload.available_tags.emoji_name,
});
}
if (t.emoji_id !== null) {
result = this.client.emojis.get(
t.emoji_id,
)!;
} else if (t.emoji_name !== null) {
result = new Emoji(this.client, {
id: null,
name: t.emoji_name,
});
}

return {
id: this.payload.available_tags.id,
name: this.payload.available_tags.name,
moderated: this.payload.available_tags.moderated,
emoji: result!,
};
return {
id: t.id,
name: t.name,
moderated: t.moderated,
emoji: result!,
};
});
}
}
10 changes: 8 additions & 2 deletions framework/src/structures/channels/guildStageChannel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { GuildStageChannelPayload } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";
import { GuildVoiceBasedChannel } from "./guildVoiceBasedChannel.ts";

export class GuildStageChannel
extends GuildVoiceBasedChannel<GuildStageChannelPayload> {}
export class GuildStageChannel extends GuildVoiceBasedChannel {
payload: GuildStageChannelPayload;
constructor(client: Client, payload: GuildStageChannelPayload) {
super(client, payload);
this.payload = payload;
}
}
13 changes: 7 additions & 6 deletions framework/src/structures/channels/guildTextBasedChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { GuildChannel } from "./guildChannel.ts";
import type { GuildTextBasedChannelPayload } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";

export class GuildTextBasedChannel<P extends GuildTextBasedChannelPayload>
extends Mixin(
GuildChannel,
TextChannel,
) {
constructor(client: Client, payload: P) {
export class GuildTextBasedChannel extends Mixin(
GuildChannel,
TextChannel,
) {
payload: GuildTextBasedChannelPayload;
constructor(client: Client, payload: GuildTextBasedChannelPayload) {
super(client, payload);
this.payload = payload;
}

get rateLimitPerUser(): number {
Expand Down
10 changes: 8 additions & 2 deletions framework/src/structures/channels/guildTextChannel.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { GuildTextChannelPayload } from "../../../../types/mod.ts";
import { Mixin } from "../../../deps.ts";
import type { Client } from "../../client/mod.ts";
import { GuildTextBasedChannel } from "./guildTextBasedChannel.ts";
import { GuildThreadAvailableChannel } from "./guildThreadAvailableChannel.ts";

export class GuildTextChannel extends Mixin(
GuildTextBasedChannel<GuildTextChannelPayload>,
GuildThreadAvailableChannel<GuildTextChannelPayload>,
GuildTextBasedChannel,
GuildThreadAvailableChannel,
) {
payload: GuildTextChannelPayload;
constructor(client: Client, payload: GuildTextChannelPayload) {
super(client, payload);
this.payload = payload;
}
}
11 changes: 8 additions & 3 deletions framework/src/structures/channels/guildThreadAvailableChannel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type { GuildThreadAvailableChannelPayload } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";
import { GuildChannel } from "./guildChannel.ts";

export class GuildThreadAvailableChannel<
P extends GuildThreadAvailableChannelPayload,
> extends GuildChannel<P> {
export class GuildThreadAvailableChannel extends GuildChannel {
payload: GuildThreadAvailableChannelPayload;
constructor(client: Client, payload: GuildThreadAvailableChannelPayload) {
super(client, payload);
this.payload = payload;
}

get defaultAutoArchiveDuration() {
return this.payload.default_auto_archive_duration;
}
Expand Down
9 changes: 7 additions & 2 deletions framework/src/structures/channels/guildVoiceBasedChannel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { GuildVoiceBasedChannelPayload } from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";
import { GuildChannel } from "./guildChannel.ts";

export class GuildVoiceBasedChannel<P extends GuildVoiceBasedChannelPayload>
extends GuildChannel<P> {
export class GuildVoiceBasedChannel extends GuildChannel {
payload: GuildVoiceBasedChannelPayload;
constructor(client: Client, payload: GuildVoiceBasedChannelPayload) {
super(client, payload);
this.payload = payload;
}
get bitrate() {
return this.payload.bitrate;
}
Expand Down
11 changes: 9 additions & 2 deletions framework/src/structures/channels/guildVoiceChannel.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type { GuildVoiceChannelPayload } from "../../../../types/mod.ts";
import { Mixin } from "../../../deps.ts";
import type { Client } from "../../client/mod.ts";
import { GuildTextBasedChannel } from "./guildTextBasedChannel.ts";
import { GuildVoiceBasedChannel } from "./guildVoiceBasedChannel.ts";

export class GuildVoiceChannel extends Mixin(
GuildTextBasedChannel<GuildVoiceChannelPayload>,
GuildVoiceBasedChannel<GuildVoiceChannelPayload>,
GuildTextBasedChannel,
GuildVoiceBasedChannel,
) {
payload: GuildVoiceChannelPayload;
constructor(client: Client, payload: GuildVoiceChannelPayload) {
super(client, payload);
this.payload = payload;
}

get videoQualityMode() {
return this.payload.video_quality_mode;
}
Expand Down
9 changes: 8 additions & 1 deletion framework/src/structures/channels/textChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ import type {
MessagePayload,
TextChannelPayload,
} from "../../../../types/mod.ts";
import type { Client } from "../../client/mod.ts";
import { Message } from "../messages/mod.ts";
import { Channel } from "./channel.ts";

export class TextChannel<P extends TextChannelPayload> extends Channel<P> {
export class TextChannel extends Channel {
payload: TextChannelPayload;
constructor(client: Client, payload: TextChannelPayload) {
super(client, payload);
this.payload = payload;
}

get lastPinTimestamp(): string | null {
return this.payload.last_pin_timestamp;
}
Expand Down
Loading

0 comments on commit aa1de8d

Please sign in to comment.