From b91e072e2fbc63692f42a1e9476e171ee37905bb Mon Sep 17 00:00:00 2001 From: cheqpat Date: Sat, 2 Oct 2021 02:14:47 -0500 Subject: [PATCH 01/30] implement @udany's fix --- src/commands/play.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/commands/play.ts b/src/commands/play.ts index a907a40..0dc1ce1 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -157,12 +157,16 @@ export default class implements Command { await res.stop(`u betcha, **${firstSong.title}** and ${newSongs.length - 1} other songs were added to the queue${extraMsg}`); } + if (player.voiceConnection === null) { + await player.connect(targetVoiceChannel); + + if (player.status === STATUS.PAUSED && queueOldSize) { + await msg.channel.send('joined, but I\'m paused, use a lonely `-p` to resume playback'); + } + } + if (queueOldSize === 0 && !wasPlayingSong) { // Only auto-play if queue was empty before and nothing was playing - if (player.voiceConnection === null) { - await player.connect(targetVoiceChannel); - } - await player.play(); } } From 3924c8007c08fa62b71303333d3563671e3c3db1 Mon Sep 17 00:00:00 2001 From: cheqpat Date: Sat, 2 Oct 2021 02:16:59 -0500 Subject: [PATCH 02/30] Always autoplay rather than alerting that it is paused --- src/commands/play.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/play.ts b/src/commands/play.ts index 0dc1ce1..a0e5bb6 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -161,7 +161,8 @@ export default class implements Command { await player.connect(targetVoiceChannel); if (player.status === STATUS.PAUSED && queueOldSize) { - await msg.channel.send('joined, but I\'m paused, use a lonely `-p` to resume playback'); + // Resume playing from queue after being paused + await player.play(); } } From d8b434b9bd7840d26754829713ec66fa55e73c7a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Nov 2021 01:18:41 +0000 Subject: [PATCH 03/30] Bump array-shuffle from 2.0.0 to 3.0.0 Bumps [array-shuffle](https://github.com/sindresorhus/array-shuffle) from 2.0.0 to 3.0.0. - [Release notes](https://github.com/sindresorhus/array-shuffle/releases) - [Commits](https://github.com/sindresorhus/array-shuffle/compare/v2.0.0...v3.0.0) --- updated-dependencies: - dependency-name: array-shuffle dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 79235d3..419f06e 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "@discordjs/opus": "^0.7.0", "@discordjs/voice": "^0.7.5", "@types/libsodium-wrappers": "^0.7.9", - "array-shuffle": "^2.0.0", + "array-shuffle": "^3.0.0", "debug": "^4.3.1", "delay": "^5.0.0", "discord.js": "^13.3.0", diff --git a/yarn.lock b/yarn.lock index 93c2cd2..74e30a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -532,10 +532,10 @@ argparse@^1.0.7: dependencies: sprintf-js "~1.0.2" -array-shuffle@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/array-shuffle/-/array-shuffle-2.0.0.tgz#fd36437cd7997d557055283c946e46379a7cd343" - integrity sha512-rJTchCppiO6QsQnN51KDH1cgMYm13B+ybxFS5GgdBdTTHpZcrq3M7SOBgzp+L9fqqnjkFDiwdEVcX1wINgl9DQ== +array-shuffle@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/array-shuffle/-/array-shuffle-3.0.0.tgz#9a927cc2ca4c8ef4d71cddef7c9ee7b3b733d54b" + integrity sha512-rogEGxHOQPhslOhpg12LJkB+bbAl484/s2AJq0BxtzQDQfKl76fS2u9zWgg3p3b9ENcuvE7K8A7l5ddiPjCRnw== array-union@^2.1.0: version "2.1.0" From e3c6ac4b249b055915dc58db2fa51407d3767b97 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Nov 2021 01:18:50 +0000 Subject: [PATCH 04/30] Bump inversify from 5.1.1 to 6.0.1 Bumps [inversify](https://github.com/inversify/InversifyJS) from 5.1.1 to 6.0.1. - [Release notes](https://github.com/inversify/InversifyJS/releases) - [Changelog](https://github.com/inversify/InversifyJS/blob/master/CHANGELOG.md) - [Commits](https://github.com/inversify/InversifyJS/compare/5.1.1...v6.0.1) --- updated-dependencies: - dependency-name: inversify dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 79235d3..d98248a 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "get-youtube-id": "^1.0.1", "got": "^11.8.2", "hasha": "^5.2.2", - "inversify": "^5.1.1", + "inversify": "^6.0.1", "iso8601-duration": "^1.3.0", "libsodium-wrappers": "^0.7.9", "make-dir": "^3.1.0", diff --git a/yarn.lock b/yarn.lock index 93c2cd2..6b0f4c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1761,10 +1761,10 @@ ini@~1.3.0: resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== -inversify@^5.1.1: - version "5.1.1" - resolved "https://registry.yarnpkg.com/inversify/-/inversify-5.1.1.tgz#6fbd668c591337404e005a1946bfe0d802c08730" - integrity sha512-j8grHGDzv1v+8T1sAQ+3boTCntFPfvxLCkNcxB1J8qA0lUN+fAlSyYd+RXKvaPRL4AGyPxViutBEJHNXOyUdFQ== +inversify@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/inversify/-/inversify-6.0.1.tgz#b20d35425d5d8c5cd156120237aad0008d969f02" + integrity sha512-B3ex30927698TJENHR++8FfEaJGqoWOgI6ZY5Ht/nLUsFCwHn6akbwtnUAPCgUepAnTpe2qHxhDNjoKLyz6rgQ== is-arrayish@^0.2.1: version "0.2.1" From 9abc7370a8671c6802417a0e4a3fe5a592600d81 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Nov 2021 01:19:30 +0000 Subject: [PATCH 05/30] Bump p-limit from 3.1.0 to 4.0.0 Bumps [p-limit](https://github.com/sindresorhus/p-limit) from 3.1.0 to 4.0.0. - [Release notes](https://github.com/sindresorhus/p-limit/releases) - [Commits](https://github.com/sindresorhus/p-limit/compare/v3.1.0...v4.0.0) --- updated-dependencies: - dependency-name: p-limit dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 79235d3..0a64999 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "make-dir": "^3.1.0", "node-emoji": "^1.10.0", "p-event": "^4.2.0", - "p-limit": "^3.1.0", + "p-limit": "^4.0.0", "p-queue": "^7.1.0", "reflect-metadata": "^0.1.13", "sequelize": "^6.11.0", diff --git a/yarn.lock b/yarn.lock index 93c2cd2..4d58279 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2455,13 +2455,20 @@ p-finally@^1.0.0: resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4= -p-limit@^3.0.2, p-limit@^3.1.0: +p-limit@^3.0.2: version "3.1.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b" integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== dependencies: yocto-queue "^0.1.0" +p-limit@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-4.0.0.tgz#914af6544ed32bfa54670b061cafcbd04984b644" + integrity sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ== + dependencies: + yocto-queue "^1.0.0" + p-locate@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834" @@ -3515,6 +3522,11 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== +yocto-queue@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251" + integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g== + youtube.ts@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/youtube.ts/-/youtube.ts-0.2.2.tgz#d068bd13da7d2a98743d78682d54535d9c1a2833" From 3b2aa47e95e277e94a053636f693801c8dc96cf4 Mon Sep 17 00:00:00 2001 From: Hellyson Rodrigo Parteka Date: Tue, 30 Nov 2021 04:39:40 -0300 Subject: [PATCH 06/30] fix(file-cache): try/catch to prevent concurrency issues --- src/services/file-cache.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index fa4f1f7..ddbe190 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -58,10 +58,14 @@ export default class FileCacheProvider { const stats = await fs.stat(tmpPath); if (stats.size !== 0) { - await fs.rename(tmpPath, finalPath); - } + try { + await fs.rename(tmpPath, finalPath); - await FileCache.create({hash, bytes: stats.size, accessedAt: new Date()}); + await FileCache.create({hash, bytes: stats.size, accessedAt: new Date()}); + } catch (e: unknown) { + console.error(e); + } + } await this.evictOldestIfNecessary(); }); From af82be13f9b9a27578c7506c98ef71ccbd84a65c Mon Sep 17 00:00:00 2001 From: Hellyson Rodrigo Parteka Date: Fri, 3 Dec 2021 01:01:35 -0300 Subject: [PATCH 07/30] fix(file-cache): add queue to handle eviction of old files This commit also removes the `await` from every stream creation. The eviction will be handled totally assyncronously. The only drawback is the possibility of exceeding the cache limit for a moment, until the next execution of `evictOldest`. This will only be a problem if the cache is set too close to the remaining disk space, which I wouldn't recomend. I also removed the recursion. --- src/services/file-cache.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index ddbe190..826c26d 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -5,9 +5,11 @@ import sequelize from 'sequelize'; import {FileCache} from '../models/index.js'; import {TYPES} from '../types.js'; import Config from './config.js'; +import PQueue from 'p-queue'; @injectable() export default class FileCacheProvider { + private static readonly evictionQueue = new PQueue({concurrency: 1}); private readonly config: Config; constructor(@inject(TYPES.Config) config: Config) { @@ -67,7 +69,7 @@ export default class FileCacheProvider { } } - await this.evictOldestIfNecessary(); + this.evictOldestIfNecessary(); }); return stream; @@ -80,10 +82,16 @@ export default class FileCacheProvider { */ async cleanup() { await this.removeOrphans(); - await this.evictOldestIfNecessary(); + this.evictOldestIfNecessary(); } - private async evictOldestIfNecessary() { + private evictOldestIfNecessary() { + if (FileCacheProvider.evictionQueue.size === 0 && FileCacheProvider.evictionQueue.pending === 0) { + void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); + } + } + + private async evictOldest() { const [{dataValues: {totalSizeBytes}}] = await FileCache.findAll({ attributes: [ [sequelize.fn('sum', sequelize.col('bytes')), 'totalSizeBytes'], @@ -103,7 +111,7 @@ export default class FileCacheProvider { } // Continue to evict until we're under the limit - await this.evictOldestIfNecessary(); + void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); } } From b52f9253c2a905642a01e510bc91dadeb0db419a Mon Sep 17 00:00:00 2001 From: Hellyson Rodrigo Parteka Date: Fri, 3 Dec 2021 03:26:36 -0300 Subject: [PATCH 08/30] add some debug logs --- src/services/file-cache.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index 826c26d..1df8d71 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -6,6 +6,7 @@ import {FileCache} from '../models/index.js'; import {TYPES} from '../types.js'; import Config from './config.js'; import PQueue from 'p-queue'; +import debug from '../utils/debug.js'; @injectable() export default class FileCacheProvider { @@ -65,7 +66,7 @@ export default class FileCacheProvider { await FileCache.create({hash, bytes: stats.size, accessedAt: new Date()}); } catch (e: unknown) { - console.error(e); + debug(`Caught error trying to move a finished cache file: ${String(e)}`); } } @@ -87,11 +88,13 @@ export default class FileCacheProvider { private evictOldestIfNecessary() { if (FileCacheProvider.evictionQueue.size === 0 && FileCacheProvider.evictionQueue.pending === 0) { + debug('Adding evictOldest task to queue'); void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); } } private async evictOldest() { + debug('Evicting oldest (if found)'); const [{dataValues: {totalSizeBytes}}] = await FileCache.findAll({ attributes: [ [sequelize.fn('sum', sequelize.col('bytes')), 'totalSizeBytes'], @@ -111,8 +114,11 @@ export default class FileCacheProvider { } // Continue to evict until we're under the limit + debug('Scheduling another eviction'); void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); } + + debug('Finished evictOldest'); } private async removeOrphans() { From 70a55e9a2e8df91d2e4dc0792a17d9b48f6f20d0 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 3 Dec 2021 10:36:06 -0500 Subject: [PATCH 09/30] Disable @typescript-eslint/no-implicit-any-catch (Strict mode in TS 4.4 enables useUnknownInCatchVariables, so this is redundant.) --- package.json | 3 ++- src/services/file-cache.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 79235d3..beedf29 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,8 @@ "new-cap": "off", "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-unused-vars-experimental": "error", - "@typescript-eslint/prefer-readonly-parameter-types": "off" + "@typescript-eslint/prefer-readonly-parameter-types": "off", + "@typescript-eslint/no-implicit-any-catch": "off" } }, "husky": { diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index 1df8d71..b99c8c6 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -65,8 +65,8 @@ export default class FileCacheProvider { await fs.rename(tmpPath, finalPath); await FileCache.create({hash, bytes: stats.size, accessedAt: new Date()}); - } catch (e: unknown) { - debug(`Caught error trying to move a finished cache file: ${String(e)}`); + } catch (error) { + debug('Errored when moving a finished cache file:', error); } } From 3f0f97f762d0cf5c9be6dbc34b0bc081307058ef Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 3 Dec 2021 10:45:09 -0500 Subject: [PATCH 10/30] Return when queue is empty --- src/services/file-cache.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index b99c8c6..e82b705 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -10,7 +10,7 @@ import debug from '../utils/debug.js'; @injectable() export default class FileCacheProvider { - private static readonly evictionQueue = new PQueue({concurrency: 1}); + private readonly evictionQueue = new PQueue({concurrency: 1}); private readonly config: Config; constructor(@inject(TYPES.Config) config: Config) { @@ -70,7 +70,7 @@ export default class FileCacheProvider { } } - this.evictOldestIfNecessary(); + await this.evictOldestIfNecessary(); }); return stream; @@ -83,14 +83,16 @@ export default class FileCacheProvider { */ async cleanup() { await this.removeOrphans(); - this.evictOldestIfNecessary(); + await this.evictOldestIfNecessary(); } - private evictOldestIfNecessary() { - if (FileCacheProvider.evictionQueue.size === 0 && FileCacheProvider.evictionQueue.pending === 0) { + private async evictOldestIfNecessary() { + if (this.evictionQueue.size === 0 && this.evictionQueue.pending === 0) { debug('Adding evictOldest task to queue'); - void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); + void this.evictionQueue.add(this.evictOldest.bind(this)); } + + return this.evictionQueue.onEmpty(); } private async evictOldest() { @@ -115,7 +117,7 @@ export default class FileCacheProvider { // Continue to evict until we're under the limit debug('Scheduling another eviction'); - void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); + void this.evictionQueue.add(this.evictOldest.bind(this)); } debug('Finished evictOldest'); From 4ffd679ddb227ea6e6ac911de382e4d5bec0926d Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 3 Dec 2021 10:52:30 -0500 Subject: [PATCH 11/30] Update debug logging --- src/services/file-cache.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index e82b705..7e7aa6d 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -87,16 +87,13 @@ export default class FileCacheProvider { } private async evictOldestIfNecessary() { - if (this.evictionQueue.size === 0 && this.evictionQueue.pending === 0) { - debug('Adding evictOldest task to queue'); - void this.evictionQueue.add(this.evictOldest.bind(this)); - } + void this.evictionQueue.add(this.evictOldest.bind(this)); return this.evictionQueue.onEmpty(); } private async evictOldest() { - debug('Evicting oldest (if found)'); + debug('Evicting oldest files...'); const [{dataValues: {totalSizeBytes}}] = await FileCache.findAll({ attributes: [ [sequelize.fn('sum', sequelize.col('bytes')), 'totalSizeBytes'], @@ -113,14 +110,14 @@ export default class FileCacheProvider { if (oldest) { await oldest.destroy(); await fs.unlink(path.join(this.config.CACHE_DIR, oldest.hash)); + debug(`${oldest.hash} has been evicted`); } // Continue to evict until we're under the limit - debug('Scheduling another eviction'); void this.evictionQueue.add(this.evictOldest.bind(this)); + } else { + debug(`No files needed to be evicted. Total size of the cache is currently ${totalSizeBytes} bytes, and the cache limit is ${this.config.CACHE_LIMIT_IN_BYTES} bytes.`); } - - debug('Finished evictOldest'); } private async removeOrphans() { From 7ff54b9495545cd23fa87ac13bd654a78c29aa1d Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 3 Dec 2021 11:06:56 -0500 Subject: [PATCH 12/30] Use loop instead of recursion --- src/services/file-cache.ts | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index 7e7aa6d..ac8c815 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -94,13 +94,12 @@ export default class FileCacheProvider { private async evictOldest() { debug('Evicting oldest files...'); - const [{dataValues: {totalSizeBytes}}] = await FileCache.findAll({ - attributes: [ - [sequelize.fn('sum', sequelize.col('bytes')), 'totalSizeBytes'], - ], - }) as unknown as [{dataValues: {totalSizeBytes: number}}]; - if (totalSizeBytes > this.config.CACHE_LIMIT_IN_BYTES) { + let totalSizeBytes = await this.getDiskUsageInBytes(); + let numOfEvictedFiles = 0; + // Continue to evict until we're under the limit + /* eslint-disable no-await-in-loop */ + while (totalSizeBytes > this.config.CACHE_LIMIT_IN_BYTES) { const oldest = await FileCache.findOne({ order: [ ['accessedAt', 'ASC'], @@ -111,10 +110,15 @@ export default class FileCacheProvider { await oldest.destroy(); await fs.unlink(path.join(this.config.CACHE_DIR, oldest.hash)); debug(`${oldest.hash} has been evicted`); + numOfEvictedFiles++; } - // Continue to evict until we're under the limit - void this.evictionQueue.add(this.evictOldest.bind(this)); + totalSizeBytes = await this.getDiskUsageInBytes(); + } + /* eslint-enable no-await-in-loop */ + + if (numOfEvictedFiles > 0) { + debug(`${numOfEvictedFiles} files have been evicted`); } else { debug(`No files needed to be evicted. Total size of the cache is currently ${totalSizeBytes} bytes, and the cache limit is ${this.config.CACHE_LIMIT_IN_BYTES} bytes.`); } @@ -131,4 +135,19 @@ export default class FileCacheProvider { } } } + + /** + * Pulls from the database rather than the filesystem, + * so may be slightly inaccurate. + * @returns the total size of the cache in bytes + */ + private async getDiskUsageInBytes() { + const [{dataValues: {totalSizeBytes}}] = await FileCache.findAll({ + attributes: [ + [sequelize.fn('sum', sequelize.col('bytes')), 'totalSizeBytes'], + ], + }) as unknown as [{dataValues: {totalSizeBytes: number}}]; + + return totalSizeBytes; + } } From 29ec1d0092425c1c3822518b12d62bd4b562704e Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 3 Dec 2021 11:28:50 -0500 Subject: [PATCH 13/30] Revert back to static property --- src/services/file-cache.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index ac8c815..64dcfe1 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -10,7 +10,7 @@ import debug from '../utils/debug.js'; @injectable() export default class FileCacheProvider { - private readonly evictionQueue = new PQueue({concurrency: 1}); + private static readonly evictionQueue = new PQueue({concurrency: 1}); private readonly config: Config; constructor(@inject(TYPES.Config) config: Config) { @@ -87,9 +87,9 @@ export default class FileCacheProvider { } private async evictOldestIfNecessary() { - void this.evictionQueue.add(this.evictOldest.bind(this)); + void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); - return this.evictionQueue.onEmpty(); + return FileCacheProvider.evictionQueue.onEmpty(); } private async evictOldest() { From 0396949b39213104054008ccc4b26c6d5b1dd3e3 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Tue, 7 Dec 2021 20:36:06 -0500 Subject: [PATCH 14/30] Check database direction for orphans --- src/services/file-cache.ts | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index 64dcfe1..1ffb824 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -125,15 +125,29 @@ export default class FileCacheProvider { } private async removeOrphans() { + // Check filesystem direction (do files exist on the disk but not in the database?) for await (const dirent of await fs.opendir(this.config.CACHE_DIR)) { if (dirent.isFile()) { const model = await FileCache.findByPk(dirent.name); if (!model) { + debug(`${dirent.name} was present on disk but was not in the database. Removing from disk.`); await fs.unlink(path.join(this.config.CACHE_DIR, dirent.name)); } } } + + // Check database direction (do entries exist in the database but not on the disk?) + for await (const model of this.getFindAllIterable()) { + const filePath = path.join(this.config.CACHE_DIR, model.hash); + + try { + await fs.access(filePath); + } catch { + debug(`${model.hash} was present in database but was not on disk. Removing from database.`); + await model.destroy(); + } + } } /** @@ -150,4 +164,56 @@ export default class FileCacheProvider { return totalSizeBytes; } + + /** + * An efficient way to iterate over all rows. + * @returns an iterable for the result of FileCache.findAll() + */ + private getFindAllIterable() { + const limit = 50; + let previousCreatedAt: Date | null = null; + + let models: FileCache[] = []; + + const fetchNextBatch = async () => { + let where = {}; + + if (previousCreatedAt) { + where = { + createdAt: { + [sequelize.Op.gt]: previousCreatedAt, + }, + }; + } + + models = await FileCache.findAll({ + where, + limit, + order: ['createdAt'], + }); + + if (models.length > 0) { + previousCreatedAt = models[models.length - 1].createdAt as Date; + } + }; + + return { + [Symbol.asyncIterator]() { + return { + async next() { + if (models.length === 0) { + await fetchNextBatch(); + } + + if (models.length === 0) { + // Must return value here for types to be inferred correctly + return {done: true, value: null as unknown as FileCache}; + } + + return {value: models.shift()!, done: false}; + }, + }; + }, + }; + } } From d5b8cc82b75ef86895e0bf80f30a854a6e5ae367 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Dec 2021 10:03:20 +0000 Subject: [PATCH 15/30] Bump typescript from 4.4.4 to 4.5.3 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.4.4 to 4.5.3. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/commits) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 79235d3..0f6bf20 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "nodemon": "^2.0.7", "ts-node": "^10.4.0", "type-fest": "^2.5.4", - "typescript": "^4.4.3" + "typescript": "^4.5.3" }, "eslintConfig": { "extends": [ diff --git a/yarn.lock b/yarn.lock index 93c2cd2..a04ca6c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3280,10 +3280,10 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@>=4.3, typescript@^4.4.3: - version "4.4.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" - integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== +typescript@>=4.3, typescript@^4.5.3: + version "4.5.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.3.tgz#afaa858e68c7103317d89eb90c5d8906268d353c" + integrity sha512-eVYaEHALSt+s9LbvgEv4Ef+Tdq7hBiIZgii12xXJnukryt3pMgJf6aKhoCZ3FWQsu6sydEnkg11fYXLzhLBjeQ== undefsafe@^2.0.5: version "2.0.5" From e4a8dde7762101d0bfe965f1ddc04ffdcd74574d Mon Sep 17 00:00:00 2001 From: Max Isom Date: Sun, 12 Dec 2021 13:20:36 -0500 Subject: [PATCH 16/30] Always resume --- src/commands/play.ts | 37 ++++++++++++++++++++++--------------- src/services/player.ts | 4 ++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/commands/play.ts b/src/commands/play.ts index 8fb5775..856edec 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -46,7 +46,6 @@ export default class implements Command { const player = this.playerManager.get(msg.guild!.id); - const queueOldSize = player.queueSize(); const wasPlayingSong = player.getCurrent() !== null; if (args.length === 0) { @@ -147,6 +146,28 @@ export default class implements Command { const firstSong = newSongs[0]; + let statusMsg = ''; + + if (player.voiceConnection === null) { + await player.connect(targetVoiceChannel); + + // Resume / start playback + await player.play(); + + if (wasPlayingSong) { + statusMsg = 'resuming playback'; + } + } + + // Build response message + if (statusMsg !== '') { + if (extraMsg === '') { + extraMsg = statusMsg; + } else { + extraMsg = `${statusMsg}, ${extraMsg}`; + } + } + if (extraMsg !== '') { extraMsg = ` (${extraMsg})`; } @@ -156,19 +177,5 @@ export default class implements Command { } else { await res.stop(`u betcha, **${firstSong.title}** and ${newSongs.length - 1} other songs were added to the queue${extraMsg}`); } - - if (player.voiceConnection === null) { - await player.connect(targetVoiceChannel); - - if (player.status === STATUS.PAUSED && queueOldSize) { - // Resume playing from queue after being paused - await player.play(); - } - } - - if (queueOldSize === 0 && !wasPlayingSong) { - // Only auto-play if queue was empty before and nothing was playing - await player.play(); - } } } diff --git a/src/services/player.ts b/src/services/player.ts index 67b8b38..4a226c5 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -235,6 +235,10 @@ export default class { return null; } + /** + * Returns queue, not including the current song. + * @returns {QueuedSong[]} + */ getQueue(): QueuedSong[] { return this.queue.slice(this.queuePosition + 1); } From f35f1de7b881d4443e81d7b70d812ec06d8ce9c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 12 Dec 2021 18:42:09 +0000 Subject: [PATCH 17/30] Bump got from 11.8.2 to 12.0.0 Bumps [got](https://github.com/sindresorhus/got) from 11.8.2 to 12.0.0. - [Release notes](https://github.com/sindresorhus/got/releases) - [Commits](https://github.com/sindresorhus/got/compare/v11.8.2...v12.0.0) --- updated-dependencies: - dependency-name: got dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 87 +++++++++++++++++++++++++++++++--------------------- 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index ea702a7..f9db322 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "fluent-ffmpeg": "^2.1.2", "fs-capacitor": "^7.0.1", "get-youtube-id": "^1.0.1", - "got": "^11.8.2", + "got": "^12.0.0", "hasha": "^5.2.2", "inversify": "^6.0.1", "iso8601-duration": "^1.3.0", diff --git a/yarn.lock b/yarn.lock index 26c7c6d..36eaece 100644 --- a/yarn.lock +++ b/yarn.lock @@ -162,7 +162,7 @@ resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea" integrity sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ== -"@sindresorhus/is@^4.0.0", "@sindresorhus/is@^4.0.1", "@sindresorhus/is@^4.2.0": +"@sindresorhus/is@^4.0.1", "@sindresorhus/is@^4.2.0": version "4.2.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.2.0.tgz#667bfc6186ae7c9e0b45a08960c551437176e1ca" integrity sha512-VkE3KLBmJwcCaVARtQpfuKcKv8gcBmUubrfHGF84dXuuW6jgsRYxPtzcIhPyK9WAPpRt2/xY6zkD9MnRaJzSyw== @@ -174,12 +174,12 @@ dependencies: defer-to-connect "^1.0.1" -"@szmarczak/http-timer@^4.0.5": - version "4.0.6" - resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-4.0.6.tgz#b4a914bb62e7c272d4e5989fe4440f812ab1d807" - integrity sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w== +"@szmarczak/http-timer@^5.0.1": + version "5.0.1" + resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-5.0.1.tgz#c7c1bf1141cdd4751b0399c8fc7b8b664cd5be3a" + integrity sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw== dependencies: - defer-to-connect "^2.0.0" + defer-to-connect "^2.0.1" "@tsconfig/node10@^1.0.7": version "1.0.8" @@ -206,7 +206,7 @@ resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.36.tgz#00d9301d4dc35c2f6465a8aec634bb533674c652" integrity sha512-HBNx4lhkxN7bx6P0++W8E289foSu8kO8GCk2unhuVggO+cE7rh9DhZUyPhUxNRG9m+5B5BTKxZQ5ZP92x/mx9Q== -"@types/cacheable-request@^6.0.1": +"@types/cacheable-request@^6.0.2": version "6.0.2" resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.2.tgz#c324da0197de0a98a2312156536ae262429ff6b9" integrity sha512-B3xVo+dlKM6nnKTcmm5ZtY/OL8bOAOd2Olee9M1zft65ox50OzjEHW91sDiU9j6cvW8Ejg1/Qkf4xd2kugApUA== @@ -639,10 +639,10 @@ braces@^3.0.1, braces@~3.0.2: dependencies: fill-range "^7.0.1" -cacheable-lookup@^5.0.3: - version "5.0.4" - resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz#5a6b865b2c44357be3d5ebc2a467b032719a7005" - integrity sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA== +cacheable-lookup@^6.0.4: + version "6.0.4" + resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-6.0.4.tgz#65c0e51721bb7f9f2cb513aed6da4a1b93ad7dc8" + integrity sha512-mbcDEZCkv2CZF4G01kr8eBd/5agkt9oCqz75tJMSIsquvRZ2sL6Hi5zGVKi/0OSC9oO1GHfJ2AV0ZIOY9vye0A== cacheable-request@^6.0.0: version "6.1.0" @@ -657,7 +657,7 @@ cacheable-request@^6.0.0: normalize-url "^4.1.0" responselike "^1.0.2" -cacheable-request@^7.0.1: +cacheable-request@^7.0.2: version "7.0.2" resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-7.0.2.tgz#ea0d0b889364a25854757301ca12b2da77f91d27" integrity sha512-pouW8/FmiPQbuGpkXQ9BAPv/Mo5xDGANgSNXzTzJ8DrKGuXOssM4wIQRjfanNRh3Yu5cfYPvcorqbhg2KIJtew== @@ -960,7 +960,7 @@ defer-to-connect@^1.0.1: resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-1.1.3.tgz#331ae050c08dcf789f8c83a7b81f0ed94f4ac591" integrity sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ== -defer-to-connect@^2.0.0: +defer-to-connect@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-2.0.1.tgz#8016bdb4143e4632b77a3449c6236277de520587" integrity sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg== @@ -1362,6 +1362,11 @@ forever-agent@~0.6.1: resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE= +form-data-encoder@1.7.1: + version "1.7.1" + resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-1.7.1.tgz#ac80660e4f87ee0d3d3c3638b7da8278ddb8ec96" + integrity sha512-EFRDrsMm/kyqbTQocNvRXMLjc7Es2Vk+IQFx/YW7hkUH1eBl4J1fqiP34l74Yt0pFLCNpc06fkbVk00008mzjg== + form-data@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f" @@ -1491,6 +1496,11 @@ get-stream@^5.1.0: dependencies: pump "^3.0.0" +get-stream@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" + integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== + get-youtube-id@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/get-youtube-id/-/get-youtube-id-1.0.1.tgz#adb6f475e292d98f98ed5bfb530887656193e157" @@ -1548,21 +1558,23 @@ globby@^11.0.3: merge2 "^1.3.0" slash "^3.0.0" -got@^11.8.2: - version "11.8.2" - resolved "https://registry.yarnpkg.com/got/-/got-11.8.2.tgz#7abb3959ea28c31f3576f1576c1effce23f33599" - integrity sha512-D0QywKgIe30ODs+fm8wMZiAcZjypcCodPNuMz5H9Mny7RJ+IjJ10BdmGW7OM7fHXP+O7r6ZwapQ/YQmMSvB0UQ== +got@^12.0.0: + version "12.0.0" + resolved "https://registry.yarnpkg.com/got/-/got-12.0.0.tgz#2ee3d5ff25eabc47dae975d376ddcee1d450bec1" + integrity sha512-gNNNghQ1yw0hyzie1FLK6gY90BQlXU9zSByyRygnbomHPruKQ6hAKKbpO1RfNZp8b+qNzNipGeRG3tUelKcVsA== dependencies: - "@sindresorhus/is" "^4.0.0" - "@szmarczak/http-timer" "^4.0.5" - "@types/cacheable-request" "^6.0.1" + "@sindresorhus/is" "^4.2.0" + "@szmarczak/http-timer" "^5.0.1" + "@types/cacheable-request" "^6.0.2" "@types/responselike" "^1.0.0" - cacheable-lookup "^5.0.3" - cacheable-request "^7.0.1" + cacheable-lookup "^6.0.4" + cacheable-request "^7.0.2" decompress-response "^6.0.0" - http2-wrapper "^1.0.0-beta.5.2" - lowercase-keys "^2.0.0" - p-cancelable "^2.0.0" + form-data-encoder "1.7.1" + get-stream "^6.0.1" + http2-wrapper "^2.1.9" + lowercase-keys "^3.0.0" + p-cancelable "^3.0.0" responselike "^2.0.0" got@^9.6.0: @@ -1654,13 +1666,13 @@ http-signature@~1.2.0: jsprim "^1.2.2" sshpk "^1.7.0" -http2-wrapper@^1.0.0-beta.5.2: - version "1.0.3" - resolved "https://registry.yarnpkg.com/http2-wrapper/-/http2-wrapper-1.0.3.tgz#b8f55e0c1f25d4ebd08b3b0c2c079f9590800b3d" - integrity sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg== +http2-wrapper@^2.1.9: + version "2.1.9" + resolved "https://registry.yarnpkg.com/http2-wrapper/-/http2-wrapper-2.1.9.tgz#d27b9475f132973a74b4ee50901b951ff6e56020" + integrity sha512-z5jPLkDXHsQM762XFo4XproHTXT0lMQscKCQMPGccHDzY0kNxmUxWyGkW66zB2RGAr9pF9Tzc5Dmmv8Uh8HW3Q== dependencies: quick-lru "^5.1.1" - resolve-alpn "^1.0.0" + resolve-alpn "^1.2.0" https-proxy-agent@^5.0.0: version "5.0.0" @@ -2028,6 +2040,11 @@ lowercase-keys@^2.0.0: resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479" integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA== +lowercase-keys@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-3.0.0.tgz#c5e7d442e37ead247ae9db117a9d0a467c89d4f2" + integrity sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ== + lru-cache@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" @@ -2438,10 +2455,10 @@ p-cancelable@^1.0.0: resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-1.1.0.tgz#d078d15a3af409220c886f1d9a0ca2e441ab26cc" integrity sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw== -p-cancelable@^2.0.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-2.1.1.tgz#aab7fbd416582fa32a3db49859c122487c5ed2cf" - integrity sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg== +p-cancelable@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-3.0.0.tgz#63826694b54d61ca1c20ebcb6d3ecf5e14cd8050" + integrity sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw== p-event@^4.2.0: version "4.2.0" @@ -2748,7 +2765,7 @@ require-from-string@^2.0.2: resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909" integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw== -resolve-alpn@^1.0.0: +resolve-alpn@^1.2.0: version "1.2.1" resolved "https://registry.yarnpkg.com/resolve-alpn/-/resolve-alpn-1.2.1.tgz#b7adbdac3546aaaec20b45e7d8265927072726f9" integrity sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g== From ffc8493ea3816402f142794cc7904244e9f6e2ac Mon Sep 17 00:00:00 2001 From: Max Isom Date: Mon, 13 Dec 2021 20:11:14 -0500 Subject: [PATCH 18/30] Add splash banner and spinner progress for initial connection --- package.json | 8 +-- src/bot.ts | 8 ++- src/index.ts | 13 +++++ tsconfig.json | 3 +- yarn.lock | 146 ++++++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 169 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 931c92f..eb7ddb4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "muse", "version": "0.1.0", "description": "🎧 a self-hosted Discord music bot that doesn't suck ", - "exports": "./dist/index.js", + "exports": "./dist/src/index.js", "repository": "git@github.com:codetheweb/muse.git", "author": "Max Isom ", "license": "MIT", @@ -22,9 +22,9 @@ "clean": "rm -rf dist dts", "test": "npm run lint", "build": "tsc", - "watch": "tsc --watch", + "build:watch": "tsc --watch", "prepack": "npm run clean && npm run build", - "start": "node dist/index.js", + "start": "node --experimental-json-modules dist/src/index.js", "dev": "concurrently nodemon 'tsc --watch'", "docker-publish": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t codetheweb/muse:latest --push ." }, @@ -90,6 +90,8 @@ "libsodium-wrappers": "^0.7.9", "make-dir": "^3.1.0", "node-emoji": "^1.10.0", + "nodesplash": "^0.1.1", + "ora": "^6.0.1", "p-event": "^4.2.0", "p-limit": "^4.0.0", "p-queue": "^7.1.0", diff --git a/src/bot.ts b/src/bot.ts index b49c1f6..5260ae0 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,5 +1,6 @@ import {Client, Message, Collection} from 'discord.js'; import {inject, injectable} from 'inversify'; +import ora from 'ora'; import {TYPES} from './types.js'; import {Settings, Shortcut} from './models/index.js'; import container from './inversify.config.js'; @@ -96,9 +97,12 @@ export default class { } }); - this.client.on('ready', async () => { + const spinner = ora('📡 connecting to Discord...').start(); + + this.client.on('ready', () => { debug(generateDependencyReport()); - console.log(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.client.user?.id ?? ''}&scope=bot&permissions=36752448`); + + spinner.succeed(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.client.user?.id ?? ''}&scope=bot&permissions=36752448`); }); this.client.on('error', console.error); diff --git a/src/index.ts b/src/index.ts index 383faef..a6b6d35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,28 @@ import makeDir from 'make-dir'; import path from 'path'; +import {makeLines} from 'nodesplash'; import container from './inversify.config.js'; import {TYPES} from './types.js'; import Bot from './bot.js'; import {sequelize} from './utils/db.js'; import Config from './services/config.js'; import FileCacheProvider from './services/file-cache.js'; +import metadata from '../package.json'; const bot = container.get(TYPES.Bot); (async () => { + // Banner + console.log(makeLines({ + user: 'codetheweb', + repository: 'muse', + version: metadata.version, + paypalUser: 'codetheweb', + githubSponsor: 'codetheweb', + madeByPrefix: 'Made with 🎶 by ', + }).join('\n')); + console.log('\n'); + // Create data directories if necessary const config = container.get(TYPES.Config); diff --git a/tsconfig.json b/tsconfig.json index d424d91..c5bf780 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,8 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, "esModuleInterop": true, - "sourceMap": true + "sourceMap": true, + "resolveJsonModule": true }, "include": ["src"], "exclude": ["node_modules"] diff --git a/yarn.lock b/yarn.lock index daceee5..36aaa6c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -467,6 +467,11 @@ ansi-regex@^5.0.1: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== +ansi-regex@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.0.1.tgz#3183e38fae9a65d7cb5e53945cd5897d0260a06a" + integrity sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA== + ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" @@ -591,6 +596,11 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +base64-js@^1.3.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" + integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== + bcrypt-pbkdf@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e" @@ -603,6 +613,15 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== +bl@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/bl/-/bl-5.0.0.tgz#6928804a41e9da9034868e1c50ca88f21f57aea2" + integrity sha512-8vxFNZ0pflFfi0WXA3WQXlj6CaMEwsmh63I1CNp0q+wWv8sD0ARx1KovSQd0l2GkwrMIOyedq0EF1FxI+RCZLQ== + dependencies: + buffer "^6.0.3" + inherits "^2.0.4" + readable-stream "^3.4.0" + block-stream@*: version "0.0.9" resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a" @@ -639,6 +658,14 @@ braces@^3.0.1, braces@~3.0.2: dependencies: fill-range "^7.0.1" +buffer@^6.0.3: + version "6.0.3" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" + integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== + dependencies: + base64-js "^1.3.1" + ieee754 "^1.2.1" + cacheable-lookup@^6.0.4: version "6.0.4" resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-6.0.4.tgz#65c0e51721bb7f9f2cb513aed6da4a1b93ad7dc8" @@ -702,7 +729,7 @@ chalk@^2.0.0: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -chalk@^4.0.0, chalk@^4.1.0: +chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -710,6 +737,11 @@ chalk@^4.0.0, chalk@^4.1.0: ansi-styles "^4.1.0" supports-color "^7.1.0" +chalk@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.0.0.tgz#bd96c6bb8e02b96e08c0c3ee2a9d90e050c7b832" + integrity sha512-/duVOqst+luxCQRKEo4bNxinsOQtMP80ZYm7mMqzuh5PociNL0PvmHFvREJ9ueYL2TxlHjBcmLCdmocx9Vg+IQ== + chokidar@^3.5.2: version "3.5.2" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75" @@ -745,6 +777,18 @@ cli-boxes@^2.2.1: resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.1.tgz#ddd5035d25094fce220e9cab40a45840a440318f" integrity sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw== +cli-cursor@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-4.0.0.tgz#3cecfe3734bf4fe02a8361cbdc0f6fe28c6a57ea" + integrity sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg== + dependencies: + restore-cursor "^4.0.0" + +cli-spinners@^2.6.0: + version "2.6.1" + resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.6.1.tgz#adc954ebe281c37a6319bfa401e6dd2488ffb70d" + integrity sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g== + cliui@^7.0.2: version "7.0.4" resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f" @@ -761,6 +805,11 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" +clone@^1.0.2: + version "1.0.4" + resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" + integrity sha1-2jCcwmPfFZlMaIypAheco8fNfH4= + code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" @@ -955,6 +1004,13 @@ deep-is@^0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831" integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ== +defaults@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d" + integrity sha1-xlYFHpgX2f8I7YgUd/P+QBnz730= + dependencies: + clone "^1.0.2" + defer-to-connect@^1.0.1: version "1.1.3" resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-1.1.3.tgz#331ae050c08dcf789f8c83a7b81f0ed94f4ac591" @@ -1599,6 +1655,11 @@ graceful-fs@^4.1.2: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a" integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg== +grapheme-splitter@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz#9cf3a665c6247479896834af35cf1dbb4400767e" + integrity sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ== + har-schema@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92" @@ -1705,6 +1766,11 @@ iconv-lite@^0.4.4: dependencies: safer-buffer ">= 2.1.2 < 3" +ieee754@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" + integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== + ignore-by-default@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/ignore-by-default/-/ignore-by-default-1.0.1.tgz#48ca6d72f6c6a3af00a9ad4ae6876be3889e2b09" @@ -1758,7 +1824,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.3: +inherits@2, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.0, inherits@~2.0.3: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -1834,6 +1900,11 @@ is-installed-globally@^0.4.0: global-dirs "^3.0.0" is-path-inside "^3.0.2" +is-interactive@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-interactive/-/is-interactive-2.0.0.tgz#40c57614593826da1100ade6059778d597f16e90" + integrity sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ== + is-npm@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/is-npm/-/is-npm-5.0.0.tgz#43e8d65cc56e1b67f8d47262cf667099193f45a8" @@ -1864,6 +1935,11 @@ is-typedarray@^1.0.0, is-typedarray@~1.0.0: resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo= +is-unicode-supported@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-1.1.0.tgz#9127b71f9fa82f52ca5c20e982e7bec0ee31ee1e" + integrity sha512-lDcxivp8TJpLG75/DpatAqNzOpDPSpED8XNtrpBHTdQ2InQ1PbW78jhwSxyxhhu+xbVSast2X38bwj8atwoUQA== + is-yarn-global@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/is-yarn-global/-/is-yarn-global-0.3.0.tgz#d502d3382590ea3004893746754c89139973e232" @@ -2030,6 +2106,14 @@ lodash@^4.17.20, lodash@^4.17.21: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== +log-symbols@^5.0.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-5.1.0.tgz#a20e3b9a5f53fac6aeb8e2bb22c07cf2c8f16d93" + integrity sha512-l0x2DvrW294C9uDCoQe1VSU4gf529FkSZ6leBl4TiqZH/e+0R7hSfHQBNut2mNygDgHwvYHfFLn6Oxb3VWj2rA== + dependencies: + chalk "^5.0.0" + is-unicode-supported "^1.1.0" + lowercase-keys@^1.0.0, lowercase-keys@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f" @@ -2107,6 +2191,11 @@ mime@^2.4.6: resolved "https://registry.yarnpkg.com/mime/-/mime-2.6.0.tgz#a2a682a95cd4d0cb1d6257e28f83da7e35800367" integrity sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg== +mimic-fn@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" + integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== + mimic-response@^1.0.0, mimic-response@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b" @@ -2291,6 +2380,13 @@ nodemon@^2.0.7: undefsafe "^2.0.5" update-notifier "^5.1.0" +nodesplash@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/nodesplash/-/nodesplash-0.1.1.tgz#b3f876e7be6366f2fffb814d02de6baf2db1158a" + integrity sha512-V5yqmtR9ovc0PAUVIisaV0H1WL7tgZOVuiniJaDNP/DZHYybwaPw5wm6Jkx/0M0j13JcDW1NsAxxuv2DtngCPQ== + dependencies: + grapheme-splitter "^1.0.4" + "nopt@2 || 3": version "3.0.6" resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9" @@ -2403,6 +2499,13 @@ once@^1.3.0, once@^1.3.1, once@^1.4.0: dependencies: wrappy "1" +onetime@^5.1.0: + version "5.1.2" + resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e" + integrity sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg== + dependencies: + mimic-fn "^2.1.0" + opencollective-postinstall@^2.0.2: version "2.0.3" resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259" @@ -2420,6 +2523,21 @@ optionator@^0.9.1: type-check "^0.4.0" word-wrap "^1.2.3" +ora@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/ora/-/ora-6.0.1.tgz#68caa9fd6c485a40d6f46c50a3940fa3df99c7f3" + integrity sha512-TDdKkKHdWE6jo/6pIa5U5AWcSVfpNRFJ8sdRJpioGNVPLAzZzHs/N+QhUfF7ZbyoC+rnDuNTKzeDJUbAza9g4g== + dependencies: + bl "^5.0.0" + chalk "^4.1.2" + cli-cursor "^4.0.0" + cli-spinners "^2.6.0" + is-interactive "^2.0.0" + is-unicode-supported "^1.1.0" + log-symbols "^5.0.0" + strip-ansi "^7.0.1" + wcwidth "^1.0.1" + os-homedir@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" @@ -2689,7 +2807,7 @@ readable-stream@^2.0.6: string_decoder "~1.1.1" util-deprecate "~1.0.1" -readable-stream@^3.6.0: +readable-stream@^3.4.0, readable-stream@^3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== @@ -2789,6 +2907,14 @@ responselike@^2.0.0: dependencies: lowercase-keys "^2.0.0" +restore-cursor@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-4.0.0.tgz#519560a4318975096def6e609d44100edaa4ccb9" + integrity sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg== + dependencies: + onetime "^5.1.0" + signal-exit "^3.0.2" + retry-as-promised@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/retry-as-promised/-/retry-as-promised-3.2.0.tgz#769f63d536bec4783549db0777cb56dadd9d8543" @@ -3073,6 +3199,13 @@ strip-ansi@^6.0.0, strip-ansi@^6.0.1: dependencies: ansi-regex "^5.0.1" +strip-ansi@^7.0.1: + version "7.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.0.1.tgz#61740a08ce36b61e50e65653f07060d000975fb2" + integrity sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw== + dependencies: + ansi-regex "^6.0.1" + strip-json-comments@^3.1.0, strip-json-comments@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" @@ -3394,6 +3527,13 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" +wcwidth@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8" + integrity sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g= + dependencies: + defaults "^1.0.3" + webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" From 761ac9f7ed3d446c5a3384a8c2608e82be9cdd34 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Mon, 13 Dec 2021 20:25:32 -0500 Subject: [PATCH 19/30] Add PR workflow --- .github/workflows/build.yml | 5 ++- .github/workflows/pr.yml | 70 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4663dc..75f5729 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,9 @@ name: Lint & build -on: [pull_request] +on: + push: + branches: + - main jobs: build: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..fbbc47f --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,70 @@ +name: PR Workflow + +on: + pull_request: + types: [opened, synchronize, ready_for_review, edited, closed] + branches: + - main + +jobs: + build: + name: Build & lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v2 + with: + node-version: '16' + + - name: Install dependencies + uses: bahmutov/npm-install@v1 + + - name: Run lint + run: yarn lint + + - name: Build + run: yarn build + + release: + name: Release snapshot + runs-on: ubuntu-latest + steps: + - name: Set up Buildx + uses: docker/setup-buildx-action@v1 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: codetheweb/muse:${{ github.event.pull_request.head.sha }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max + + - name: Create comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: "pr-release" + message: | + #### :package: A new release has been made for this pull request + + To play around with this PR, pull `codetheweb/muse:${{ github.event.pull_request.head.sha }}`. + + > Latest commit: ${{ github.event.pull_request.head.sha }} From f91d69492fcefb195ed661912e95e14f48126266 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Mon, 13 Dec 2021 20:28:56 -0500 Subject: [PATCH 20/30] Fix branch name --- .github/workflows/build.yml | 2 +- .github/workflows/pr.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 75f5729..f181dc0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,7 @@ name: Lint & build on: push: branches: - - main + - master jobs: build: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index fbbc47f..313ef19 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -4,7 +4,7 @@ on: pull_request: types: [opened, synchronize, ready_for_review, edited, closed] branches: - - main + - master jobs: build: From 7c1e860c50587765c2dd4fa1e5deb28337ca2551 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Thu, 16 Dec 2021 13:59:38 -0500 Subject: [PATCH 21/30] Add PR template --- .github/pull_request_template.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..6ff7b29 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,5 @@ +Closes # + + + +- [ ] I updated the changelog From ea6367ccdc1e62da8e83c5e0be02328d5b23f8dd Mon Sep 17 00:00:00 2001 From: Max Isom Date: Thu, 16 Dec 2021 14:00:21 -0500 Subject: [PATCH 22/30] Build every commit --- .github/workflows/build.yml | 51 +++++++++++++++++-------------------- .github/workflows/pr.yml | 18 ------------- 2 files changed, 24 insertions(+), 45 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f181dc0..5eea299 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,31 +1,28 @@ name: Lint & build -on: - push: - branches: - - master +on: push jobs: - build: - name: Lint & build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v2 - with: - node-version: '16' - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ./node_modules - key: ${{ runner.OS }}-dependencies-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.OS }}-dependencies-${{ env.cache-name }}- - ${{ runner.OS }}-dependencies- - ${{ runner.OS }}- - - name: Install dependencies - run: yarn install - - name: Run lint - run: yarn lint - - name: Build - run: yarn build + build: + name: Lint & build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v2 + with: + node-version: '16' + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: ./node_modules + key: ${{ runner.OS }}-dependencies-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.OS }}-dependencies-${{ env.cache-name }}- + ${{ runner.OS }}-dependencies- + ${{ runner.OS }}- + - name: Install dependencies + run: yarn install + - name: Run lint + run: yarn lint + - name: Build + run: yarn build diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 313ef19..48646e6 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -7,24 +7,6 @@ on: - master jobs: - build: - name: Build & lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v2 - with: - node-version: '16' - - - name: Install dependencies - uses: bahmutov/npm-install@v1 - - - name: Run lint - run: yarn lint - - - name: Build - run: yarn build - release: name: Release snapshot runs-on: ubuntu-latest From f6376048eb27e7e2f5c5305f931b23a2d026bbd8 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Thu, 16 Dec 2021 14:03:27 -0500 Subject: [PATCH 23/30] Add changelog, generate releases --- .github/workflows/publish-image.yml | 52 ----------------- .github/workflows/publish.yml | 91 +++++++++++++++++++++++++++++ CHANGELOG.md | 14 +++++ 3 files changed, 105 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/publish-image.yml create mode 100644 .github/workflows/publish.yml create mode 100644 CHANGELOG.md diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml deleted file mode 100644 index ea41dd0..0000000 --- a/.github/workflows/publish-image.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Publish Docker image - -on: - push: - branches: master - -jobs: - main: - runs-on: ubuntu-latest - steps: - - name: Set up Buildx - uses: docker/setup-buildx-action@v1 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Limit concurrent builds to 1 - uses: softprops/turnstyle@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v2 - with: - push: true - tags: codetheweb/muse:latest - platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache,mode=max - - - name: Update Docker Hub description - uses: peter-evans/dockerhub-description@v2.1.0 - env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} - DOCKERHUB_REPOSITORY: codetheweb/muse - \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..51339b2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,91 @@ +name: Publish Docker image + +on: + push: + tags: + - 'v*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Get version from tag + id: tag_name + run: | + echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v} + shell: bash + + - name: Get Changelog Entry + id: changelog_reader + uses: mindsers/changelog-reader-action@v2 + with: + validation_depth: 10 + version: ${{ steps.tag_name.outputs.current_version }} + path: ./CHANGELOG.md + + - name: Create/update release + uses: ncipollo/release-action@v1 + with: + tag: ${{ steps.changelog_reader.outputs.version }} + name: Release ${{ steps.changelog_reader.outputs.version }} + body: ${{ steps.changelog_reader.outputs.changes }} + prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }} + draft: ${{ steps.changelog_reader.outputs.status == 'unreleased' }} + allowUpdates: true + token: ${{ secrets.GITHUB_TOKEN }} + + publish: + runs-on: ubuntu-latest + steps: + - name: Set up Buildx + uses: docker/setup-buildx-action@v1 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Get tags + id: get-tags + uses: Surgo/docker-smart-tag-action@v1 + with: + docker_image: codetheweb/muse + + - name: Wait on lint & build + uses: lewagon/wait-on-check-action@v1.1.1 + with: + ref: ${{ github.sha }} + check-name: 'Lint & build' + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 10 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ steps.get-tags.outputs.tag }} + platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max + + - name: Update Docker Hub description + uses: peter-evans/dockerhub-description@v2.1.0 + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + DOCKERHUB_REPOSITORY: codetheweb/muse diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d6e9487 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [0.1.0] +### Added +- Initial release + +[Unreleased]: https://github.com/codetheweb/muse/compare/v0.1.0...HEAD +[0.1.0]: https://github.com/codetheweb/muse/releases/tag/v0.1.0 From a73fd840f7a521bd56bb3b1e3bb30234c175470d Mon Sep 17 00:00:00 2001 From: Max Isom Date: Thu, 16 Dec 2021 15:03:31 -0500 Subject: [PATCH 24/30] Update README --- .github/workflows/publish.yml | 3 +-- README.md | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 51339b2..12eebab 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Publish Docker image +name: Make release & publish Docker image on: push: @@ -21,7 +21,6 @@ jobs: id: changelog_reader uses: mindsers/changelog-reader-action@v2 with: - validation_depth: 10 version: ${{ steps.tag_name.outputs.current_version }} path: ./CHANGELOG.md diff --git a/README.md b/README.md index ac6e0d3..069f41d 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,25 @@ Muse is written in TypeScript. You can either run Muse with Docker (recommended) Muse will log a URL when run. Open this URL in a browser to invite Muse to your server. Muse will DM the server owner after it's added with setup instructions. +#### Versioning + +The `master` branch acts as the developing / bleeding edge branch and is not guaranteed to be stable. + +When running a production instance, I recommend that you use the [latest release](https://github.com/codetheweb/muse/releases/). + + #### Docker +There are a variety of image tags available: +- `:2`: versions >= 2.0.0 +- `:2.1`: versions >= 2.1.0 and < 2.2.0 +- `:2.1.1`: an exact version specifier +- `:latest`: whatever the latest version is + (Replace empty config strings with correct values.) ```bash -docker run -it -v "$(pwd)/data":/data -e DISCORD_TOKEN='' -e SPOTIFY_CLIENT_ID='' -e SPOTIFY_CLIENT_SECRET='' -e YOUTUBE_API_KEY='' codetheweb/muse +docker run -it -v "$(pwd)/data":/data -e DISCORD_TOKEN='' -e SPOTIFY_CLIENT_ID='' -e SPOTIFY_CLIENT_SECRET='' -e YOUTUBE_API_KEY='' codetheweb/muse:latest ``` This starts Muse and creates a data directory in your current directory. @@ -47,7 +60,7 @@ version: '3.4' services: muse: - image: codetheweb/muse + image: codetheweb/muse:latest restart: always volumes: - ./muse:/data @@ -64,9 +77,10 @@ services: 1. `git clone https://github.com/codetheweb/muse.git && cd muse` 2. Copy `.env.example` to `.env` and populate with values -3. `yarn install` (or `npm i`) -4. `yarn build` (or `npm run build`) -5. `yarn start` (or `npm run start`) +3. I recommend checking out a tagged release with `git checkout v[latest release]` +4. `yarn install` (or `npm i`) +5. `yarn build` (or `npm run build`) +6. `yarn start` (or `npm run start`) **Note**: if you're on Windows, you may need to manually set the ffmpeg path. See [#345](https://github.com/codetheweb/muse/issues/345) for details. From 55c98ff2a937392a2f24d3ee3d3d7cb6e15ff178 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Thu, 16 Dec 2021 15:05:37 -0500 Subject: [PATCH 25/30] Don't create a new tag --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 12eebab..6055264 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,7 +27,7 @@ jobs: - name: Create/update release uses: ncipollo/release-action@v1 with: - tag: ${{ steps.changelog_reader.outputs.version }} + tag: ${GITHUB_REF#refs/tags} name: Release ${{ steps.changelog_reader.outputs.version }} body: ${{ steps.changelog_reader.outputs.changes }} prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }} From 260e8702bf74438fb738d28dd8238576f26ab8a8 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 17 Dec 2021 18:38:23 -0600 Subject: [PATCH 26/30] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6e9487..353c969 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fixes a race condition in the file cache service (see #420) ## [0.1.0] ### Added From f92ec0dd424708caafc789ca5b79ecfec70a4a7c Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 17 Dec 2021 18:45:32 -0600 Subject: [PATCH 27/30] 0.1.1 --- CHANGELOG.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 353c969..ffc1533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.1.1] ### Fixed - Fixes a race condition in the file cache service (see #420) @@ -13,4 +15,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial release [Unreleased]: https://github.com/codetheweb/muse/compare/v0.1.0...HEAD +[0.1.1]: https://github.com/codetheweb/muse/releases/tag/v0.1.1 [0.1.0]: https://github.com/codetheweb/muse/releases/tag/v0.1.0 diff --git a/package.json b/package.json index 1df42c9..d23ba73 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muse", - "version": "0.1.0", + "version": "0.1.1", "description": "🎧 a self-hosted Discord music bot that doesn't suck ", "exports": "./dist/src/index.js", "repository": "git@github.com:codetheweb/muse.git", From 3db8b4cc1dd8c8444a8d146e6a3160c28066d9ff Mon Sep 17 00:00:00 2001 From: Max Isom Date: Sat, 18 Dec 2021 12:05:25 -0600 Subject: [PATCH 28/30] Lint & build on PRs --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5eea299..ffea6a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: Lint & build -on: push +on: [push, pull_request] jobs: build: From 86605f76a56823721af3595a2073133b7b3f8108 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Sat, 18 Dec 2021 12:07:37 -0600 Subject: [PATCH 29/30] Fix tagging during publishing --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6055264..3da4b6f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,8 +27,8 @@ jobs: - name: Create/update release uses: ncipollo/release-action@v1 with: - tag: ${GITHUB_REF#refs/tags} - name: Release ${{ steps.changelog_reader.outputs.version }} + tag: v${{ steps.changelog_reader.outputs.version }} + name: Release v${{ steps.changelog_reader.outputs.version }} body: ${{ steps.changelog_reader.outputs.changes }} prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }} draft: ${{ steps.changelog_reader.outputs.status == 'unreleased' }} From d4827b86d5c848c68cb9868bfde28a2db932c630 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Sat, 18 Dec 2021 12:12:38 -0600 Subject: [PATCH 30/30] Fix PR workflows --- .github/workflows/pr.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 48646e6..2a7a117 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,10 +1,6 @@ name: PR Workflow -on: - pull_request: - types: [opened, synchronize, ready_for_review, edited, closed] - branches: - - master +on: pull_request_target jobs: release: @@ -21,9 +17,9 @@ jobs: uses: actions/cache@v2 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} + key: ${{ runner.os }}-buildx-prs-${{ github.sha }} restore-keys: | - ${{ runner.os }}-buildx- + ${{ runner.os }}-buildx-prs- - name: Login to DockerHub uses: docker/login-action@v1