Add /repeat command
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
a106d19435
commit
4eba6f3b96
2 changed files with 49 additions and 0 deletions
|
@ -81,6 +81,18 @@ public sealed class InfoCommandGroup(
|
|||
feedbackService.Theme.FaultOrDanger);
|
||||
}
|
||||
|
||||
var repeatMode = player.RepeatMode;
|
||||
if (repeatMode is not TrackRepeatMode.None)
|
||||
{
|
||||
builder.AppendLine($"> The current repeat mode is set to {Markdown.Bold(repeatMode.ToString())}");
|
||||
}
|
||||
|
||||
if (repeatMode is TrackRepeatMode.Track)
|
||||
{
|
||||
builder.AppendLine("Use **/nowplaying** to show current playing track");
|
||||
return Result.FromSuccess();
|
||||
}
|
||||
|
||||
for (var i = 0; i < queue.Count; i++)
|
||||
{
|
||||
var track = queue[i].Track;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using Cassette.Extensions;
|
||||
using JetBrains.Annotations;
|
||||
using Lavalink4NET;
|
||||
using Lavalink4NET.Players.Queued;
|
||||
using Remora.Discord.Commands.Contexts;
|
||||
using Remora.Commands.Attributes;
|
||||
using Remora.Commands.Groups;
|
||||
|
@ -24,6 +25,42 @@ public sealed class TrustedCommandGroup(
|
|||
{
|
||||
private const DiscordPermission RequiredPermission = DiscordPermission.MuteMembers;
|
||||
|
||||
[Command("repeat")]
|
||||
[Description("Changes player repeat mode")]
|
||||
[DiscordDefaultMemberPermissions(RequiredPermission)]
|
||||
[DiscordDefaultDMPermission(false)]
|
||||
[UsedImplicitly]
|
||||
public async Task<Result> RepeatCommandAsync(
|
||||
TrackRepeatMode mode)
|
||||
{
|
||||
var player = await LavalinkPlayer.GetPlayerAsync(
|
||||
commandContext, audioService, feedbackService);
|
||||
if (player is null)
|
||||
{
|
||||
return Result.FromSuccess();
|
||||
}
|
||||
|
||||
if (player.RepeatMode is TrackRepeatMode.Queue
|
||||
&& mode is not TrackRepeatMode.Queue)
|
||||
{
|
||||
var queue = player.Queue;
|
||||
await queue.RemoveAsync(queue[^1]);
|
||||
}
|
||||
|
||||
if (player.RepeatMode is not TrackRepeatMode.Queue
|
||||
&& mode is TrackRepeatMode.Queue
|
||||
&& player.CurrentTrack is not null)
|
||||
{
|
||||
await player.PlayAsync(player.CurrentTrack);
|
||||
}
|
||||
|
||||
player.RepeatMode = mode;
|
||||
|
||||
return await feedbackService.SendContextualMessageResult(
|
||||
$"Repeat mode is now set to {Markdown.Bold(mode.ToString())}",
|
||||
feedbackService.Theme.Success);
|
||||
}
|
||||
|
||||
[Command("setvolume")]
|
||||
[Description("Adjusts the volume of the music player")]
|
||||
[DiscordDefaultMemberPermissions(RequiredPermission)]
|
||||
|
|
Loading…
Reference in a new issue