Kotz's editorconfig styles slightly modified. Target typed new usage. Brackets in expressions used for clarity.

This commit is contained in:
Kwoth
2021-12-26 02:52:09 +01:00
parent 68741ec484
commit d18f9429c6
172 changed files with 921 additions and 494 deletions

View File

@@ -12,7 +12,7 @@ public sealed class MusicPlayer : IMusicPlayer
{
private delegate void AdjustVolumeDelegate(Span<byte> data, float volume);
private AdjustVolumeDelegate AdjustVolume;
private readonly AdjustVolumeDelegate AdjustVolume;
private readonly VoiceClient _vc;
public bool IsKilled { get; private set; }
@@ -369,7 +369,7 @@ public sealed class MusicPlayer : IMusicPlayer
for (var i = 0; i < samples.Length; i++)
{
ref var sample = ref samples[i];
sample = (float) (sample * volume);
sample = sample * volume;
}
}

View File

@@ -55,7 +55,7 @@ public sealed partial class MusicQueue : IMusicQueue
}
}
private readonly object locker = new object();
private readonly object locker = new();
public MusicQueue()
{

View File

@@ -9,7 +9,7 @@ public sealed class SimpleTrackInfo : ITrackInfo
public TimeSpan Duration { get; }
public MusicPlatform Platform { get; }
public string? StreamUrl { get; }
public ValueTask<string?> GetStreamUrl() => new ValueTask<string?>(StreamUrl);
public ValueTask<string?> GetStreamUrl() => new(StreamUrl);
public SimpleTrackInfo(string title, string url, string thumbnail, TimeSpan duration,
MusicPlatform platform, string streamUrl)

View File

@@ -4,10 +4,10 @@ namespace NadekoBot.Modules.Music.Resolvers;
public class RadioResolver : IRadioResolver
{
private readonly Regex plsRegex = new Regex("File1=(?<url>.*?)\\n", RegexOptions.Compiled);
private readonly Regex m3uRegex = new Regex("(?<url>^[^#].*)", RegexOptions.Compiled | RegexOptions.Multiline);
private readonly Regex asxRegex = new Regex("<ref href=\"(?<url>.*?)\"", RegexOptions.Compiled);
private readonly Regex xspfRegex = new Regex("<location>(?<url>.*?)</location>", RegexOptions.Compiled);
private readonly Regex plsRegex = new("File1=(?<url>.*?)\\n", RegexOptions.Compiled);
private readonly Regex m3uRegex = new("(?<url>^[^#].*)", RegexOptions.Compiled | RegexOptions.Multiline);
private readonly Regex asxRegex = new("<ref href=\"(?<url>.*?)\"", RegexOptions.Compiled);
private readonly Regex xspfRegex = new("<location>(?<url>.*?)</location>", RegexOptions.Compiled);
public RadioResolver()
{

View File

@@ -10,7 +10,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
{"ss", "m\\:ss", "mm\\:ss", "h\\:mm\\:ss", "hh\\:mm\\:ss", "hhh\\:mm\\:ss"};
public Regex YtVideoIdRegex { get; }
= new Regex(
= new(
@"(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\?(?:\S*?&?v\=))|youtu\.be\/)(?<id>[a-zA-Z0-9_-]{6,11})",
RegexOptions.Compiled
);
@@ -21,7 +21,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
private readonly YtdlOperation _ytdlIdOperation;
private readonly YtdlOperation _ytdlSearchOperation;
private IGoogleApiService _google;
private readonly IGoogleApiService _google;
public YtdlYoutubeResolver(ITrackCacher trackCacher, IGoogleApiService google)
{
@@ -136,7 +136,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
async () => await ExtractNewStreamUrlAsync(id)
);
private static readonly Regex expiryRegex = new Regex(@"(?:[\?\&]expire\=(?<timestamp>\d+))");
private static readonly Regex expiryRegex = new(@"(?:[\?\&]expire\=(?<timestamp>\d+))");
private static TimeSpan GetExpiry(string streamUrl)
{
var match = expiryRegex.Match(streamUrl);
@@ -205,8 +205,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
);
private static readonly Regex _simplePlaylistRegex
= new Regex(@"&list=(?<id>[\w\-]{12,})", RegexOptions.Compiled);
private static readonly Regex _simplePlaylistRegex = new(@"&list=(?<id>[\w\-]{12,})", RegexOptions.Compiled);
public async IAsyncEnumerable<ITrackInfo> ResolveTracksByPlaylistIdAsync(string playlistId)
{

View File

@@ -36,7 +36,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
return true;
}
private static readonly SemaphoreSlim voiceChannelLock = new SemaphoreSlim(1, 1);
private static readonly SemaphoreSlim voiceChannelLock = new(1, 1);
private async Task EnsureBotInVoiceChannelAsync(ulong voiceChannelId, IGuildUser botUser = null)
{
botUser ??= await ctx.Guild.GetCurrentUserAsync();
@@ -253,7 +253,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
return;
}
await ListQueue(mp.CurrentIndex / LQ_ITEMS_PER_PAGE + 1);
await ListQueue((mp.CurrentIndex / LQ_ITEMS_PER_PAGE) + 1);
}
// list queue, specify page
@@ -319,7 +319,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
desc = add + "\n" + desc;
var embed = _eb.Create()
.WithAuthor(GetText(strs.player_queue(curPage + 1, tracks.Count / LQ_ITEMS_PER_PAGE + 1)),
.WithAuthor(GetText(strs.player_queue(curPage + 1, (tracks.Count / LQ_ITEMS_PER_PAGE) + 1)),
MusicIconUrl)
.WithDescription(desc)
.WithFooter($" {mp.PrettyVolume()} | 🎶 {tracks.Count} | ⌛ {mp.PrettyTotalTime()} ")

View File

@@ -158,7 +158,7 @@ public sealed partial class Music
}
private static readonly SemaphoreSlim _playlistLock = new SemaphoreSlim(1, 1);
private static readonly SemaphoreSlim _playlistLock = new(1, 1);
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]

View File

@@ -8,8 +8,8 @@ public sealed class AyuVoiceStateService : INService
// public delegate Task VoiceProxyUpdatedDelegate(ulong guildId, IVoiceProxy proxy);
// public event VoiceProxyUpdatedDelegate OnVoiceProxyUpdate = delegate { return Task.CompletedTask; };
private readonly ConcurrentDictionary<ulong, IVoiceProxy> _voiceProxies = new ConcurrentDictionary<ulong, IVoiceProxy>();
private readonly ConcurrentDictionary<ulong, SemaphoreSlim> _voiceGatewayLocks = new ConcurrentDictionary<ulong, SemaphoreSlim>();
private readonly ConcurrentDictionary<ulong, IVoiceProxy> _voiceProxies = new();
private readonly ConcurrentDictionary<ulong, SemaphoreSlim> _voiceGatewayLocks = new();
private readonly DiscordSocketClient _client;
private readonly MethodInfo _sendVoiceStateUpdateMethodInfo;
@@ -167,7 +167,7 @@ public sealed class AyuVoiceStateService : INService
var voiceServerData = await voiceServerUpdatedSource.Task;
VoiceGateway CreateVoiceGatewayLocal() =>
new VoiceGateway(
new(
guildId,
_currentUserId,
session,