mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
- Updated editorconfig rules to hopefully look a bit nicer.
- Removed configureawait(false) from everywhere as it doesnt' do anything in a console app and just makes the code look ugly - Started using .WhenAll extension instead of Task.WhenAll to make it look nicer when chaining methods
This commit is contained in:
@@ -398,12 +398,12 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
if (IsKilled)
|
||||
break;
|
||||
|
||||
var queueTasks = chunk.Select(async data =>
|
||||
await chunk.Select(async data =>
|
||||
{
|
||||
var (query, platform) = data;
|
||||
try
|
||||
{
|
||||
await TryEnqueueTrackAsync(query, queuer, false, forcePlatform: platform).ConfigureAwait(false);
|
||||
await TryEnqueueTrackAsync(query, queuer, false, forcePlatform: platform);
|
||||
errorCount = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -411,9 +411,8 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
Log.Warning(ex, "Error resolving {MusicPlatform} Track {TrackQuery}", platform, query);
|
||||
++errorCount;
|
||||
}
|
||||
});
|
||||
}).WhenAll();
|
||||
|
||||
await Task.WhenAll(queueTasks);
|
||||
await Task.Delay(1000);
|
||||
|
||||
// > 10 errors in a row = kill
|
||||
|
@@ -60,8 +60,9 @@ public sealed class LocalTrackResolver : ILocalTrackResolver
|
||||
|
||||
var fileChunks = files.Skip(1).Chunk(10);
|
||||
foreach (var chunk in fileChunks)
|
||||
{
|
||||
var part = await Task.WhenAll(chunk.Select(x => ResolveByQueryAsync(x.FullName)));
|
||||
{
|
||||
var part = await chunk.Select(x => ResolveByQueryAsync(x.FullName))
|
||||
.WhenAll();
|
||||
|
||||
// nullable reference types being annoying
|
||||
foreach (var p in part)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace NadekoBot.Modules.Music.Resolvers;
|
||||
@@ -17,7 +17,7 @@ public class RadioResolver : IRadioResolver
|
||||
public async Task<ITrackInfo> ResolveByQueryAsync(string query)
|
||||
{
|
||||
if (IsRadioLink(query))
|
||||
query = await HandleStreamContainers(query).ConfigureAwait(false);
|
||||
query = await HandleStreamContainers(query);
|
||||
|
||||
return new SimpleTrackInfo(
|
||||
query.TrimTo(50),
|
||||
@@ -44,7 +44,7 @@ public class RadioResolver : IRadioResolver
|
||||
try
|
||||
{
|
||||
using var http = new HttpClient();
|
||||
file = await http.GetStringAsync(query).ConfigureAwait(false);
|
||||
file = await http.GetStringAsync(query);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@@ -37,7 +37,7 @@ public sealed class SoundcloudResolver : ISoundcloudResolver
|
||||
.Select(VideoModelToCachedData)
|
||||
.ToList();
|
||||
|
||||
await Task.WhenAll(cachableTracks.Select(_trackCacher.CacheTrackDataAsync));
|
||||
await cachableTracks.Select(_trackCacher.CacheTrackDataAsync).WhenAll();
|
||||
foreach(var info in cachableTracks.Select(CachableDataToTrackInfo))
|
||||
{
|
||||
yield return info;
|
||||
@@ -77,8 +77,8 @@ public sealed class SoundcloudResolver : ISoundcloudResolver
|
||||
return CachableDataToTrackInfo(cached);
|
||||
|
||||
var svideo = !IsSoundCloudLink(query)
|
||||
? await _sc.GetVideoByQueryAsync(query).ConfigureAwait(false)
|
||||
: await _sc.ResolveVideoAsync(query).ConfigureAwait(false);
|
||||
? await _sc.GetVideoByQueryAsync(query)
|
||||
: await _sc.ResolveVideoAsync(query);
|
||||
|
||||
if (svideo is null)
|
||||
return null;
|
||||
|
@@ -110,7 +110,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
if (!string.IsNullOrWhiteSpace(trackInfo.Thumbnail))
|
||||
embed.WithThumbnailUrl(trackInfo.Thumbnail);
|
||||
|
||||
var queuedMessage = await _service.SendToOutputAsync(ctx.Guild.Id, embed).ConfigureAwait(false);
|
||||
var queuedMessage = await _service.SendToOutputAsync(ctx.Guild.Id, embed);
|
||||
queuedMessage?.DeleteAfter(10, _logService);
|
||||
if (mp.IsStopped)
|
||||
{
|
||||
@@ -346,7 +346,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
if (videos is null || videos.Count == 0)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.song_not_found).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.song_not_found);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
try
|
||||
{
|
||||
var input = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id).ConfigureAwait(false);
|
||||
var input = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id);
|
||||
if (input is null
|
||||
|| !int.TryParse(input, out var index)
|
||||
|| (index -= 1) < 0
|
||||
@@ -367,7 +367,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
_logService.AddDeleteIgnore(msg.Id);
|
||||
try
|
||||
{
|
||||
await msg.DeleteAsync().ConfigureAwait(false);
|
||||
await msg.DeleteAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -384,7 +384,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
_logService.AddDeleteIgnore(msg.Id);
|
||||
try
|
||||
{
|
||||
await msg.DeleteAsync().ConfigureAwait(false);
|
||||
await msg.DeleteAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -399,7 +399,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
{
|
||||
if (index < 1)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.removed_song_error).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.removed_song_error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
if (!mp.TryRemoveTrackAt(index - 1, out var song))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.removed_song_error).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.removed_song_error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
}
|
||||
|
||||
mp.Clear();
|
||||
await ReplyConfirmLocalizedAsync(strs.queue_cleared).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.queue_cleared);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -563,7 +563,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
await _service.EnqueueDirectoryAsync(mp, dirPath, ctx.User.ToString());
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.dir_queue_complete).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.dir_queue_complete);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -572,7 +572,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
{
|
||||
if (--from < 0 || --to < 0 || from == to)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.invalid_input).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.invalid_input);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -590,7 +590,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
var track = mp.MoveTrack(from, to);
|
||||
if (track is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.invalid_input).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.invalid_input);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -604,7 +604,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
if (Uri.IsWellFormedUriString(track.Url, UriKind.Absolute))
|
||||
embed.WithUrl(track.Url);
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -661,7 +661,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
var queuedCount = await _service.EnqueueYoutubePlaylistAsync(mp, playlistQuery, ctx.User.ToString());
|
||||
if (queuedCount == 0)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.no_search_results).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.no_search_results);
|
||||
return;
|
||||
}
|
||||
await ctx.OkAsync();
|
||||
@@ -688,7 +688,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
.WithThumbnailUrl(currentTrack.Thumbnail)
|
||||
.WithFooter($"{mp.PrettyVolume()} | {mp.PrettyTotalTime()} | {currentTrack.Platform} | {currentTrack.Queuer}");
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Modules.Music.Services;
|
||||
@@ -55,7 +55,7 @@ public sealed partial class Music
|
||||
GetText(strs.playlists(r.Id, r.Name, r.Author, r.Songs.Count)))))
|
||||
.WithOkColor();
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -84,9 +84,9 @@ public sealed partial class Music
|
||||
}
|
||||
|
||||
if (!success)
|
||||
await ReplyErrorLocalizedAsync(strs.playlist_delete_fail).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.playlist_delete_fail);
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.playlist_deleted).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.playlist_deleted);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -113,7 +113,7 @@ public sealed partial class Music
|
||||
.WithTitle($"\"{mpl.Name}\" by {mpl.Author}")
|
||||
.WithOkColor()
|
||||
.WithDescription(str);
|
||||
}, mpl.Songs.Count, 20).ConfigureAwait(false);
|
||||
}, mpl.Songs.Count, 20);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -202,7 +202,7 @@ public sealed partial class Music
|
||||
|
||||
if (mpl is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.playlist_id_not_found).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.playlist_id_not_found);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -210,8 +210,7 @@ public sealed partial class Music
|
||||
try
|
||||
{
|
||||
msg = await ctx.Channel
|
||||
.SendMessageAsync(GetText(strs.attempting_to_queue(Format.Bold(mpl.Songs.Count.ToString()))))
|
||||
.ConfigureAwait(false);
|
||||
.SendMessageAsync(GetText(strs.attempting_to_queue(Format.Bold(mpl.Songs.Count.ToString()))));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using System.Reflection;
|
||||
using Ayu.Discord.Voice;
|
||||
|
||||
@@ -92,7 +92,7 @@ public sealed class AyuVoiceStateService : INService
|
||||
public async Task LeaveVoiceChannel(ulong guildId)
|
||||
{
|
||||
var gwLock = GetVoiceGatewayLock(guildId);
|
||||
await gwLock.WaitAsync().ConfigureAwait(false);
|
||||
await gwLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
await LeaveVoiceChannelInternalAsync(guildId);
|
||||
@@ -198,7 +198,7 @@ public sealed class AyuVoiceStateService : INService
|
||||
public async Task<IVoiceProxy> JoinVoiceChannel(ulong guildId, ulong channelId, bool forceReconnect = true)
|
||||
{
|
||||
var gwLock = GetVoiceGatewayLock(guildId);
|
||||
await gwLock.WaitAsync().ConfigureAwait(false);
|
||||
await gwLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
await LeaveVoiceChannelInternalAsync(guildId);
|
||||
|
Reference in New Issue
Block a user