From 54e0e41dc7e0fe8c56624390000b121cbed2e6d8 Mon Sep 17 00:00:00 2001 From: Helloyunho Date: Mon, 25 Jan 2021 23:02:43 +0900 Subject: [PATCH 1/5] just test thing --- src/test/index.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/test/index.ts b/src/test/index.ts index aa30522..528982c 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -13,6 +13,7 @@ import { } from '../../mod.ts' import { Collector } from '../models/collectors.ts' import { MessageAttachment } from '../structures/message.ts' +import { Permissions } from '../utils/permissions.ts' import { TOKEN } from './config.ts' const client = new Client({ @@ -160,6 +161,37 @@ client.on('messageCreate', async (msg: Message) => { const vs = await msg.guild?.voiceStates.get(msg.member.id) if (typeof vs !== 'object') return vs.channel?.join() + } else if (msg.content === '!getOverwrites') { + if (msg.channel.type !== ChannelTypes.GUILD_TEXT) { + return msg.channel.send("This isn't a guild text channel!") + } + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const overwrites = await (msg.channel as GuildTextChannel).overwritesFor( + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + msg.member as Member + ) + msg.channel.send( + `Your permission overwrites:\n${overwrites + .map( + (over) => + `ID: ${over.id}\nAllowed:\n${new Permissions(over.allow) + .toArray() + .join('\n')}\nDenied:\n${new Permissions(over.deny) + .toArray() + .join('\n')}` + ) + .join('\n\n')}` + ) + } else if (msg.content === '!getPermissions') { + if (msg.channel.type !== ChannelTypes.GUILD_TEXT) { + return msg.channel.send("This isn't a guild text channel!") + } + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const permissions = await (msg.channel as GuildTextChannel).permissionsFor( + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + msg.member as Member + ) + msg.channel.send(`Your permissions:\n${permissions.toArray().join('\n')}`) } }) From 2a38fc1e0052c57520113043544e6ccd97095e51 Mon Sep 17 00:00:00 2001 From: Helloyunho Date: Thu, 28 Jan 2021 04:10:11 +0900 Subject: [PATCH 2/5] Fix member nick type --- src/structures/member.ts | 6 +++--- src/types/guild.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/structures/member.ts b/src/structures/member.ts index f035ddb..fe491d4 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -18,7 +18,7 @@ export interface MemberData { export class Member extends SnowflakeBase { id: string user: User - nick?: string + nick: string | null roles: MemberRolesManager joinedAt: string premiumSince?: string @@ -49,7 +49,7 @@ export class Member extends SnowflakeBase { } get displayName(): string { - return this.nick !== undefined ? this.nick : this.user.username + return this.nick !== null ? this.nick : this.user.username } toString(): string { @@ -95,7 +95,7 @@ export class Member extends SnowflakeBase { ) if (res.ok === true) { if (data.nick !== undefined) - this.nick = data.nick === null ? undefined : data.nick + this.nick = data.nick === null ? null : data.nick if (data.deaf !== undefined) this.deaf = data.deaf if (data.mute !== undefined) this.mute = data.mute } diff --git a/src/types/guild.ts b/src/types/guild.ts index 3c67657..30d009a 100644 --- a/src/types/guild.ts +++ b/src/types/guild.ts @@ -67,7 +67,7 @@ export interface GuildPayload { export interface MemberPayload { user: UserPayload - nick?: string + nick: string | null roles: string[] joined_at: string premium_since?: string From bf0c82f27302448750d0078948d7e3fb9b59df1a Mon Sep 17 00:00:00 2001 From: Helloyunho Date: Thu, 28 Jan 2021 04:14:39 +0900 Subject: [PATCH 3/5] fix unpatched part --- src/types/gateway.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/gateway.ts b/src/types/gateway.ts index 937a41b..8186f6f 100644 --- a/src/types/gateway.ts +++ b/src/types/gateway.ts @@ -212,7 +212,7 @@ export interface GuildMemberUpdatePayload { guild_id: string roles: string[] user: UserPayload - nick?: string | undefined + nick: string | null joined_at: string premium_since?: string | undefined } From 6a58a69031f8422efd4ccdc5377fb2f689f776aa Mon Sep 17 00:00:00 2001 From: ayntee Date: Thu, 28 Jan 2021 20:05:12 +0400 Subject: [PATCH 4/5] fix(models/rest): unique key for form data item --- src/models/rest.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/models/rest.ts b/src/models/rest.ts index f14e81d..7adbdf6 100644 --- a/src/models/rest.ts +++ b/src/models/rest.ts @@ -319,9 +319,7 @@ export class RESTManager { } } const form = new FormData() - for (const file of files) { - form.append(file.name, file.blob, file.name) - } + files.map((file, index) => form.append(`file${index + 1}`, file.blob, file.name)) const json = JSON.stringify(body) form.append('payload_json', json) if (body === undefined) body = {} From d7647a88eed4ed5e0aa72976a893d872b44e72b4 Mon Sep 17 00:00:00 2001 From: ayntee Date: Thu, 28 Jan 2021 20:26:41 +0400 Subject: [PATCH 5/5] Update src/models/rest.ts --- src/models/rest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/rest.ts b/src/models/rest.ts index 7adbdf6..daab5d1 100644 --- a/src/models/rest.ts +++ b/src/models/rest.ts @@ -319,7 +319,7 @@ export class RESTManager { } } const form = new FormData() - files.map((file, index) => form.append(`file${index + 1}`, file.blob, file.name)) + files.forEach((file, index) => form.append(`file${index + 1}`, file.blob, file.name)) const json = JSON.stringify(body) form.append('payload_json', json) if (body === undefined) body = {}