- More code cleanup and codestyle updates

- Fixed some possible nullref exceptions
- Methods signatures now have up to 3 parameters before breakaing down each parameter in a separate line
- Method invocations have the same rule, except the first parameter will be in the same line as the invocation to prevent some ugliness when passing lambas as arguments
- Applied many more codestyles
- Extensions folder fully reformatted
This commit is contained in:
Kwoth
2021-12-26 17:28:39 +01:00
parent b85ba177cd
commit d5fd6aae8e
217 changed files with 1017 additions and 1494 deletions

View File

@@ -77,9 +77,7 @@ public sealed class MultimediaTimer : IDisposable
}
private void CallbackInternal(uint uTimerId, uint uMsg, int dwUser, int dw1, int dw2)
{
_callback(_state);
}
=> _callback(_state);
public void Dispose()
{

View File

@@ -424,29 +424,19 @@ public sealed class MusicPlayer : IMusicPlayer
}
public void EnqueueTrack(ITrackInfo track, string queuer)
{
_queue.Enqueue(track, queuer, out _);
}
=> _queue.Enqueue(track, queuer, out _);
public void EnqueueTracks(IEnumerable<ITrackInfo> tracks, string queuer)
{
_queue.EnqueueMany(tracks, queuer);
}
=> _queue.EnqueueMany(tracks, queuer);
public void SetRepeat(PlayerRepeatType type)
{
Repeat = type;
}
=> Repeat = type;
public void ShuffleQueue()
{
_queue.Shuffle(_rng);
}
=> _queue.Shuffle(_rng);
public void Stop()
{
IsStopped = true;
}
=> IsStopped = true;
public void Clear()
{
@@ -484,7 +474,7 @@ public sealed class MusicPlayer : IMusicPlayer
public void SetVolume(int newVolume)
{
var normalizedVolume = newVolume / 100f;
if (normalizedVolume < 0f || normalizedVolume > 1f)
if (normalizedVolume is < 0f or > 1f)
throw new ArgumentOutOfRangeException(nameof(newVolume), "Volume must be in range 0-100");
_volume = normalizedVolume;

View File

@@ -10,10 +10,8 @@ public sealed class RedisTrackCacher : ITrackCacher
private readonly ConnectionMultiplexer _multiplexer;
public RedisTrackCacher(ConnectionMultiplexer multiplexer)
{
_multiplexer = multiplexer;
}
=> _multiplexer = multiplexer;
public async Task<string?> GetOrCreateStreamLink(
string id,
MusicPlatform platform,

View File

@@ -27,9 +27,7 @@ public sealed class VoiceProxy : IVoiceProxy
private VoiceGateway _gateway;
public VoiceProxy(VoiceGateway initial)
{
_gateway = initial;
}
=> _gateway = initial;
public bool SendPcmFrame(VoiceClient vc, Span<byte> data, int length)
{
@@ -86,24 +84,16 @@ public sealed class VoiceProxy : IVoiceProxy
}
public void SetGateway(VoiceGateway gateway)
{
_gateway = gateway;
}
=> _gateway = gateway;
public Task StartSpeakingAsync()
{
return RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.Microphone));
}
=> RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.Microphone));
public Task StopSpeakingAsync()
{
return RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.None));
}
=> RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.None));
public async Task StartGateway()
{
await _gateway.Start();
}
=> await _gateway.Start();
public Task StopGateway()
{

View File

@@ -11,10 +11,8 @@ public sealed partial class Music : NadekoModule<IMusicService>
private readonly ILogCommandService _logService;
public Music(ILogCommandService _logService)
{
this._logService = _logService;
}
=> this._logService = _logService;
private async Task<bool> ValidateAsync()
{
var user = (IGuildUser) ctx.User;
@@ -209,7 +207,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
[RequireContext(ContextType.Guild)]
public async Task Volume(int vol)
{
if (vol < 0 || vol > 100)
if (vol is < 0 or > 100)
{
await ReplyErrorLocalizedAsync(strs.volume_input_invalid);
return;
@@ -313,7 +311,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
return $"`{index + 1}.` {v.PrettyFullName()}";
})
.JoinWith('\n');
.Join('\n');
if (!string.IsNullOrWhiteSpace(add))
desc = add + "\n" + desc;
@@ -353,7 +351,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
var resultsString = videos
.Select((x, i) => $"`{i + 1}.`\n\t{Format.Bold(x.Title)}\n\t{x.Url}")
.JoinWith('\n');
.Join('\n');
var msg = await SendConfirmAsync(resultsString);

View File

@@ -44,10 +44,8 @@ public sealed class AyuVoiceStateService : INService
}
private Task InvokeSendVoiceStateUpdateAsync(ulong guildId, ulong? channelId = null, bool isDeafened = false, bool isMuted = false)
{
// return _voiceStateUpdate(guildId, channelId, isDeafened, isMuted);
return (Task) _sendVoiceStateUpdateMethodInfo.Invoke(_dnetApiClient, new object[] {guildId, channelId, isMuted, isDeafened, null});
}
=> (Task) _sendVoiceStateUpdateMethodInfo.Invoke(_dnetApiClient, new object[] {guildId, channelId, isMuted, isDeafened, null});
private Task SendLeaveVoiceChannelInternalAsync(ulong guildId)
=> InvokeSendVoiceStateUpdateAsync(guildId);

View File

@@ -407,7 +407,7 @@ public sealed class MusicService : IMusicService
public async Task SetVolumeAsync(ulong guildId, int value)
{
if (value < 0 || value > 100)
if (value is < 0 or > 100)
throw new ArgumentOutOfRangeException(nameof(value));
await ModifySettingsInternalAsync(guildId, (settings, newValue) =>
@@ -438,12 +438,10 @@ public sealed class MusicService : IMusicService
}
public Task SetMusicQualityAsync(ulong guildId, QualityPreset preset)
{
return ModifySettingsInternalAsync(guildId, (settings, _) =>
=> ModifySettingsInternalAsync(guildId, (settings, _) =>
{
settings.QualityPreset = preset;
}, preset);
}
#endregion
}

View File

@@ -16,9 +16,7 @@ public sealed partial class YtLoader
};
public YtLoader(IHttpClientFactory httpFactory)
{
_httpFactory = httpFactory;
}
=> _httpFactory = httpFactory;
// public async Task<TrackInfo> LoadTrackByIdAsync(string videoId)
// {
@@ -115,13 +113,13 @@ public sealed partial class YtLoader
private Memory<byte> GetScriptResponseSpan(byte[] response)
{
var responseSpan = response.AsSpan().Slice(140_000);
var responseSpan = response.AsSpan()[140_000..];
var startIndex = responseSpan.IndexOf(YT_RESULT_INITIAL_DATA);
if (startIndex == -1)
return null; // todo future try selecting html
startIndex += YT_RESULT_INITIAL_DATA.Length;
var endIndex = 140_000 + startIndex + responseSpan.Slice(startIndex + 20_000).IndexOf(YT_RESULT_JSON_END) + 20_000;
var endIndex = 140_000 + startIndex + responseSpan[(startIndex + 20_000)..].IndexOf(YT_RESULT_JSON_END) + 20_000;
startIndex += 140_000;
return response.AsMemory(
startIndex,