Add /replay command (#901)

Co-authored-by: xHyperElectric <laskew21@yahoo.com>
Co-authored-by: xHyperElectric <xhyperelectric@xHyperElectric>
Co-authored-by: Max Isom <codetheweb@users.noreply.github.com>
This commit is contained in:
xHyperElectric 2023-02-26 21:50:36 -05:00 committed by GitHub
parent c89f288b7d
commit 8acc4f23f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 5 deletions

View file

@ -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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
### Added
- Added a '/replay' to restart the current song. Alias for '/seek time: 0'
## [2.1.9] - 2023-02-14 ## [2.1.9] - 2023-02-14
### Fixed ### Fixed

42
src/commands/replay.ts Normal file
View file

@ -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';
@injectable()
export default class implements Command {
public readonly slashCommand = new SlashCommandBuilder()
.setName('replay')
.setDescription('replay the current song');
public requiresVC = true;
private readonly playerManager: PlayerManager;
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
this.playerManager = playerManager;
}
public async execute(interaction: ChatInputCommandInteraction): Promise<void> {
const player = this.playerManager.get(interaction.guild!.id);
const currentSong = player.getCurrent();
if (!currentSong) {
throw new Error('nothing is playing');
}
if (currentSong.isLive) {
throw new Error('can\'t replay a livestream');
}
await Promise.all([
player.seek(0),
interaction.deferReply(),
]);
await interaction.editReply('👍 replayed the current song');
}
}

View file

@ -14,30 +14,31 @@ import GetSongs from './services/get-songs.js';
import YoutubeAPI from './services/youtube-api.js'; import YoutubeAPI from './services/youtube-api.js';
import SpotifyAPI from './services/spotify-api.js'; import SpotifyAPI from './services/spotify-api.js';
// Comands // Commands
import Command from './commands'; import Command from './commands';
import Clear from './commands/clear.js'; import Clear from './commands/clear.js';
import Config from './commands/config.js'; import Config from './commands/config.js';
import Disconnect from './commands/disconnect.js'; import Disconnect from './commands/disconnect.js';
import Favorites from './commands/favorites.js'; import Favorites from './commands/favorites.js';
import ForwardSeek from './commands/fseek.js'; import ForwardSeek from './commands/fseek.js';
import Loop from './commands/loop';
import Move from './commands/move.js'; import Move from './commands/move.js';
import Next from './commands/next.js';
import NowPlaying from './commands/now-playing.js'; import NowPlaying from './commands/now-playing.js';
import Pause from './commands/pause.js'; import Pause from './commands/pause.js';
import Play from './commands/play.js'; import Play from './commands/play.js';
import QueueCommand from './commands/queue.js'; import QueueCommand from './commands/queue.js';
import Remove from './commands/remove.js'; import Remove from './commands/remove.js';
import Replay from './commands/replay.js';
import Resume from './commands/resume.js'; import Resume from './commands/resume.js';
import Seek from './commands/seek.js'; import Seek from './commands/seek.js';
import Shuffle from './commands/shuffle.js'; import Shuffle from './commands/shuffle.js';
import Skip from './commands/skip.js'; import Skip from './commands/skip.js';
import Next from './commands/next.js';
import Stop from './commands/stop.js'; import Stop from './commands/stop.js';
import Unskip from './commands/unskip.js'; import Unskip from './commands/unskip.js';
import ThirdParty from './services/third-party.js'; import ThirdParty from './services/third-party.js';
import FileCacheProvider from './services/file-cache.js'; import FileCacheProvider from './services/file-cache.js';
import KeyValueCacheProvider from './services/key-value-cache.js'; import KeyValueCacheProvider from './services/key-value-cache.js';
import Loop from './commands/loop';
const container = new Container(); const container = new Container();
@ -67,20 +68,21 @@ container.bind<SpotifyAPI>(TYPES.Services.SpotifyAPI).to(SpotifyAPI).inSingleton
Disconnect, Disconnect,
Favorites, Favorites,
ForwardSeek, ForwardSeek,
Loop,
Move, Move,
Next,
NowPlaying, NowPlaying,
Pause, Pause,
Play, Play,
QueueCommand, QueueCommand,
Remove, Remove,
Replay,
Resume, Resume,
Seek, Seek,
Shuffle, Shuffle,
Skip, Skip,
Next,
Stop, Stop,
Unskip, Unskip,
Loop,
].forEach(command => { ].forEach(command => {
container.bind<Command>(TYPES.Command).to(command).inSingletonScope(); container.bind<Command>(TYPES.Command).to(command).inSingletonScope();
}); });