Add project files.
This commit is contained in:
24
TomatenMusicCore/Commands/Checks/OnlyGuildCheck.cs
Normal file
24
TomatenMusicCore/Commands/Checks/OnlyGuildCheck.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus;
|
||||
using TomatenMusic.Music;
|
||||
|
||||
namespace TomatenMusic.Commands.Checks
|
||||
{
|
||||
public class OnlyGuildCheck : SlashCheckBaseAttribute
|
||||
{
|
||||
public override async Task<bool> ExecuteChecksAsync(InteractionContext ctx)
|
||||
{
|
||||
if (ctx.Guild == null)
|
||||
{
|
||||
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DSharpPlus.Entities.DiscordInteractionResponseBuilder().WithContent("This Command is only available on Guilds.").AsEphemeral(true));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
41
TomatenMusicCore/Commands/Checks/UserInMusicChannelCheck.cs
Normal file
41
TomatenMusicCore/Commands/Checks/UserInMusicChannelCheck.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.EventArgs;
|
||||
using DSharpPlus;
|
||||
using TomatenMusic.Music;
|
||||
using Emzi0767.Utilities;
|
||||
using Lavalink4NET;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace TomatenMusic.Commands.Checks
|
||||
{
|
||||
public class UserInMusicChannelCheck : SlashCheckBaseAttribute
|
||||
{
|
||||
public bool _passIfNull { get; set; }
|
||||
public UserInMusicChannelCheck(bool passIfNull = false)
|
||||
{
|
||||
_passIfNull = passIfNull;
|
||||
}
|
||||
public override async Task<bool> ExecuteChecksAsync(InteractionContext ctx)
|
||||
{
|
||||
IAudioService audioService = TomatenMusicBot.ServiceProvider.GetRequiredService<IAudioService>();
|
||||
|
||||
GuildPlayer player = audioService.GetPlayer<GuildPlayer>(ctx.Guild.Id);
|
||||
bool allowed;
|
||||
//TODO
|
||||
if (player != null)
|
||||
{
|
||||
allowed = ctx.Member.VoiceState.Channel != null && ctx.Member.VoiceState.Channel.Id == player.VoiceChannelId;
|
||||
}
|
||||
else
|
||||
allowed = _passIfNull;
|
||||
|
||||
if (!allowed)
|
||||
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DSharpPlus.Entities.DiscordInteractionResponseBuilder().WithContent("❌ Please connect to the Bots Channel to use this Command").AsEphemeral(true));
|
||||
return allowed;
|
||||
}
|
||||
}
|
||||
}
|
27
TomatenMusicCore/Commands/Checks/UserInVoiceChannelCheck.cs
Normal file
27
TomatenMusicCore/Commands/Checks/UserInVoiceChannelCheck.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus;
|
||||
using TomatenMusic.Music;
|
||||
|
||||
namespace TomatenMusic.Commands.Checks
|
||||
{
|
||||
class UserInVoiceChannelCheck : SlashCheckBaseAttribute
|
||||
{
|
||||
|
||||
public override async Task<bool> ExecuteChecksAsync(InteractionContext ctx)
|
||||
{
|
||||
|
||||
if (ctx.Member.VoiceState == null || ctx.Member.VoiceState.Channel == null)
|
||||
{
|
||||
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DSharpPlus.Entities.DiscordInteractionResponseBuilder().WithContent("You are not in a Voice Channel.").AsEphemeral(true));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
266
TomatenMusicCore/Commands/MusicCommands.cs
Normal file
266
TomatenMusicCore/Commands/MusicCommands.cs
Normal file
@@ -0,0 +1,266 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.Entities;
|
||||
using System.Threading.Tasks;
|
||||
using TomatenMusic.Music;
|
||||
using TomatenMusic.Music.Entitites;
|
||||
using TomatenMusic.Commands.Checks;
|
||||
using TomatenMusic.Util;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TomatenMusic.Prompt;
|
||||
using TomatenMusic.Prompt.Model;
|
||||
using TomatenMusic.Prompt.Implementation;
|
||||
using TomatenMusic.Prompt.Option;
|
||||
using System.Linq;
|
||||
using Lavalink4NET;
|
||||
using Lavalink4NET.Player;
|
||||
|
||||
namespace TomatenMusic.Commands
|
||||
{
|
||||
public class MusicCommands : ApplicationCommandModule
|
||||
{
|
||||
public IAudioService _audioService { get; set; }
|
||||
public ILogger<MusicCommands> _logger { get; set; }
|
||||
public TrackProvider _trackProvider { get; set; }
|
||||
|
||||
public MusicCommands(IAudioService audioService, ILogger<MusicCommands> logger, TrackProvider trackProvider)
|
||||
{
|
||||
_audioService = audioService;
|
||||
_logger = logger;
|
||||
_trackProvider = trackProvider;
|
||||
}
|
||||
|
||||
[SlashCommand("stop", "Stops the current Playback and clears the Queue")]
|
||||
[OnlyGuildCheck]
|
||||
[UserInMusicChannelCheck]
|
||||
public async Task StopCommand(InteractionContext ctx)
|
||||
{
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
try
|
||||
{
|
||||
await player.DisconnectAsync();
|
||||
}catch (Exception ex)
|
||||
{
|
||||
await ctx.CreateResponseAsync(new DiscordInteractionResponseBuilder
|
||||
{
|
||||
Content = $"❌ An Error occured : ``{ex.Message}``",
|
||||
IsEphemeral = true
|
||||
});
|
||||
return;
|
||||
}
|
||||
await ctx.CreateResponseAsync(new DiscordInteractionResponseBuilder
|
||||
{
|
||||
Content = $"✔️ The Bot was stopped successfully",
|
||||
IsEphemeral = true
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
[SlashCommand("skip", "Skips the current song and plays the next one in the queue")]
|
||||
[OnlyGuildCheck]
|
||||
[UserInMusicChannelCheck]
|
||||
public async Task SkipCommand(InteractionContext ctx)
|
||||
{
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
|
||||
LavalinkTrack oldTrack = player.CurrentTrack;
|
||||
try
|
||||
{
|
||||
await player.SkipAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"⛔ Could not Skip Song, Queue Empty!").AsEphemeral(true));
|
||||
return;
|
||||
}
|
||||
|
||||
_ = ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"Skipped From Song ``{oldTrack.Title}`` To Song:")
|
||||
.AddEmbed(Common.AsEmbed(player.CurrentTrack, loopType: player.PlayerQueue.LoopType)).AsEphemeral(true));
|
||||
}
|
||||
|
||||
[SlashCommand("fav", "Shows the favorite Song Panel")]
|
||||
[OnlyGuildCheck]
|
||||
public async Task FavCommand(InteractionContext ctx)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[SlashCommand("search", "Searches for a specific query")]
|
||||
[OnlyGuildCheck]
|
||||
public async Task SearchCommand(InteractionContext ctx, [Option("query", "The Search Query")] string query)
|
||||
{
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
MusicActionResponse response;
|
||||
try
|
||||
{
|
||||
response = await _trackProvider.SearchAsync(query, true);
|
||||
}catch (Exception e)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"❌ Search failed: ``{e.Message}``"));
|
||||
return;
|
||||
}
|
||||
|
||||
var prompt = new SongSelectorPrompt($"Search results for {query}", response.Tracks);
|
||||
prompt.ConfirmCallback = async (tracks) =>
|
||||
{
|
||||
var selectPrompt = new SongListActionPrompt(tracks, ctx.Member, prompt);
|
||||
await selectPrompt.UseAsync(prompt.Interaction, prompt.Message);
|
||||
};
|
||||
|
||||
await prompt.UseAsync(ctx.Interaction, await ctx.GetOriginalResponseAsync());
|
||||
}
|
||||
|
||||
[SlashCommand("time", "Sets the playing position of the current Song.")]
|
||||
[OnlyGuildCheck]
|
||||
[UserInMusicChannelCheck]
|
||||
public async Task TimeCommand(InteractionContext ctx, [Option("time", "The time formatted like this: Hours: 1h, Minutes: 1m, Seconds 1s")] string time)
|
||||
{
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
|
||||
TimeSpan timeSpan;
|
||||
|
||||
try
|
||||
{
|
||||
timeSpan = TimeSpan.Parse(time);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
timeSpan = Common.ToTimeSpan(time);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("❌ An Error occured when parsing your input."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await player.SeekPositionAsync(timeSpan);
|
||||
}catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"❌ An Error occured while Seeking the Track: ``{ex.Message}``"));
|
||||
return;
|
||||
}
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"✔️ You successfully set the Song to ``{Common.GetTimestamp(timeSpan)}``."));
|
||||
}
|
||||
|
||||
[SlashCommand("pause", "Pauses or Resumes the current Song.")]
|
||||
[OnlyGuildCheck]
|
||||
[UserInMusicChannelCheck]
|
||||
public async Task PauseCommand(InteractionContext ctx)
|
||||
{
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
try
|
||||
{
|
||||
await player.TogglePauseAsync();
|
||||
}catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"❌ An Error occured changing the pause state of the Song: ``{ex.Message}``"));
|
||||
return;
|
||||
}
|
||||
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"✔️ You {(player.State == PlayerState.Paused ? "successfully paused the Track" : "successfully resumed the Track")}"));
|
||||
|
||||
}
|
||||
|
||||
[SlashCommand("shuffle", "Shuffles the Queue.")]
|
||||
[OnlyGuildCheck]
|
||||
[UserInMusicChannelCheck]
|
||||
public async Task ShuffleCommand(InteractionContext ctx)
|
||||
{
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = _audioService.GetPlayer<GuildPlayer>(ctx.Guild.Id);
|
||||
try
|
||||
{
|
||||
await player.ShuffleAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"❌ An error occured while shuffling the Queue: ``{ex.Message}``"));
|
||||
return;
|
||||
}
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"😀 You shuffled the Queue."));
|
||||
|
||||
}
|
||||
|
||||
[SlashCommand("loop", "Sets the loop type of the current player.")]
|
||||
[OnlyGuildCheck]
|
||||
[UserInMusicChannelCheck]
|
||||
public async Task LoopCommand(InteractionContext ctx, [Option("Looptype", "The loop type which the player should be set to")] LoopType type)
|
||||
{
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = _audioService.GetPlayer<GuildPlayer>(ctx.Guild.Id);
|
||||
|
||||
try
|
||||
{
|
||||
await player.SetLoopAsync(type);
|
||||
}catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"❌ An error occured while change the Queue Loop: ``{ex.Message}``"));
|
||||
|
||||
}
|
||||
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"😀 You have set the Loop to ``{type.ToString()}``."));
|
||||
|
||||
}
|
||||
|
||||
[SlashCommand("autoplay", "Enables/Disables Autoplay")]
|
||||
[OnlyGuildCheck]
|
||||
[UserInMusicChannelCheck]
|
||||
public async Task AutoplayCommand(InteractionContext ctx)
|
||||
{
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = _audioService.GetPlayer<GuildPlayer>(ctx.Guild.Id);
|
||||
|
||||
player.Autoplay = !player.Autoplay;
|
||||
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"You have set Autoplay to ``{(player.Autoplay ? "Enabled" : "Disabled")}``"));
|
||||
|
||||
}
|
||||
|
||||
[SlashCommand("queue", "Shows the Queue")]
|
||||
[OnlyGuildCheck]
|
||||
public async Task QueueCommand(InteractionContext ctx)
|
||||
{
|
||||
await ctx.DeferAsync(true);
|
||||
GuildPlayer player = _audioService.GetPlayer<GuildPlayer>(ctx.Guild.Id);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("❌ ``Theres currently nothing playing``"));
|
||||
return;
|
||||
}
|
||||
|
||||
LavalinkTrack track = player.CurrentTrack;
|
||||
|
||||
if (track == null)
|
||||
{
|
||||
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("❌ ``Theres currently nothing playing``"));
|
||||
return;
|
||||
}
|
||||
|
||||
QueuePrompt prompt = new QueuePrompt(player);
|
||||
|
||||
_ = prompt.UseAsync(ctx.Interaction, await ctx.GetOriginalResponseAsync());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
294
TomatenMusicCore/Commands/PlayCommandGroup.cs
Normal file
294
TomatenMusicCore/Commands/PlayCommandGroup.cs
Normal file
@@ -0,0 +1,294 @@
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using Lavalink4NET;
|
||||
using Lavalink4NET.Player;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TomatenMusic.Commands.Checks;
|
||||
using TomatenMusic.Music;
|
||||
using TomatenMusic.Music.Entitites;
|
||||
using TomatenMusic.Util;
|
||||
|
||||
namespace TomatenMusic.Commands
|
||||
{
|
||||
|
||||
[SlashCommandGroup("play", "Play a song.")]
|
||||
public class PlayCommandGroup : ApplicationCommandModule
|
||||
{
|
||||
|
||||
[SlashCommandGroup("now", "Plays the specified Song now and prepends the Current song to the Queue.")]
|
||||
public class PlayNowGroup : ApplicationCommandModule
|
||||
{
|
||||
public IAudioService _audioService { get; set; }
|
||||
public ILogger<PlayCommandGroup> _logger { get; set; }
|
||||
public TrackProvider _trackProvider { get; set; }
|
||||
|
||||
public PlayNowGroup(IAudioService audioService, ILogger<PlayCommandGroup> logger, TrackProvider trackProvider)
|
||||
{
|
||||
_audioService = audioService;
|
||||
_logger = logger;
|
||||
_trackProvider = trackProvider;
|
||||
}
|
||||
|
||||
[SlashCommand("query", "Play a song with its youtube/spotify link. (or youtube search)")]
|
||||
[UserInVoiceChannelCheck]
|
||||
[UserInMusicChannelCheck(true)]
|
||||
[OnlyGuildCheck]
|
||||
public async Task PlayQueryCommand(InteractionContext ctx, [Option("query", "The song search query.")] string query)
|
||||
{
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
|
||||
MusicActionResponse response;
|
||||
|
||||
try
|
||||
{
|
||||
response = await _trackProvider.SearchAsync(query);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while resolving your query: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
player = await _audioService.JoinAsync<GuildPlayer>(ctx.Guild.Id, ctx.Member.VoiceState.Channel.Id, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
player = _audioService.GetPlayer<GuildPlayer>(ctx.Guild.Id);
|
||||
|
||||
if (player == null || player.VoiceChannelId == null)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while connecting to your Channel: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (response.isPlaylist)
|
||||
{
|
||||
LavalinkPlaylist playlist = response.Playlist;
|
||||
await player.PlayPlaylistNowAsync(playlist);
|
||||
|
||||
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed(
|
||||
Common.AsEmbed(playlist)
|
||||
));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LavalinkTrack track = response.Track;
|
||||
|
||||
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Playing Now")
|
||||
.AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, 0)));
|
||||
|
||||
await player.PlayNowAsync(response.Track);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while playing your Query: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[SlashCommand("file", "Play a song file. (mp3/mp4)")]
|
||||
[UserInVoiceChannelCheck]
|
||||
[UserInMusicChannelCheck(true)]
|
||||
[OnlyGuildCheck]
|
||||
public async Task PlayFileCommand(InteractionContext ctx, [Option("File", "The File that should be played.")] DiscordAttachment file)
|
||||
{
|
||||
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
|
||||
MusicActionResponse response;
|
||||
|
||||
try
|
||||
{
|
||||
response = await _trackProvider.SearchAsync(new Uri(file.Url));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while resolving your file: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
player = await _audioService.JoinAsync<GuildPlayer>(ctx.Guild.Id, ctx.Member.VoiceState.Channel.Id, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
player = _audioService.GetPlayer<GuildPlayer>(ctx.Guild.Id);
|
||||
if (player == null || player.VoiceChannelId == null)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while connecting to your Channel: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LavalinkTrack track = response.Track;
|
||||
|
||||
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Playing Now")
|
||||
.AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, 0)));
|
||||
|
||||
await player.PlayNowAsync(response.Track);
|
||||
}
|
||||
}
|
||||
|
||||
[SlashCommandGroup("queue", "Queues or plays the Song")]
|
||||
public class PlayQueueGroup : ApplicationCommandModule
|
||||
{
|
||||
public IAudioService _audioService { get; set; }
|
||||
public ILogger<PlayCommandGroup> _logger { get; set; }
|
||||
public TrackProvider _trackProvider { get; set; }
|
||||
|
||||
public PlayQueueGroup(IAudioService audioService, ILogger<PlayCommandGroup> logger, TrackProvider trackProvider)
|
||||
{
|
||||
_audioService = audioService;
|
||||
_logger = logger;
|
||||
_trackProvider = trackProvider;
|
||||
}
|
||||
|
||||
|
||||
[SlashCommand("query", "Play a song with its youtube/spotify link. (or youtube search)")]
|
||||
[UserInVoiceChannelCheck]
|
||||
[UserInMusicChannelCheck(true)]
|
||||
[OnlyGuildCheck]
|
||||
public async Task PlayQueryCommand(InteractionContext ctx, [Option("query", "The song search query.")] string query)
|
||||
{
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
|
||||
MusicActionResponse response;
|
||||
|
||||
try
|
||||
{
|
||||
response = await _trackProvider.SearchAsync(query);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while resolving your query: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
player = await _audioService.JoinAsync<GuildPlayer>(ctx.Guild.Id, ctx.Member.VoiceState.Channel.Id, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
player = _audioService.GetPlayer<GuildPlayer>(ctx.Guild.Id);
|
||||
if (player == null || player.VoiceChannelId == null)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while connecting to your Channel: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (response.isPlaylist)
|
||||
{
|
||||
LavalinkPlaylist playlist = response.Playlist;
|
||||
await player.PlayPlaylistAsync(playlist);
|
||||
|
||||
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed(
|
||||
Common.AsEmbed(playlist)
|
||||
));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LavalinkTrack track = response.Track;
|
||||
|
||||
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(player.State == PlayerState.NotPlaying ? "Now Playing:" : "Added to Queue")
|
||||
.AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, player.State == PlayerState.NotPlaying ? 0 : player.PlayerQueue.Queue.Count + 1)));
|
||||
|
||||
await player.PlayAsync(response.Track);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while playing your Track: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[SlashCommand("file", "Play a song file. (mp3/mp4)")]
|
||||
[UserInVoiceChannelCheck]
|
||||
[UserInMusicChannelCheck(true)]
|
||||
[OnlyGuildCheck]
|
||||
public async Task PlayFileCommand(InteractionContext ctx, [Option("File", "The File that should be played.")] DiscordAttachment file)
|
||||
{
|
||||
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
|
||||
MusicActionResponse response;
|
||||
|
||||
try
|
||||
{
|
||||
response = await _trackProvider.SearchAsync(new Uri(file.Url));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while resolving your file: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
player = await _audioService.JoinAsync<GuildPlayer>(ctx.Guild.Id, ctx.Member.VoiceState.Channel.Id, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
player = _audioService.GetPlayer<GuildPlayer>(ctx.Guild.Id);
|
||||
if (player == null || player.VoiceChannelId == null)
|
||||
{
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while connecting to your Channel: ``{ex.Message}``")
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LavalinkTrack track = response.Track;
|
||||
|
||||
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(player.State == PlayerState.NotPlaying ? "Now Playing:" : "Added to Queue")
|
||||
.AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, player.State == PlayerState.NotPlaying ? 0 : player.PlayerQueue.Queue.Count + 1)));
|
||||
|
||||
await player.PlayAsync(response.Track);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user