/repeat: Make command publicly available
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
6c88ad59e5
commit
2c93147eea
2 changed files with 37 additions and 37 deletions
|
@ -3,6 +3,7 @@ using System.Text;
|
||||||
using Cassette.Extensions;
|
using Cassette.Extensions;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Lavalink4NET;
|
using Lavalink4NET;
|
||||||
|
using Lavalink4NET.Players.Queued;
|
||||||
using Lavalink4NET.Rest.Entities.Tracks;
|
using Lavalink4NET.Rest.Entities.Tracks;
|
||||||
using Remora.Commands.Attributes;
|
using Remora.Commands.Attributes;
|
||||||
using Remora.Commands.Groups;
|
using Remora.Commands.Groups;
|
||||||
|
@ -11,6 +12,7 @@ using Remora.Discord.Commands.Attributes;
|
||||||
using Remora.Discord.Commands.Conditions;
|
using Remora.Discord.Commands.Conditions;
|
||||||
using Remora.Discord.Commands.Contexts;
|
using Remora.Discord.Commands.Contexts;
|
||||||
using Remora.Discord.Commands.Feedback.Services;
|
using Remora.Discord.Commands.Feedback.Services;
|
||||||
|
using Remora.Discord.Extensions.Formatting;
|
||||||
using Remora.Results;
|
using Remora.Results;
|
||||||
|
|
||||||
namespace Cassette.Commands;
|
namespace Cassette.Commands;
|
||||||
|
@ -128,6 +130,41 @@ public sealed class ControlsCommandGroup(
|
||||||
$"Resumed {player.CurrentTrack.Display()}", feedbackService.Theme.Success);
|
$"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")]
|
[Command("seek")]
|
||||||
[Description("Rewinds the current track to a specific position")]
|
[Description("Rewinds the current track to a specific position")]
|
||||||
[DiscordDefaultDMPermission(false)]
|
[DiscordDefaultDMPermission(false)]
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
using Cassette.Extensions;
|
using Cassette.Extensions;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Lavalink4NET;
|
using Lavalink4NET;
|
||||||
using Lavalink4NET.Players.Queued;
|
|
||||||
using Remora.Discord.Commands.Contexts;
|
using Remora.Discord.Commands.Contexts;
|
||||||
using Remora.Commands.Attributes;
|
using Remora.Commands.Attributes;
|
||||||
using Remora.Commands.Groups;
|
using Remora.Commands.Groups;
|
||||||
|
@ -25,42 +24,6 @@ public sealed class TrustedCommandGroup(
|
||||||
{
|
{
|
||||||
private const DiscordPermission RequiredPermission = DiscordPermission.MuteMembers;
|
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")]
|
[Command("setvolume")]
|
||||||
[Description("Adjusts the volume of the music player")]
|
[Description("Adjusts the volume of the music player")]
|
||||||
[DiscordDefaultMemberPermissions(RequiredPermission)]
|
[DiscordDefaultMemberPermissions(RequiredPermission)]
|
||||||
|
|
Reference in a new issue