From 7b737cc31e301701a40fad017f2844de99662f5d Mon Sep 17 00:00:00 2001 From: Federico Grandi Date: Fri, 26 Mar 2021 09:52:43 +0100 Subject: [PATCH 1/6] fix(DiscordJS): update shard getter for v12 --- src/Interface/Clients/DiscordJS.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Interface/Clients/DiscordJS.ts b/src/Interface/Clients/DiscordJS.ts index 142d9d2f..6b8d8467 100644 --- a/src/Interface/Clients/DiscordJS.ts +++ b/src/Interface/Clients/DiscordJS.ts @@ -37,10 +37,15 @@ export default class DiscordJS extends ClientFiller { get shard(): Shard | undefined { return this.client.shard - ? { - id: this.client.shard.id, - count: this.client.shard.count - } + ? this.client.shard?.ids // True if on v12 + ? { + id: this.client.guilds?.cache?.find((g: any) => g.shardID)?.shardID, + count: this.client.shard.count + } + : { + id: this.client.shard.id, + count: this.client.shard.count + } : undefined } } From 4db583d5d55cef710be066a44bd28f7f877820c0 Mon Sep 17 00:00:00 2001 From: Federico Grandi Date: Fri, 26 Mar 2021 08:54:26 +0000 Subject: [PATCH 2/6] [auto] docs: update docs --- docs/general/services.md | 62 ++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/docs/general/services.md b/docs/general/services.md index 430059f0..d0230441 100644 --- a/docs/general/services.md +++ b/docs/general/services.md @@ -9,7 +9,7 @@

Arcane Bot List

Keys: `arcane`, `arcane-center.xyz` -Class: [dbots.Arcane](/#/docs/main/master/class/Arcane) +Class: [dbots.Arcane](/#/docs/main/djs12-shards/class/Arcane) Website: https://arcane-center.xyz @@ -22,7 +22,7 @@ Website: https://arcane-center.xyz

Astro Bot List

Keys: `astrobotlist`, `botlists.com` -Class: [dbots.AstroBotList](/#/docs/main/master/class/AstroBotList) +Class: [dbots.AstroBotList](/#/docs/main/djs12-shards/class/AstroBotList) Website: https://botlists.com @@ -35,7 +35,7 @@ Website: https://botlists.com

BladeBotList

Keys: `bladebotlist`, `bladebotlist.xyz` -Class: [dbots.BladeBotList](/#/docs/main/master/class/BladeBotList) +Class: [dbots.BladeBotList](/#/docs/main/djs12-shards/class/BladeBotList) Website: https://bladebotlist.xyz @@ -48,7 +48,7 @@ Website: https://bladebotlist.xyz

Blist

Keys: `blist`, `blist.xyz` -Class: [dbots.Blist](/#/docs/main/master/class/Blist) +Class: [dbots.Blist](/#/docs/main/djs12-shards/class/Blist) Website: https://blist.xyz @@ -61,7 +61,7 @@ Website: https://blist.xyz

botlist.space

Keys: `botlistspace`, `botlist.space` -Class: [dbots.BotListSpace](/#/docs/main/master/class/BotListSpace) +Class: [dbots.BotListSpace](/#/docs/main/djs12-shards/class/BotListSpace) Website: https://botlist.space @@ -74,7 +74,7 @@ Website: https://botlist.space

BotsDataBase

Keys: `botsdatabase`, `botsdatabase.com` -Class: [dbots.BotsDataBase](/#/docs/main/master/class/BotsDataBase) +Class: [dbots.BotsDataBase](/#/docs/main/djs12-shards/class/BotsDataBase) Website: https://botsdatabase.com @@ -87,7 +87,7 @@ Website: https://botsdatabase.com

Bots For Discord

Keys: `botsfordiscord`, `botsfordiscord.com` -Class: [dbots.BotsForDiscord](/#/docs/main/master/class/BotsForDiscord) +Class: [dbots.BotsForDiscord](/#/docs/main/djs12-shards/class/BotsForDiscord) Website: https://botsfordiscord.com @@ -100,7 +100,7 @@ Website: https://botsfordiscord.com

Bots On Discord

Keys: `botsondiscord`, `bots.ondiscord.xyz` -Class: [dbots.BotsOnDiscord](/#/docs/main/master/class/BotsOnDiscord) +Class: [dbots.BotsOnDiscord](/#/docs/main/djs12-shards/class/BotsOnDiscord) Website: https://bots.ondiscord.xyz @@ -114,7 +114,7 @@ Website: https://bots.ondiscord.xyz

Carbonitex

Keys: `carbonitex`, `carbonitex.net`, `carbon` -Class: [dbots.Carbon](/#/docs/main/master/class/Carbon) +Class: [dbots.Carbon](/#/docs/main/djs12-shards/class/Carbon) Website: https://www.carbonitex.net/Discord/bots @@ -127,7 +127,7 @@ Website: https://www.carbonitex.net/Discord/bots

DBots.co

Keys: `dbots`, `dbots.co` -Class: [dbots.DBots](/#/docs/main/master/class/DBots) +Class: [dbots.DBots](/#/docs/main/djs12-shards/class/DBots) Website: https://dbots.co/ @@ -140,7 +140,7 @@ Website: https://dbots.co/

Discord Apps

Keys: `discordappsdev`, `discordapps.dev` -Class: [dbots.DiscordAppsDev](/#/docs/main/master/class/DiscordAppsDev) +Class: [dbots.DiscordAppsDev](/#/docs/main/djs12-shards/class/DiscordAppsDev) Website: https://discordapps.dev @@ -153,7 +153,7 @@ Website: https://discordapps.dev

Discord Boats

Keys: `discordboats`, `discord.boats` -Class: [dbots.DiscordBoats](/#/docs/main/master/class/DiscordBoats) +Class: [dbots.DiscordBoats](/#/docs/main/djs12-shards/class/DiscordBoats) Website: https://discord.boats @@ -166,7 +166,7 @@ Website: https://discord.boats

Discord Bot Directory

Keys: `discordbotdirectory`, `discordbotdirectory.net` -Class: [dbots.DiscordBotDirectory](/#/docs/main/master/class/DiscordBotDirectory) +Class: [dbots.DiscordBotDirectory](/#/docs/main/djs12-shards/class/DiscordBotDirectory) Website: https://discordbotdirectory.net @@ -179,7 +179,7 @@ Website: https://discordbotdirectory.net

Discord Bot List

Keys: `discordbotlist`, `discordbotlist.com` -Class: [dbots.DiscordBotList](/#/docs/main/master/class/DiscordBotList) +Class: [dbots.DiscordBotList](/#/docs/main/djs12-shards/class/DiscordBotList) Website: https://discordbotlist.com @@ -192,7 +192,7 @@ Website: https://discordbotlist.com

DiscordBots.co

Keys: `discordbotsco`, `discordbots.co` -Class: [dbots.DiscordBotsCo](/#/docs/main/master/class/DiscordBotsCo) +Class: [dbots.DiscordBotsCo](/#/docs/main/djs12-shards/class/DiscordBotsCo) Website: https://discordbots.co @@ -205,7 +205,7 @@ Website: https://discordbots.co

Discord Bots

Keys: `discordbotsgg`, `discord.bots.gg` -Class: [dbots.DiscordBotsGG](/#/docs/main/master/class/DiscordBotsGG) +Class: [dbots.DiscordBotsGG](/#/docs/main/djs12-shards/class/DiscordBotsGG) Website: https://discord.bots.gg @@ -218,7 +218,7 @@ Website: https://discord.bots.gg

Discord Extreme List

Keys: `discordextremelist`, `discordextremelist.xyz` -Class: [dbots.DiscordExtremeList](/#/docs/main/master/class/DiscordExtremeList) +Class: [dbots.DiscordExtremeList](/#/docs/main/djs12-shards/class/DiscordExtremeList) Website: https://discordextremelist.xyz/ @@ -231,7 +231,7 @@ Website: https://discordextremelist.xyz/

Discord Labs

Keys: `discordlabs`, `discordlabs.org` -Class: [dbots.DiscordLabs](/#/docs/main/master/class/DiscordLabs) +Class: [dbots.DiscordLabs](/#/docs/main/djs12-shards/class/DiscordLabs) Website: https://bots.discordlabs.org/ @@ -244,7 +244,7 @@ Website: https://bots.discordlabs.org/

DiscordListology

Keys: `discordlistology`, `discordlistology.com` -Class: [dbots.DiscordListology](/#/docs/main/master/class/DiscordListology) +Class: [dbots.DiscordListology](/#/docs/main/djs12-shards/class/DiscordListology) Website: https://discordlistology.com/ @@ -257,7 +257,7 @@ Website: https://discordlistology.com/

Discord Services

Keys: `discordservices`, `discordservices.net` -Class: [dbots.DiscordServices](/#/docs/main/master/class/DiscordServices) +Class: [dbots.DiscordServices](/#/docs/main/djs12-shards/class/DiscordServices) Website: https://discordservices.net @@ -270,7 +270,7 @@ Website: https://discordservices.net

Disforge

Keys: `disforge`, `disforge.com` -Class: [dbots.Disforge](/#/docs/main/master/class/Disforge) +Class: [dbots.Disforge](/#/docs/main/djs12-shards/class/Disforge) Website: https://disforge.com/bots @@ -283,7 +283,7 @@ Website: https://disforge.com/bots

Glenn Bot List

Keys: `glennbotlist`, `glennbotlist.xyz` -Class: [dbots.GlennBotList](/#/docs/main/master/class/GlennBotList) +Class: [dbots.GlennBotList](/#/docs/main/djs12-shards/class/GlennBotList) Website: https://glennbotlist.xyz @@ -296,7 +296,7 @@ Website: https://glennbotlist.xyz

Infinity Bot List

Keys: `infinitybots`, `infinitybots.xyz` -Class: [dbots.InfinityBots](/#/docs/main/master/class/InfinityBots) +Class: [dbots.InfinityBots](/#/docs/main/djs12-shards/class/InfinityBots) Website: https://infinitybots.xyz @@ -309,7 +309,7 @@ Website: https://infinitybots.xyz

List My Bots

Keys: `listmybots`, `listmybots.com` -Class: [dbots.ListMyBots](/#/docs/main/master/class/ListMyBots) +Class: [dbots.ListMyBots](/#/docs/main/djs12-shards/class/ListMyBots) Website: https://listmybots.com/ @@ -322,7 +322,7 @@ Website: https://listmybots.com/

Paradise Bots

Keys: `paradisebots`, `paradisebots.net` -Class: [dbots.ParadiseBots](/#/docs/main/master/class/ParadiseBots) +Class: [dbots.ParadiseBots](/#/docs/main/djs12-shards/class/ParadiseBots) Website: https://paradisebots.net/ @@ -335,7 +335,7 @@ Website: https://paradisebots.net/

Space Bots List

Keys: `spacebotslist`, `space-bot-list.xyz` -Class: [dbots.SpaceBotsList](/#/docs/main/master/class/SpaceBotsList) +Class: [dbots.SpaceBotsList](/#/docs/main/djs12-shards/class/SpaceBotsList) Website: https://space-bot-list.xyz/ @@ -348,7 +348,7 @@ Website: https://space-bot-list.xyz/

TopCord

Keys: `topcord`, `topcord.xyz` -Class: [dbots.TopCord](/#/docs/main/master/class/TopCord) +Class: [dbots.TopCord](/#/docs/main/djs12-shards/class/TopCord) Website: https://topcord.xyz/ @@ -361,7 +361,7 @@ Website: https://topcord.xyz/

Top.gg

Keys: `topgg`, `top.gg` -Class: [dbots.TopGG](/#/docs/main/master/class/TopGG) +Class: [dbots.TopGG](/#/docs/main/djs12-shards/class/TopGG) Website: https://top.gg @@ -374,7 +374,7 @@ Website: https://top.gg

Void Bots

Keys: `voidbots`, `voidbots.net` -Class: [dbots.VoidBots](/#/docs/main/master/class/VoidBots) +Class: [dbots.VoidBots](/#/docs/main/djs12-shards/class/VoidBots) Website: https://voidbots.net/ @@ -387,7 +387,7 @@ Website: https://voidbots.net/

Wonder Bot List

Keys: `wonderbotlist`, `wonderbotlist.com` -Class: [dbots.WonderBotList](/#/docs/main/master/class/WonderBotList) +Class: [dbots.WonderBotList](/#/docs/main/djs12-shards/class/WonderBotList) Website: https://wonderbotlist.com/en @@ -400,6 +400,6 @@ Website: https://wonderbotlist.com/en

Yet Another Bot List

Keys: `yabl`, `yabl.xyz` -Class: [dbots.YABL](/#/docs/main/master/class/YABL) +Class: [dbots.YABL](/#/docs/main/djs12-shards/class/YABL) Website: https://yabl.xyz/ \ No newline at end of file From 51ffad86899d216b5fc42974d63b99766d647312 Mon Sep 17 00:00:00 2001 From: Federico Grandi Date: Sun, 28 Mar 2021 13:59:08 +0200 Subject: [PATCH 3/6] fix(DiscordJS): improve shard getter --- src/Interface/Clients/DiscordJS.ts | 40 ++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/Interface/Clients/DiscordJS.ts b/src/Interface/Clients/DiscordJS.ts index 6b8d8467..24daef27 100644 --- a/src/Interface/Clients/DiscordJS.ts +++ b/src/Interface/Clients/DiscordJS.ts @@ -36,16 +36,34 @@ export default class DiscordJS extends ClientFiller { } get shard(): Shard | undefined { - return this.client.shard - ? this.client.shard?.ids // True if on v12 - ? { - id: this.client.guilds?.cache?.find((g: any) => g.shardID)?.shardID, - count: this.client.shard.count - } - : { - id: this.client.shard.id, - count: this.client.shard.count - } - : undefined + if ( + (this.client.shard?.ids && this.client.shard?.ids.length !== 1) || + this.client.options?.shards instanceof Array + ) + // v12 unsupported + return undefined + + if (this.client.shard?.id) + // v11 + return { + id: this.client.shard.id, + count: this.client.shard.count + } + + if (this.client.shard?.ids) + // v12 supported, using a ShardingManager + return { + id: this.client.shard.ids[0], + count: this.client.shard.count + } + + if (typeof this.client.options?.shards == 'number') + // v12 supported, manual + return { + id: this.client.options.shards, + count: this.client.options.shardCount + } + + return undefined } } From e5179ecfcf99188bd79f48d460af2675434060cd Mon Sep 17 00:00:00 2001 From: Federico Grandi Date: Sun, 28 Mar 2021 21:12:23 +0200 Subject: [PATCH 4/6] fix(DiscordJS): don't support manual shards Co-authored-by: Snazzah <7025343+Snazzah@users.noreply.github.com> --- src/Interface/Clients/DiscordJS.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Interface/Clients/DiscordJS.ts b/src/Interface/Clients/DiscordJS.ts index 24daef27..612074a1 100644 --- a/src/Interface/Clients/DiscordJS.ts +++ b/src/Interface/Clients/DiscordJS.ts @@ -57,12 +57,6 @@ export default class DiscordJS extends ClientFiller { count: this.client.shard.count } - if (typeof this.client.options?.shards == 'number') - // v12 supported, manual - return { - id: this.client.options.shards, - count: this.client.options.shardCount - } return undefined } From c1f1e0f91d157003fb13915cf2ca79f849a29446 Mon Sep 17 00:00:00 2001 From: Federico Grandi Date: Sun, 28 Mar 2021 21:51:54 +0200 Subject: [PATCH 5/6] fix(DiscordJS): remove remaining manual sharding support Line 41 was explicitly removing support for manual sharding. If you're spawning shards manually you're supposed to provide the shard data yourself in the Poster options. --- src/Interface/Clients/DiscordJS.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Interface/Clients/DiscordJS.ts b/src/Interface/Clients/DiscordJS.ts index 612074a1..4bbd14a4 100644 --- a/src/Interface/Clients/DiscordJS.ts +++ b/src/Interface/Clients/DiscordJS.ts @@ -9,10 +9,12 @@ import { ClientFiller } from '../ClientFiller' export default class DiscordJS extends ClientFiller { get userCount(): number { if (this.client.guilds?.constructor?.name === 'GuildManager') + // v12 return this.client.guilds?.cache?.reduce( (count: number, guild: AnyObject) => count + guild.memberCount, 0 ) + // v11 else return this.client.guilds?.reduce( (count: number, guild: AnyObject) => count + guild.memberCount, @@ -22,13 +24,16 @@ export default class DiscordJS extends ClientFiller { get serverCount(): number { if (this.client.guilds?.constructor?.name === 'GuildManager') + // v12 return this.client.guilds?.cache?.size - else return this.client.guilds?.size + else return this.client.guilds?.size // v11 } get voiceConnections(): number { - if (this.client.voice) return this.client.voice.broadcasts?.length || 0 - else return this.client.broadcasts?.size + if (this.client.voice) + // v12 + return this.client.voice.broadcasts?.length || 0 + else return this.client.broadcasts?.size // v11 } get clientID(): string | undefined { @@ -36,10 +41,7 @@ export default class DiscordJS extends ClientFiller { } get shard(): Shard | undefined { - if ( - (this.client.shard?.ids && this.client.shard?.ids.length !== 1) || - this.client.options?.shards instanceof Array - ) + if (this.client.shard?.ids && this.client.shard?.ids.length !== 1) // v12 unsupported return undefined @@ -57,7 +59,6 @@ export default class DiscordJS extends ClientFiller { count: this.client.shard.count } - return undefined } } From e66761e8401ed4bac67bd0c0fad8783cba9d28ca Mon Sep 17 00:00:00 2001 From: Federico Grandi Date: Sun, 28 Mar 2021 21:52:55 +0200 Subject: [PATCH 6/6] test(DiscordJS): improve fake clients --- tests/Interface/Clients/common.test.ts | 118 ++++++++++++++++--------- 1 file changed, 76 insertions(+), 42 deletions(-) diff --git a/tests/Interface/Clients/common.test.ts b/tests/Interface/Clients/common.test.ts index 4bc47c7e..7584628c 100644 --- a/tests/Interface/Clients/common.test.ts +++ b/tests/Interface/Clients/common.test.ts @@ -6,51 +6,80 @@ import Collection from '@discordjs/collection' const clientsDir = path.join(__dirname, '../../../src/Interface/Clients') const fakeClients = { - Discordie: { - Guilds: { - size: 123, - toArray: () => [1, 2, 3].map((n) => ({ member_count: n })) - }, - VoiceConnections: [1, 2, 3], - User: { id: 'abc' }, - options: { - shardId: 'abc', - shardCount: 123 + Discordie: [ + { + Guilds: { + size: 123, + toArray: () => [1, 2, 3].map((n) => ({ member_count: n })) + }, + VoiceConnections: [1, 2, 3], + User: { id: 'abc' }, + options: { + shardId: 'abc', + shardCount: 123 + } } - }, - DiscordIO: { - servers: [1, 2, 3].map((n) => ({ member_count: n })), - _vChannels: [1, 2, 3], - id: 'abc', - _shard: ['abc', 123] - }, - DiscordJS: { - guilds: { - constructor: { name: 'GuildManager' }, - cache: new Collection([1, 2, 3].map((n) => [n, { memberCount: n }])) - }, - voice: { broadcasts: [1, 2, 3] }, - user: { id: 'abc' }, - shard: { + ], + DiscordIO: [ + { + servers: [1, 2, 3].map((n) => ({ member_count: n })), + _vChannels: [1, 2, 3], id: 'abc', - count: 123 + _shard: ['abc', 123] } - }, - Eris: { - guilds: new Collection([1, 2, 3].map((n) => [n, { memberCount: n }])), - voiceConnections: { - constructor: { name: 'VoiceConnectionManager' }, - size: 123 + ], + DiscordJS: [ + { + // v11 + guilds: new Collection([1, 2, 3].map((n) => [n, { memberCount: n }])), + broadcasts: { size: 123 }, + user: { id: 'abc' }, + shard: { + id: 'abc', + count: 123 + } }, - user: { id: 'abc' } - }, - Paracord: { - guilds: { - values: [1, 2, 3].map((n) => [n, { member_count: n }]), - size: 123 + { + // v12 + guilds: { + constructor: { name: 'GuildManager' }, + cache: new Collection([1, 2, 3].map((n) => [n, { memberCount: n }])) + }, + voice: { broadcasts: [1, 2, 3] }, + user: { id: 'abc' }, + shard: { + ids: [123], + count: 123 + } }, - user: { id: 'abc' } - } + { + // v12, unsupported sharding + testAsEmpty: true, + shard: { + ids: [1, 2, 3], + count: 123 + } + } + ], + Eris: [ + { + guilds: new Collection([1, 2, 3].map((n) => [n, { memberCount: n }])), + voiceConnections: { + constructor: { name: 'VoiceConnectionManager' }, + size: 123 + }, + user: { id: 'abc' } + } + ], + Paracord: [ + { + guilds: { + values: [1, 2, 3].map((n) => [n, { member_count: n }]), + size: 123 + }, + user: { id: 'abc' } + } + ] } const noVoiceFillers: (keyof typeof fakeClients)[] = ['Paracord'] const noShardFillers: (keyof typeof fakeClients)[] = ['Eris', 'Paracord'] @@ -64,7 +93,6 @@ fs.readdirSync(clientsDir).forEach((file) => { describe(`${fileName} class`, () => { const emptyClient = new Client({}) - const fakeClient = fakeClients[fileName] const testClient = (c: ClientFiller, name: string, empty = false) => { const eType = empty ? 'undefined' : undefined @@ -108,7 +136,13 @@ fs.readdirSync(clientsDir).forEach((file) => { } testClient(emptyClient, 'empty client', true) - if (fakeClient) testClient(new Client(fakeClient), 'fake client') + fakeClients[fileName]?.forEach((client: any, index: number) => + testClient( + new Client(client), + `fake client [${index}]`, + client.testAsEmpty + ) + ) }) }) })