mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 01:05:30 +01:00
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:
parent
c89f288b7d
commit
8acc4f23f2
|
@ -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]
|
||||
### Added
|
||||
- Added a '/replay' to restart the current song. Alias for '/seek time: 0'
|
||||
|
||||
## [2.1.9] - 2023-02-14
|
||||
### Fixed
|
||||
|
|
42
src/commands/replay.ts
Normal file
42
src/commands/replay.ts
Normal 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');
|
||||
}
|
||||
}
|
|
@ -14,30 +14,31 @@ import GetSongs from './services/get-songs.js';
|
|||
import YoutubeAPI from './services/youtube-api.js';
|
||||
import SpotifyAPI from './services/spotify-api.js';
|
||||
|
||||
// Comands
|
||||
// Commands
|
||||
import Command from './commands';
|
||||
import Clear from './commands/clear.js';
|
||||
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 Move from './commands/move.js';
|
||||
import Next from './commands/next.js';
|
||||
import NowPlaying from './commands/now-playing.js';
|
||||
import Pause from './commands/pause.js';
|
||||
import Play from './commands/play.js';
|
||||
import QueueCommand from './commands/queue.js';
|
||||
import Remove from './commands/remove.js';
|
||||
import Replay from './commands/replay.js';
|
||||
import Resume from './commands/resume.js';
|
||||
import Seek from './commands/seek.js';
|
||||
import Shuffle from './commands/shuffle.js';
|
||||
import Skip from './commands/skip.js';
|
||||
import Next from './commands/next.js';
|
||||
import Stop from './commands/stop.js';
|
||||
import Unskip from './commands/unskip.js';
|
||||
import ThirdParty from './services/third-party.js';
|
||||
import FileCacheProvider from './services/file-cache.js';
|
||||
import KeyValueCacheProvider from './services/key-value-cache.js';
|
||||
import Loop from './commands/loop';
|
||||
|
||||
const container = new Container();
|
||||
|
||||
|
@ -67,20 +68,21 @@ container.bind<SpotifyAPI>(TYPES.Services.SpotifyAPI).to(SpotifyAPI).inSingleton
|
|||
Disconnect,
|
||||
Favorites,
|
||||
ForwardSeek,
|
||||
Loop,
|
||||
Move,
|
||||
Next,
|
||||
NowPlaying,
|
||||
Pause,
|
||||
Play,
|
||||
QueueCommand,
|
||||
Remove,
|
||||
Replay,
|
||||
Resume,
|
||||
Seek,
|
||||
Shuffle,
|
||||
Skip,
|
||||
Next,
|
||||
Stop,
|
||||
Unskip,
|
||||
Loop,
|
||||
].forEach(command => {
|
||||
container.bind<Command>(TYPES.Command).to(command).inSingletonScope();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue