From 53b64682ee69961be5ce5c725af1eee8243e4acc Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Fri, 2 Apr 2021 19:02:20 +0300 Subject: [PATCH] Update to eris#dev --- backend/package-lock.json | 18 ++++++------- backend/package.json | 2 +- .../Utility/functions/getInviteInfoEmbed.ts | 7 +++++- .../Utility/functions/getServerInfoEmbed.ts | 3 ++- backend/src/utils.ts | 25 +++++++++++-------- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index 482431a1..bd0b5f3f 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1634,10 +1634,10 @@ "dev": true }, "eris": { - "version": "https://github.com/Dragory/eris/archive/custom.tar.gz", - "integrity": "sha512-6wb+mk7l/IDzqqki1IH0F8+U1dzGCbw7cHsg6dBVZ6emflHz+NnOND8XV3LPVnUQkw8ABIYzZhmYYXasURgmfg==", + "version": "github:abalabahaha/eris#54fc78d3a1f9f8ebe8b072c9c87c674c8453d016", + "from": "github:abalabahaha/eris#dev", "requires": { - "opusscript": "^0.0.7", + "opusscript": "^0.0.8", "tweetnacl": "^1.0.1", "ws": "^7.2.1" } @@ -2883,9 +2883,9 @@ } }, "opusscript": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.7.tgz", - "integrity": "sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==", + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/opusscript/-/opusscript-0.0.8.tgz", + "integrity": "sha512-VSTi1aWFuCkRCVq+tx/BQ5q9fMnQ9pVZ3JU4UHKqTkf0ED3fKEPdr+gKAAl3IA2hj9rrP6iyq3hlcJq3HELtNQ==", "optional": true }, "ora": { @@ -4696,9 +4696,9 @@ } }, "ws": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.0.tgz", - "integrity": "sha512-kyFwXuV/5ymf+IXhS6f0+eAFvydbaBW3zjpT6hUdAh/hbVjTIB5EHBGi0bPoCLSK2wcuz3BrEkB9LrYv1Nm4NQ==" + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.4.tgz", + "integrity": "sha512-Qm8k8ojNQIMx7S+Zp8u/uHOx7Qazv3Yv4q68MiWWWOJhiwG5W3x7iqmRtJo8xxrciZUY4vRxUTJCKuRnF28ZZw==" }, "xdg-basedir": { "version": "4.0.0", diff --git a/backend/package.json b/backend/package.json index 56e816d1..8ee06bdd 100644 --- a/backend/package.json +++ b/backend/package.json @@ -31,7 +31,7 @@ "deep-diff": "^1.0.2", "dotenv": "^4.0.0", "emoji-regex": "^8.0.0", - "eris": "https://github.com/Dragory/eris/archive/custom.tar.gz", + "eris": "github:abalabahaha/eris#dev", "erlpack": "github:abalabahaha/erlpack", "escape-string-regexp": "^1.0.5", "express": "^4.17.0", diff --git a/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts b/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts index c25b3a06..84760b1f 100644 --- a/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts @@ -9,6 +9,7 @@ import { EmbedWith, emptyEmbedValue, formatNumber, + inviteHasCounts, isGroupDMInvite, isGuildInvite, preEmbedPadding, @@ -50,13 +51,17 @@ export async function getInviteInfoEmbed( round: true, }); + const memberCount = inviteHasCounts(invite) ? invite.memberCount : 0; + + const presenceCount = inviteHasCounts(invite) ? invite.presenceCount : 0; + embed.fields.push({ name: preEmbedPadding + "Server information", value: trimLines(` Name: **${invite.guild.name}** ID: \`${invite.guild.id}\` Created: **${serverAge} ago** - Members: **${formatNumber(invite.memberCount)}** (${formatNumber(invite.presenceCount)} online) + Members: **${formatNumber(memberCount)}** (${formatNumber(presenceCount)} online) `), inline: true, }); diff --git a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts index 3022a250..3704da97 100644 --- a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts @@ -4,6 +4,7 @@ import { embedPadding, EmbedWith, formatNumber, + inviteHasCounts, memoize, MINUTES, preEmbedPadding, @@ -120,7 +121,7 @@ export async function getServerInfoEmbed( if (onlineMemberCount == null && restGuild?.vanityURL) { // For servers with a vanity URL, we can also use the numbers from the invite for online count const invite = await resolveInvite(pluginData.client, restGuild.vanityURL!, true); - if (invite) { + if (invite && inviteHasCounts(invite)) { onlineMemberCount = invite.presenceCount; } } diff --git a/backend/src/utils.ts b/backend/src/utils.ts index b78a29c7..77ca7c89 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -12,7 +12,6 @@ import { GuildChannel, Invite, InvitePartialChannel, - InviteWithMetadata, Member, Message, MessageContent, @@ -181,11 +180,11 @@ export function nonNullish(v: V): v is NonNullable { return v != null; } -export type GuildInvite = Invite & { guild: Guild }; -export type GroupDMInvite = Invite & { channel: InvitePartialChannel; type: typeof Constants.ChannelTypes.GROUP_DM }; -export type WithInviteCounts = { - memberCount: number; - presenceCount: number; +export type InviteOpts = "withMetadata" | "withCount" | "withoutCount"; +export type GuildInvite = Invite & { guild: Guild }; +export type GroupDMInvite = Invite & { + channel: InvitePartialChannel; + type: typeof Constants.ChannelTypes.GROUP_DM; }; /** @@ -1153,9 +1152,11 @@ export async function resolveRoleId(bot: Client, guildId: string, value: string) return null; } -const inviteCache = new SimpleCache>(10 * MINUTES, 200); +const inviteCache = new SimpleCache | null>>(10 * MINUTES, 200); -type ResolveInviteReturnType = Promise<(T extends true ? Invite & WithInviteCounts : Invite) | null>; +type ResolveInviteReturnType = Promise< + (T extends true ? Invite<"withCount" | "withMetadata"> : Invite<"withMetadata">) | null +>; export async function resolveInvite( client: Client, code: string, @@ -1330,14 +1331,18 @@ export function isFullMessage(msg: PossiblyUncachedMessage): msg is Message { return (msg as Message).createdAt != null; } -export function isGuildInvite(invite: Invite): invite is GuildInvite { +export function isGuildInvite(invite: Invite): invite is GuildInvite { return invite.guild != null; } -export function isGroupDMInvite(invite: Invite): invite is GroupDMInvite { +export function isGroupDMInvite(invite: Invite): invite is GroupDMInvite { return invite.guild == null && invite.channel?.type === Constants.ChannelTypes.GROUP_DM; } +export function inviteHasCounts(invite: Invite): invite is Invite<"withCount"> { + return invite.memberCount != null; +} + export function asyncMap(arr: T[], fn: (item: T) => Promise): Promise { return Promise.all(arr.map((item, index) => fn(item))); }