From c5f8d3373baec3a09c50ae1149f7a014565c5593 Mon Sep 17 00:00:00 2001 From: SerpentDrago Date: Mon, 23 Oct 2023 21:36:13 -0400 Subject: [PATCH 1/5] Update README.md (#975) Co-authored-by: Max Isom --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d474a53..394af6a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ Muse is written in TypeScript. You can either run Muse with Docker (recommended) - `SPOTIFY_CLIENT_ID` and `SPOTIFY_CLIENT_SECRET` can be acquired [here](https://developer.spotify.com/dashboard/applications) with 'Create a Client ID'. - `YOUTUBE_API_KEY` can be acquired by [creating a new project](https://console.developers.google.com) in Google's Developer Console, enabling the YouTube API, and creating an API key under credentials. +> [!WARNING] +> Even if you don't plan on using Spotify, you must still provide the client ID and secret; otherwise Muse will not function. + 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. A 64-bit OS is required to run Muse. From d8d72074f26ad1d97a0c24a619cbc68fdf10188a Mon Sep 17 00:00:00 2001 From: ninele7 <33155080+ninele7@users.noreply.github.com> Date: Fri, 22 Dec 2023 05:30:25 +0500 Subject: [PATCH 2/5] Optimize docker memory (#976) --- CHANGELOG.md | 2 ++ Dockerfile | 19 +++++++++++++++---- package.json | 3 ++- src/commands/config.ts | 2 +- src/commands/loop.ts | 2 +- src/events/voice-state-update.ts | 2 +- src/inversify.config.ts | 2 +- src/scripts/migrate-and-start.ts | 4 +++- src/services/add-query-to-queue.ts | 2 +- src/services/get-songs.ts | 2 +- src/services/player.ts | 2 +- src/utils/get-guild-settings.ts | 4 ++-- tsconfig.json | 2 +- 13 files changed, 32 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f2774a..cd3a99e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Optimized Docker container to run JS code directly with node instead of yarn, npm and tsx. Reduces memory usage. + ## [2.4.3] - 2023-09-10 ### Fixed diff --git a/Dockerfile b/Dockerfile index 6ec862d..a3d20ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,18 +14,29 @@ COPY package.json . COPY yarn.lock . RUN yarn install --prod +RUN cp -R node_modules /usr/app/prod_node_modules + +RUN yarn install + +FROM dependencies AS builder + +COPY . . + +# Run tsc build +RUN yarn prisma generate +RUN yarn build # Only keep what's necessary to run FROM base AS runner WORKDIR /usr/app -COPY --from=dependencies /usr/app/node_modules node_modules +COPY --from=builder /usr/app/dist ./dist +COPY --from=dependencies /usr/app/prod_node_modules node_modules +COPY --from=builder /usr/app/node_modules/.prisma/client ./node_modules/.prisma/client COPY . . -RUN yarn prisma generate - ARG COMMIT_HASH=unknown ARG BUILD_DATE=unknown @@ -34,4 +45,4 @@ ENV NODE_ENV production ENV COMMIT_HASH $COMMIT_HASH ENV BUILD_DATE $BUILD_DATE -CMD ["tini", "--", "yarn", "start"] +CMD ["tini", "--", "node", "--enable-source-maps", "dist/scripts/migrate-and-start.js"] diff --git a/package.json b/package.json index 62f38e7..1e1b98f 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "migrations:run": "npm run prisma:with-env migrate deploy", "prisma:with-env": "npm run env:set-database-url prisma", "env:set-database-url": "tsx src/scripts/run-with-database-url.ts", - "release": "release-it" + "release": "release-it", + "build": "tsc" }, "devDependencies": { "@release-it/keep-a-changelog": "^2.3.0", diff --git a/src/commands/config.ts b/src/commands/config.ts index 158f4f4..ae3bc45 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -3,7 +3,7 @@ import {ChatInputCommandInteraction, EmbedBuilder, PermissionFlagsBits} from 'di import {injectable} from 'inversify'; import {prisma} from '../utils/db.js'; import Command from './index.js'; -import {getGuildSettings} from '../utils/get-guild-settings'; +import {getGuildSettings} from '../utils/get-guild-settings.js'; @injectable() export default class implements Command { diff --git a/src/commands/loop.ts b/src/commands/loop.ts index 3b609a5..6618e84 100644 --- a/src/commands/loop.ts +++ b/src/commands/loop.ts @@ -4,7 +4,7 @@ import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player.js'; import Command from '.'; import {SlashCommandBuilder} from '@discordjs/builders'; -import {STATUS} from '../services/player'; +import {STATUS} from '../services/player.js'; @injectable() export default class implements Command { diff --git a/src/events/voice-state-update.ts b/src/events/voice-state-update.ts index e941a70..15784db 100644 --- a/src/events/voice-state-update.ts +++ b/src/events/voice-state-update.ts @@ -3,7 +3,7 @@ import container from '../inversify.config.js'; import {TYPES} from '../types.js'; import PlayerManager from '../managers/player.js'; import {getSizeWithoutBots} from '../utils/channels.js'; -import {getGuildSettings} from '../utils/get-guild-settings'; +import {getGuildSettings} from '../utils/get-guild-settings.js'; export default async (oldState: VoiceState, _: VoiceState): Promise => { const playerManager = container.get(TYPES.Managers.Player); diff --git a/src/inversify.config.ts b/src/inversify.config.ts index 1a3b85c..65a0258 100644 --- a/src/inversify.config.ts +++ b/src/inversify.config.ts @@ -21,7 +21,7 @@ import Config from './commands/config.js'; import Disconnect from './commands/disconnect.js'; import Favorites from './commands/favorites.js'; import ForwardSeek from './commands/fseek.js'; -import Loop from './commands/loop'; +import Loop from './commands/loop.js'; import Move from './commands/move.js'; import Next from './commands/next.js'; import NowPlaying from './commands/now-playing.js'; diff --git a/src/scripts/migrate-and-start.ts b/src/scripts/migrate-and-start.ts index d971745..41197e4 100644 --- a/src/scripts/migrate-and-start.ts +++ b/src/scripts/migrate-and-start.ts @@ -9,11 +9,13 @@ import Prisma from '@prisma/client'; import ora from 'ora'; import {startBot} from '../index.js'; import logBanner from '../utils/log-banner.js'; -import {createDatabasePath} from '../utils/create-database-url.js'; +import createDatabaseUrl, {createDatabasePath} from '../utils/create-database-url.js'; import {DATA_DIR} from '../services/config.js'; const client = new Prisma.PrismaClient(); +process.env.DATABASE_URL = process.env.DATABASE_URL ?? createDatabaseUrl(DATA_DIR); + const migrateFromSequelizeToPrisma = async () => { await execa('prisma', ['migrate', 'resolve', '--applied', '20220101155430_migrate_from_sequelize'], {preferLocal: true}); }; diff --git a/src/services/add-query-to-queue.ts b/src/services/add-query-to-queue.ts index b5367a2..79bfdcd 100644 --- a/src/services/add-query-to-queue.ts +++ b/src/services/add-query-to-queue.ts @@ -9,7 +9,7 @@ import {SongMetadata, STATUS} from './player.js'; import PlayerManager from '../managers/player.js'; import {buildPlayingMessageEmbed} from '../utils/build-embed.js'; import {getMemberVoiceChannel, getMostPopularVoiceChannel} from '../utils/channels.js'; -import {getGuildSettings} from '../utils/get-guild-settings'; +import {getGuildSettings} from '../utils/get-guild-settings.js'; @injectable() export default class AddQueryToQueue { diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts index 1c68e7e..b957734 100644 --- a/src/services/get-songs.ts +++ b/src/services/get-songs.ts @@ -1,6 +1,6 @@ import {inject, injectable} from 'inversify'; import * as spotifyURI from 'spotify-uri'; -import {SongMetadata, QueuedPlaylist, MediaSource} from './player'; +import {SongMetadata, QueuedPlaylist, MediaSource} from './player.js'; import {TYPES} from '../types.js'; import ffmpeg from 'fluent-ffmpeg'; import YoutubeAPI from './youtube-api.js'; diff --git a/src/services/player.ts b/src/services/player.ts index c888896..9754a42 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -18,7 +18,7 @@ import { } from '@discordjs/voice'; import FileCacheProvider from './file-cache.js'; import debug from '../utils/debug.js'; -import {getGuildSettings} from '../utils/get-guild-settings'; +import {getGuildSettings} from '../utils/get-guild-settings.js'; export enum MediaSource { Youtube, diff --git a/src/utils/get-guild-settings.ts b/src/utils/get-guild-settings.ts index f001aab..3d9e965 100644 --- a/src/utils/get-guild-settings.ts +++ b/src/utils/get-guild-settings.ts @@ -1,6 +1,6 @@ import {Setting} from '@prisma/client'; -import {prisma} from './db'; -import {createGuildSettings} from '../events/guild-create'; +import {prisma} from './db.js'; +import {createGuildSettings} from '../events/guild-create.js'; export async function getGuildSettings(guildId: string): Promise { const config = await prisma.setting.findUnique({where: {guildId}}); diff --git a/tsconfig.json b/tsconfig.json index c02ad2f..5685334 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "esModuleInterop": true, "sourceMap": true, "resolveJsonModule": true, - "noEmit": true + "outDir": "dist" }, "include": ["src"], "exclude": ["node_modules"] From 45bdbd1494a59f590ec7a29a65df022ae6af05ab Mon Sep 17 00:00:00 2001 From: Max Isom Date: Thu, 21 Dec 2023 18:31:08 -0600 Subject: [PATCH 3/5] Release 2.4.4 --- CHANGELOG.md | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd3a99e..cc6f396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.4.4] - 2023-12-21 + - Optimized Docker container to run JS code directly with node instead of yarn, npm and tsx. Reduces memory usage. ## [2.4.3] - 2023-09-10 @@ -273,7 +275,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release -[unreleased]: https://github.com/codetheweb/muse/compare/v2.4.3...HEAD +[unreleased]: https://github.com/codetheweb/muse/compare/v2.4.4...HEAD +[2.4.4]: https://github.com/codetheweb/muse/compare/v2.4.3...v2.4.4 [2.4.3]: https://github.com/codetheweb/muse/compare/v2.4.2...v2.4.3 [2.4.2]: https://github.com/codetheweb/muse/compare/v2.4.1...v2.4.2 [2.4.1]: https://github.com/codetheweb/muse/compare/v2.4.0...v2.4.1 diff --git a/package.json b/package.json index 1e1b98f..e6ccd08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muse", - "version": "2.4.3", + "version": "2.4.4", "description": "🎧 a self-hosted Discord music bot that doesn't suck ", "repository": "git@github.com:codetheweb/muse.git", "author": "Max Isom ", From 769f9da8a21ca467964142f57c79a0f482232900 Mon Sep 17 00:00:00 2001 From: Reynard G <40525094+Reynard-G@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:44:44 -0600 Subject: [PATCH 4/5] Add /loop-queue command (#989) --- CHANGELOG.md | 3 +++ src/commands/loop-queue.ts | 42 ++++++++++++++++++++++++++++++++++++++ src/commands/loop.ts | 4 ++++ src/inversify.config.ts | 2 ++ src/services/player.ts | 12 +++++++++++ src/utils/build-embed.ts | 2 +- 6 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/commands/loop-queue.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index cc6f396..3161a6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Added `/loop-queue` + ## [2.4.4] - 2023-12-21 - Optimized Docker container to run JS code directly with node instead of yarn, npm and tsx. Reduces memory usage. diff --git a/src/commands/loop-queue.ts b/src/commands/loop-queue.ts new file mode 100644 index 0000000..47b9adf --- /dev/null +++ b/src/commands/loop-queue.ts @@ -0,0 +1,42 @@ +import {ChatInputCommandInteraction} from 'discord.js'; +import {TYPES} from '../types.js'; +import {inject, injectable} from 'inversify'; +import PlayerManager from '../managers/player.js'; +import Command from '.'; +import {SlashCommandBuilder} from '@discordjs/builders'; +import {STATUS} from '../services/player.js'; + +@injectable() +export default class implements Command { + public readonly slashCommand = new SlashCommandBuilder() + .setName('loop-queue') + .setDescription('toggle looping the entire queue'); + + public requiresVC = true; + + private readonly playerManager: PlayerManager; + + constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) { + this.playerManager = playerManager; + } + + public async execute(interaction: ChatInputCommandInteraction): Promise { + const player = this.playerManager.get(interaction.guild!.id); + + if (player.status === STATUS.IDLE) { + throw new Error('no songs to loop!'); + } + + if (player.queueSize() < 2) { + throw new Error('not enough songs to loop a queue!'); + } + + if (player.loopCurrentSong) { + player.loopCurrentSong = false; + } + + player.loopCurrentQueue = !player.loopCurrentQueue; + + await interaction.reply((player.loopCurrentQueue ? 'looped queue :)' : 'stopped looping queue :(')); + } +} diff --git a/src/commands/loop.ts b/src/commands/loop.ts index 6618e84..f654237 100644 --- a/src/commands/loop.ts +++ b/src/commands/loop.ts @@ -27,6 +27,10 @@ export default class implements Command { throw new Error('no song to loop!'); } + if (player.loopCurrentQueue) { + player.loopCurrentQueue = false; + } + player.loopCurrentSong = !player.loopCurrentSong; await interaction.reply((player.loopCurrentSong ? 'looped :)' : 'stopped looping :(')); diff --git a/src/inversify.config.ts b/src/inversify.config.ts index 65a0258..d0694cf 100644 --- a/src/inversify.config.ts +++ b/src/inversify.config.ts @@ -21,6 +21,7 @@ import Config from './commands/config.js'; import Disconnect from './commands/disconnect.js'; import Favorites from './commands/favorites.js'; import ForwardSeek from './commands/fseek.js'; +import LoopQueue from './commands/loop-queue.js'; import Loop from './commands/loop.js'; import Move from './commands/move.js'; import Next from './commands/next.js'; @@ -68,6 +69,7 @@ container.bind(TYPES.Services.SpotifyAPI).to(SpotifyAPI).inSingleton Disconnect, Favorites, ForwardSeek, + LoopQueue, Loop, Move, Next, diff --git a/src/services/player.ts b/src/services/player.ts index 9754a42..c17a536 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -63,6 +63,7 @@ export default class { public status = STATUS.PAUSED; public guildId: string; public loopCurrentSong = false; + public loopCurrentQueue = false; private queue: QueuedSong[] = []; private queuePosition = 0; @@ -545,6 +546,17 @@ export default class { return; } + // Automatically re-add current song to queue + if (this.loopCurrentQueue && newState.status === AudioPlayerStatus.Idle && this.status === STATUS.PLAYING) { + const currentSong = this.getCurrent(); + + if (currentSong) { + this.add(currentSong); + } else { + throw new Error('No song currently playing.'); + } + } + if (newState.status === AudioPlayerStatus.Idle && this.status === STATUS.PLAYING) { await this.forward(1); } diff --git a/src/utils/build-embed.ts b/src/utils/build-embed.ts index e4159b6..d851e3f 100644 --- a/src/utils/build-embed.ts +++ b/src/utils/build-embed.ts @@ -46,7 +46,7 @@ const getPlayerUI = (player: Player) => { const button = player.status === STATUS.PLAYING ? '⏚ī¸' : 'â–ļī¸'; const progressBar = getProgressBar(15, position / song.length); const elapsedTime = song.isLive ? 'live' : `${prettyTime(position)}/${prettyTime(song.length)}`; - const loop = player.loopCurrentSong ? '🔁' : ''; + const loop = player.loopCurrentSong ? '🔂' : player.loopCurrentQueue ? '🔁' : ''; return `${button} ${progressBar} \`[${elapsedTime}]\` 🔉 ${loop}`; }; From 03d960d31a21235d2adec3feac662ef863657a7a Mon Sep 17 00:00:00 2001 From: Max Isom Date: Tue, 16 Jan 2024 17:45:08 -0800 Subject: [PATCH 5/5] Release 2.5.0 --- CHANGELOG.md | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3161a6e..cbe472b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.5.0] - 2024-01-16 + ### Added - Added `/loop-queue` @@ -278,7 +280,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release -[unreleased]: https://github.com/codetheweb/muse/compare/v2.4.4...HEAD +[unreleased]: https://github.com/codetheweb/muse/compare/v2.5.0...HEAD +[2.5.0]: https://github.com/codetheweb/muse/compare/v2.4.4...v2.5.0 [2.4.4]: https://github.com/codetheweb/muse/compare/v2.4.3...v2.4.4 [2.4.3]: https://github.com/codetheweb/muse/compare/v2.4.2...v2.4.3 [2.4.2]: https://github.com/codetheweb/muse/compare/v2.4.1...v2.4.2 diff --git a/package.json b/package.json index e6ccd08..1c91e71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muse", - "version": "2.4.4", + "version": "2.5.0", "description": "🎧 a self-hosted Discord music bot that doesn't suck ", "repository": "git@github.com:codetheweb/muse.git", "author": "Max Isom ",