mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
* add: .prunecancel to cancel active prunes
* change: .qs improved with thumbnails * change: .prune now reports progress * dev: DryIoc replacing Ninject
This commit is contained in:
@@ -110,10 +110,10 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
try
|
||||
{
|
||||
var embed = _sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithAuthor(GetText(strs.queued_track) + " #" + (index + 1), MUSIC_ICON_URL)
|
||||
.WithDescription($"{trackInfo.PrettyName()}\n{GetText(strs.queue)} ")
|
||||
.WithFooter(trackInfo.Platform.ToString());
|
||||
.WithOkColor()
|
||||
.WithAuthor(GetText(strs.queued_track) + " #" + (index + 1), MUSIC_ICON_URL)
|
||||
.WithDescription($"{trackInfo.PrettyName()}\n{GetText(strs.queue)} ")
|
||||
.WithFooter(trackInfo.Platform.ToString());
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(trackInfo.Thumbnail))
|
||||
embed.WithThumbnailUrl(trackInfo.Thumbnail);
|
||||
@@ -315,11 +315,13 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
desc = add + "\n" + desc;
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
.WithAuthor(GetText(strs.player_queue(curPage + 1, (tracks.Count / LQ_ITEMS_PER_PAGE) + 1)),
|
||||
MUSIC_ICON_URL)
|
||||
.WithDescription(desc)
|
||||
.WithFooter($" {mp.PrettyVolume()} | 🎶 {tracks.Count} | ⌛ {mp.PrettyTotalTime()} ")
|
||||
.WithOkColor();
|
||||
.WithAuthor(
|
||||
GetText(strs.player_queue(curPage + 1, (tracks.Count / LQ_ITEMS_PER_PAGE) + 1)),
|
||||
MUSIC_ICON_URL)
|
||||
.WithDescription(desc)
|
||||
.WithFooter(
|
||||
$" {mp.PrettyVolume()} | 🎶 {tracks.Count} | ⌛ {mp.PrettyTotalTime()} ")
|
||||
.WithOkColor();
|
||||
|
||||
return embed;
|
||||
}
|
||||
@@ -349,13 +351,21 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
return;
|
||||
}
|
||||
|
||||
var resultsString = videos.Select((x, i) => $"`{i + 1}.`\n\t{Format.Bold(x.Title)}\n\t{x.Url}").Join('\n');
|
||||
|
||||
var msg = await Response().Confirm(resultsString).SendAsync();
|
||||
var embeds = videos.Select((x, i) => _sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithThumbnailUrl(x.Thumbnail)
|
||||
.WithDescription($"`{i + 1}.` {Format.Bold(x.Title)}\n\t{x.Url}"))
|
||||
.ToList();
|
||||
|
||||
var msg = await Response()
|
||||
.Text(strs.queue_search_results)
|
||||
.Embeds(embeds)
|
||||
.SendAsync();
|
||||
|
||||
try
|
||||
{
|
||||
var input = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id);
|
||||
var input = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id, str => int.TryParse(str, out _));
|
||||
if (input is null || !int.TryParse(input, out var index) || (index -= 1) < 0 || index >= videos.Count)
|
||||
{
|
||||
_logService.AddDeleteIgnore(msg.Id);
|
||||
@@ -415,10 +425,10 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
}
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
.WithAuthor(GetText(strs.removed_track) + " #" + index, MUSIC_ICON_URL)
|
||||
.WithDescription(track.PrettyName())
|
||||
.WithFooter(track.PrettyInfo())
|
||||
.WithErrorColor();
|
||||
.WithAuthor(GetText(strs.removed_track) + " #" + index, MUSIC_ICON_URL)
|
||||
.WithDescription(track.PrettyName())
|
||||
.WithFooter(track.PrettyInfo())
|
||||
.WithErrorColor();
|
||||
|
||||
await _service.SendToOutputAsync(ctx.Guild.Id, embed);
|
||||
}
|
||||
@@ -583,11 +593,11 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
}
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
.WithTitle(track.Title.TrimTo(65))
|
||||
.WithAuthor(GetText(strs.track_moved), MUSIC_ICON_URL)
|
||||
.AddField(GetText(strs.from_position), $"#{from + 1}", true)
|
||||
.AddField(GetText(strs.to_position), $"#{to + 1}", true)
|
||||
.WithOkColor();
|
||||
.WithTitle(track.Title.TrimTo(65))
|
||||
.WithAuthor(GetText(strs.track_moved), MUSIC_ICON_URL)
|
||||
.AddField(GetText(strs.from_position), $"#{from + 1}", true)
|
||||
.AddField(GetText(strs.to_position), $"#{to + 1}", true)
|
||||
.WithOkColor();
|
||||
|
||||
if (Uri.IsWellFormedUriString(track.Url, UriKind.Absolute))
|
||||
embed.WithUrl(track.Url);
|
||||
@@ -642,12 +652,12 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
return;
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithAuthor(GetText(strs.now_playing), MUSIC_ICON_URL)
|
||||
.WithDescription(currentTrack.PrettyName())
|
||||
.WithThumbnailUrl(currentTrack.Thumbnail)
|
||||
.WithFooter(
|
||||
$"{mp.PrettyVolume()} | {mp.PrettyTotalTime()} | {currentTrack.Platform} | {currentTrack.Queuer}");
|
||||
.WithOkColor()
|
||||
.WithAuthor(GetText(strs.now_playing), MUSIC_ICON_URL)
|
||||
.WithDescription(currentTrack.PrettyName())
|
||||
.WithThumbnailUrl(currentTrack.Thumbnail)
|
||||
.WithFooter(
|
||||
$"{mp.PrettyVolume()} | {mp.PrettyTotalTime()} | {currentTrack.Platform} | {currentTrack.Queuer}");
|
||||
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace NadekoBot.Modules.Music.Services;
|
||||
|
||||
public interface IMusicService : IPlaceholderProvider
|
||||
public interface IMusicService
|
||||
{
|
||||
/// <summary>
|
||||
/// Leave voice channel in the specified guild if it's connected to one
|
||||
@@ -24,7 +24,7 @@ public interface IMusicService : IPlaceholderProvider
|
||||
Task EnqueueDirectoryAsync(IMusicPlayer mp, string dirPath, string queuer);
|
||||
Task<IUserMessage?> SendToOutputAsync(ulong guildId, EmbedBuilder embed);
|
||||
Task<bool> PlayAsync(ulong guildId, ulong voiceChannelId);
|
||||
Task<IList<(string Title, string Url)>> SearchVideosAsync(string query);
|
||||
Task<IList<(string Title, string Url, string Thumbnail)>> SearchVideosAsync(string query);
|
||||
Task<bool> SetMusicChannelAsync(ulong guildId, ulong? channelId);
|
||||
Task SetRepeatAsync(ulong guildId, PlayerRepeatType repeatType);
|
||||
Task SetVolumeAsync(ulong guildId, int value);
|
||||
|
@@ -4,7 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace NadekoBot.Modules.Music.Services;
|
||||
|
||||
public sealed class MusicService : IMusicService
|
||||
public sealed class MusicService : IMusicService, IPlaceholderProvider
|
||||
{
|
||||
private readonly AyuVoiceStateService _voiceStateService;
|
||||
private readonly ITrackResolveProvider _trackResolveProvider;
|
||||
@@ -233,23 +233,23 @@ public sealed class MusicService : IMusicService
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<IList<(string Title, string Url)>> SearchYtLoaderVideosAsync(string query)
|
||||
private async Task<IList<(string Title, string Url, string Thumb)>> SearchYtLoaderVideosAsync(string query)
|
||||
{
|
||||
var result = await _ytLoader.LoadResultsAsync(query);
|
||||
return result.Select(x => (x.Title, x.Url)).ToList();
|
||||
return result.Select(x => (x.Title, x.Url, x.Thumb)).ToList();
|
||||
}
|
||||
|
||||
private async Task<IList<(string Title, string Url)>> SearchGoogleApiVideosAsync(string query)
|
||||
private async Task<IList<(string Title, string Url, string Thumb)>> SearchGoogleApiVideosAsync(string query)
|
||||
{
|
||||
var result = await _googleApiService.GetVideoInfosByKeywordAsync(query, 5);
|
||||
return result.Select(x => (x.Name, x.Url)).ToList();
|
||||
return result.Select(x => (x.Name, x.Url, x.Thumbnail)).ToList();
|
||||
}
|
||||
|
||||
public async Task<IList<(string Title, string Url)>> SearchVideosAsync(string query)
|
||||
public async Task<IList<(string Title, string Url, string Thumbnail)>> SearchVideosAsync(string query)
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<(string, string)> videos = await SearchYtLoaderVideosAsync(query);
|
||||
IList<(string, string, string)> videos = await SearchYtLoaderVideosAsync(query);
|
||||
if (videos.Count > 0)
|
||||
return videos;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ public sealed class MusicService : IMusicService
|
||||
ex.Message);
|
||||
}
|
||||
|
||||
return Array.Empty<(string, string)>();
|
||||
return Array.Empty<(string, string, string)>();
|
||||
}
|
||||
|
||||
private string GetText(ulong guildId, LocStr str)
|
||||
@@ -434,4 +434,4 @@ public sealed class MusicService : IMusicService
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,7 @@ public sealed partial class YtLoader
|
||||
{
|
||||
public abstract string Url { get; }
|
||||
public abstract string Title { get; }
|
||||
public abstract string Thumb { get; }
|
||||
public abstract TimeSpan Duration { get; }
|
||||
}
|
||||
|
||||
@@ -55,13 +56,15 @@ public sealed partial class YtLoader
|
||||
private const string BASE_YOUTUBE_URL = "https://youtube.com/watch?v=";
|
||||
public override string Url { get; }
|
||||
public override string Title { get; }
|
||||
public override string Thumb { get; }
|
||||
public override TimeSpan Duration { get; }
|
||||
|
||||
private readonly string _videoId;
|
||||
|
||||
public YtTrackInfo(string title, string videoId, TimeSpan duration)
|
||||
public YtTrackInfo(string title, string videoId, string thumb, TimeSpan duration)
|
||||
{
|
||||
Title = title;
|
||||
Thumb = thumb;
|
||||
Url = BASE_YOUTUBE_URL + videoId;
|
||||
Duration = duration;
|
||||
|
||||
|
@@ -5,7 +5,7 @@ using System.Text.Json;
|
||||
|
||||
namespace NadekoBot.Modules.Music.Services;
|
||||
|
||||
public sealed partial class YtLoader
|
||||
public sealed partial class YtLoader : INService
|
||||
{
|
||||
private static readonly byte[] _ytResultInitialData = Encoding.UTF8.GetBytes("var ytInitialData = ");
|
||||
private static readonly byte[] _ytResultJsonEnd = Encoding.UTF8.GetBytes(";<");
|
||||
@@ -93,7 +93,7 @@ public sealed partial class YtLoader
|
||||
continue;
|
||||
|
||||
var videoId = elem.GetProperty("videoId").GetString();
|
||||
// var thumb = elem.GetProperty("thumbnail").GetProperty("thumbnails")[0].GetProperty("url").GetString();
|
||||
var thumb = elem.GetProperty("thumbnail").GetProperty("thumbnails")[0].GetProperty("url").GetString();
|
||||
var title = elem.GetProperty("title").GetProperty("runs")[0].GetProperty("text").GetString();
|
||||
var durationString = elem.GetProperty("lengthText").GetProperty("simpleText").GetString();
|
||||
|
||||
@@ -106,7 +106,7 @@ public sealed partial class YtLoader
|
||||
continue;
|
||||
}
|
||||
|
||||
tracks.Add(new YtTrackInfo(title, videoId, duration));
|
||||
tracks.Add(new YtTrackInfo(title, videoId, thumb, duration));
|
||||
if (tracks.Count >= 5)
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user