diff options
| author | Max Isom <[email protected]> | 2021-12-17 18:36:31 -0600 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2021-12-17 18:36:31 -0600 |
| commit | d07dc5baf4ebb3d20a456364823c97e077846768 (patch) | |
| tree | 47333f7e4024d7fae9a7b44cdd0230326bf0d053 /src | |
| parent | 0396949b39213104054008ccc4b26c6d5b1dd3e3 (diff) | |
| parent | 55c98ff2a937392a2f24d3ee3d3d7cb6e15ff178 (diff) | |
| download | muse-d07dc5baf4ebb3d20a456364823c97e077846768.tar.xz muse-d07dc5baf4ebb3d20a456364823c97e077846768.zip | |
Merge branch 'master' into mutex
Diffstat (limited to 'src')
| -rw-r--r-- | src/bot.ts | 8 | ||||
| -rw-r--r-- | src/commands/play.ts | 32 | ||||
| -rw-r--r-- | src/index.ts | 13 | ||||
| -rw-r--r-- | src/services/player.ts | 4 |
4 files changed, 45 insertions, 12 deletions
@@ -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/commands/play.ts b/src/commands/play.ts index 0582ebe..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,14 +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 (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(); - } } } 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<Bot>(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<Config>(TYPES.Config); 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); } |
