/repeat: Make command publicly available

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
Macintxsh 2023-12-19 15:38:26 +03:00
parent 6c88ad59e5
commit 2c93147eea
Signed by: mctaylors
GPG key ID: 7181BEBE676903C1
2 changed files with 37 additions and 37 deletions

View file

@ -3,6 +3,7 @@ using System.Text;
using Cassette.Extensions;
using JetBrains.Annotations;
using Lavalink4NET;
using Lavalink4NET.Players.Queued;
using Lavalink4NET.Rest.Entities.Tracks;
using Remora.Commands.Attributes;
using Remora.Commands.Groups;
@ -11,6 +12,7 @@ using Remora.Discord.Commands.Attributes;
using Remora.Discord.Commands.Conditions;
using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Feedback.Services;
using Remora.Discord.Extensions.Formatting;
using Remora.Results;
namespace Cassette.Commands;
@ -128,6 +130,41 @@ public sealed class ControlsCommandGroup(
$"Resumed {player.CurrentTrack.Display()}", feedbackService.Theme.Success);
}
[Command("repeat")]
[Description("Changes player repeat mode")]
[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("seek")]
[Description("Rewinds the current track to a specific position")]
[DiscordDefaultDMPermission(false)]

View file

@ -2,7 +2,6 @@
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;
@ -25,42 +24,6 @@ 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)]