From 2e95520b33f740bf03404177c38126b7f3017780 Mon Sep 17 00:00:00 2001 From: ITOH Date: Mon, 10 May 2021 17:14:32 +0200 Subject: [PATCH 1/5] fix: loopObject should not convert blobs --- src/util/loop_object.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util/loop_object.ts b/src/util/loop_object.ts index d31422f6e..c8c5e99c9 100644 --- a/src/util/loop_object.ts +++ b/src/util/loop_object.ts @@ -3,7 +3,7 @@ import { eventHandlers } from "../bot.ts"; export function loopObject>( obj: Record, handler: (value: unknown, key: string) => unknown, - log: string, + log: string ) { let res: Record | unknown[] = {}; @@ -11,9 +11,7 @@ export function loopObject>( res = []; for (const o of obj) { - if ( - typeof o === "object" && !Array.isArray(o) && o !== null - ) { + if (typeof o === "object" && !Array.isArray(o) && o !== null) { // A nested object res.push(loopObject(o as Record, handler, log)); } else { @@ -25,7 +23,10 @@ export function loopObject>( eventHandlers.debug?.("loop", log); if ( - typeof value === "object" && !Array.isArray(value) && value !== null + typeof value === "object" && + !Array.isArray(value) && + value !== null && + !(value instanceof Blob) ) { // A nested object res[key] = loopObject(value as Record, handler, log); From 5be9f4da7af2c992eaf4be82ffb67f1a6338bcbf Mon Sep 17 00:00:00 2001 From: ITOH Date: Mon, 10 May 2021 18:32:01 +0200 Subject: [PATCH 2/5] fix: channel guildId being undefined --- src/structures/channel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index d9e81b357..709971fe8 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -115,7 +115,7 @@ export async function createDiscordenoChannel( `Running forEach loop in createDiscordenoChannel function.`, ); - if (key === "guildId") value = guildId || data.guildId || ""; + if (key === "guildId") value = guildId?.toString() || data.guildId || ""; props[key] = createNewProp( CHANNEL_SNOWFLAKES.includes(key) From 5e501f9cd7781015dd0baaf7c7ebe83cd4414f03 Mon Sep 17 00:00:00 2001 From: itohatweb Date: Mon, 10 May 2021 16:32:24 +0000 Subject: [PATCH 3/5] Commit from GitHub Actions (Lint) --- src/util/loop_object.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/loop_object.ts b/src/util/loop_object.ts index c8c5e99c9..746f0a728 100644 --- a/src/util/loop_object.ts +++ b/src/util/loop_object.ts @@ -3,7 +3,7 @@ import { eventHandlers } from "../bot.ts"; export function loopObject>( obj: Record, handler: (value: unknown, key: string) => unknown, - log: string + log: string, ) { let res: Record | unknown[] = {}; From a80ddfcd922fb79deb5fe5e150c9bae2e7300996 Mon Sep 17 00:00:00 2001 From: ITOH Date: Mon, 10 May 2021 20:18:43 +0200 Subject: [PATCH 4/5] Update channel.ts --- src/structures/channel.ts | 73 +++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 41 deletions(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index 709971fe8..df87da91e 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -45,7 +45,7 @@ const baseChannel: Partial = { }, get voiceStates() { return this.guild?.voiceStates.filter( - (voiceState) => voiceState.channelId === this.id!, + (voiceState) => voiceState.channelId === this.id! ); }, get connectedMembers() { @@ -53,7 +53,7 @@ const baseChannel: Partial = { if (!voiceStates) return undefined; return new Collection( - voiceStates.map((vs) => [vs.userId, cache.members.get(vs.userId)]), + voiceStates.map((vs) => [vs.userId, cache.members.get(vs.userId)]) ); }, send(content) { @@ -66,26 +66,17 @@ const baseChannel: Partial = { return deleteChannel(this.id!, reason); }, editOverwrite(id, options) { - return editChannelOverwrite( - this.guildId!, - this.id!, - id, - options, - ); + return editChannelOverwrite(this.guildId!, this.id!, id, options); }, deleteOverwrite(id) { - return deleteChannelOverwrite( - this.guildId!, - this.id!, - id, - ); + return deleteChannelOverwrite(this.guildId!, this.id!, id); }, hasPermission(overwrites, permissions) { return channelOverwriteHasPermission( this.guildId!, this.id!, overwrites, - permissions, + permissions ); }, edit(options, reason) { @@ -98,50 +89,50 @@ const baseChannel: Partial = { /** Create a structure object */ // deno-lint-ignore require-await -export async function createDiscordenoChannel( - data: Channel, - guildId?: bigint, -) { - const { - lastPinTimestamp, - permissionOverwrites = [], - ...rest - } = data; +export async function createDiscordenoChannel(data: Channel, guildId?: bigint) { + const { lastPinTimestamp, permissionOverwrites = [], ...rest } = data; const props: Record = {}; Object.entries(rest).forEach(([key, value]) => { eventHandlers.debug?.( "loop", - `Running forEach loop in createDiscordenoChannel function.`, + `Running forEach loop in createDiscordenoChannel function.` ); - if (key === "guildId") value = guildId?.toString() || data.guildId || ""; - props[key] = createNewProp( CHANNEL_SNOWFLAKES.includes(key) - ? value ? snowflakeToBigint(value) : undefined - : value, + ? value + ? snowflakeToBigint(value) + : undefined + : value ); }); + // Set the guildId seperately because sometimes guildId is not included + props.guildId = createNewProp( + snowflakeToBigint(guildId?.toString() || data.guildId || "") + ); + const channel: DiscordenoChannel = Object.create(baseChannel, { ...props, lastPinTimestamp: createNewProp( - lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined, + lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined + ), + permissionOverwrites: createNewProp( + permissionOverwrites.map((o) => ({ + ...o, + id: snowflakeToBigint(o.id), + allow: snowflakeToBigint(o.allow), + deny: snowflakeToBigint(o.deny), + })) ), - permissionOverwrites: createNewProp(permissionOverwrites.map((o) => ({ - ...o, - id: snowflakeToBigint(o.id), - allow: snowflakeToBigint(o.allow), - deny: snowflakeToBigint(o.deny), - }))), }); return channel; } -export interface DiscordenoChannel extends - Omit< +export interface DiscordenoChannel + extends Omit< Channel, | "id" | "guildId" @@ -158,7 +149,7 @@ export interface DiscordenoChannel extends })[]; /** The id of the channel */ id: bigint; - /** The id of the guild */ + /** The id of the guild, 0n if it is a DM */ guildId: bigint; /** The id of the last message sent in this channel (may not point to an existing or valid message) */ lastMessageId?: bigint; @@ -208,11 +199,11 @@ export interface DiscordenoChannel extends /** Edit a channel Overwrite */ editOverwrite( overwriteId: bigint, - options: Omit, + options: Omit ): ReturnType; /** Delete a channel Overwrite */ deleteOverwrite( - overwriteId: bigint, + overwriteId: bigint ): ReturnType; /** Checks if a channel overwrite for a user id or a role id has permission in this channel */ hasPermission( @@ -221,7 +212,7 @@ export interface DiscordenoChannel extends allow: bigint; deny: bigint; })[], - permissions: PermissionStrings[], + permissions: PermissionStrings[] ): ReturnType; /** Edit the channel */ edit(options: ModifyChannel, reason?: string): ReturnType; From 5cf284b6f381001ef17ecd999fd40759a83e875a Mon Sep 17 00:00:00 2001 From: itohatweb Date: Mon, 10 May 2021 18:19:06 +0000 Subject: [PATCH 5/5] Commit from GitHub Actions (Lint) --- src/structures/channel.ts | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index df87da91e..57933d16e 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -45,7 +45,7 @@ const baseChannel: Partial = { }, get voiceStates() { return this.guild?.voiceStates.filter( - (voiceState) => voiceState.channelId === this.id! + (voiceState) => voiceState.channelId === this.id!, ); }, get connectedMembers() { @@ -53,7 +53,7 @@ const baseChannel: Partial = { if (!voiceStates) return undefined; return new Collection( - voiceStates.map((vs) => [vs.userId, cache.members.get(vs.userId)]) + voiceStates.map((vs) => [vs.userId, cache.members.get(vs.userId)]), ); }, send(content) { @@ -76,7 +76,7 @@ const baseChannel: Partial = { this.guildId!, this.id!, overwrites, - permissions + permissions, ); }, edit(options, reason) { @@ -96,27 +96,25 @@ export async function createDiscordenoChannel(data: Channel, guildId?: bigint) { Object.entries(rest).forEach(([key, value]) => { eventHandlers.debug?.( "loop", - `Running forEach loop in createDiscordenoChannel function.` + `Running forEach loop in createDiscordenoChannel function.`, ); props[key] = createNewProp( CHANNEL_SNOWFLAKES.includes(key) - ? value - ? snowflakeToBigint(value) - : undefined - : value + ? value ? snowflakeToBigint(value) : undefined + : value, ); }); // Set the guildId seperately because sometimes guildId is not included props.guildId = createNewProp( - snowflakeToBigint(guildId?.toString() || data.guildId || "") + snowflakeToBigint(guildId?.toString() || data.guildId || ""), ); const channel: DiscordenoChannel = Object.create(baseChannel, { ...props, lastPinTimestamp: createNewProp( - lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined + lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined, ), permissionOverwrites: createNewProp( permissionOverwrites.map((o) => ({ @@ -124,15 +122,15 @@ export async function createDiscordenoChannel(data: Channel, guildId?: bigint) { id: snowflakeToBigint(o.id), allow: snowflakeToBigint(o.allow), deny: snowflakeToBigint(o.deny), - })) + })), ), }); return channel; } -export interface DiscordenoChannel - extends Omit< +export interface DiscordenoChannel extends + Omit< Channel, | "id" | "guildId" @@ -199,11 +197,11 @@ export interface DiscordenoChannel /** Edit a channel Overwrite */ editOverwrite( overwriteId: bigint, - options: Omit + options: Omit, ): ReturnType; /** Delete a channel Overwrite */ deleteOverwrite( - overwriteId: bigint + overwriteId: bigint, ): ReturnType; /** Checks if a channel overwrite for a user id or a role id has permission in this channel */ hasPermission( @@ -212,7 +210,7 @@ export interface DiscordenoChannel allow: bigint; deny: bigint; })[], - permissions: PermissionStrings[] + permissions: PermissionStrings[], ): ReturnType; /** Edit the channel */ edit(options: ModifyChannel, reason?: string): ReturnType;