mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
More target-typed new and redundant paranthesis cleanup
This commit is contained in:
@@ -57,7 +57,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
|
||||
_songBuffer = new PoopyBufferImmortalized(_vc.InputLength);
|
||||
|
||||
_thread = new Thread(async () =>
|
||||
_thread = new(async () =>
|
||||
{
|
||||
await PlayLoop();
|
||||
});
|
||||
@@ -67,28 +67,28 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
private static VoiceClient GetVoiceClient(QualityPreset qualityPreset)
|
||||
=> qualityPreset switch
|
||||
{
|
||||
QualityPreset.Highest => new VoiceClient(
|
||||
QualityPreset.Highest => new(
|
||||
SampleRate._48k,
|
||||
Bitrate._192k,
|
||||
Channels.Two,
|
||||
FrameDelay.Delay20,
|
||||
BitDepthEnum.Float32
|
||||
),
|
||||
QualityPreset.High => new VoiceClient(
|
||||
QualityPreset.High => new(
|
||||
SampleRate._48k,
|
||||
Bitrate._128k,
|
||||
Channels.Two,
|
||||
FrameDelay.Delay40,
|
||||
BitDepthEnum.Float32
|
||||
),
|
||||
QualityPreset.Medium => new VoiceClient(
|
||||
QualityPreset.Medium => new(
|
||||
SampleRate._48k,
|
||||
Bitrate._96k,
|
||||
Channels.Two,
|
||||
FrameDelay.Delay40,
|
||||
BitDepthEnum.UInt16
|
||||
),
|
||||
QualityPreset.Low => new VoiceClient(
|
||||
QualityPreset.Low => new(
|
||||
SampleRate._48k,
|
||||
Bitrate._64k,
|
||||
Channels.Two,
|
||||
@@ -315,7 +315,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
|
||||
private void HandleQueuePostTrack()
|
||||
{
|
||||
if (_forceIndex is int forceIndex)
|
||||
if (_forceIndex is { } forceIndex)
|
||||
{
|
||||
_queue.SetIndex(forceIndex);
|
||||
_forceIndex = null;
|
||||
|
@@ -62,7 +62,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
public MusicQueue()
|
||||
{
|
||||
_index = 0;
|
||||
_tracks = new LinkedList<QueuedTrackInfo>();
|
||||
_tracks = new();
|
||||
}
|
||||
|
||||
public IQueuedTrackInfo Enqueue(ITrackInfo trackInfo, string queuer, out int index)
|
||||
@@ -283,7 +283,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
_index = i;
|
||||
}
|
||||
|
||||
_tracks = new LinkedList<QueuedTrackInfo>(list);
|
||||
_tracks = new(list);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -81,7 +81,7 @@ public sealed class VoiceProxy : IVoiceProxy
|
||||
await Task.Delay(DELAY_ON_ERROR_MILISECONDS);
|
||||
Log.Debug(ex, "Error performing proxy gateway action");
|
||||
}
|
||||
} while (errorCount > 0 && errorCount <= MAX_ERROR_COUNT);
|
||||
} while (errorCount is > 0 and <= MAX_ERROR_COUNT);
|
||||
|
||||
return State != VoiceProxyState.Stopped && errorCount <= MAX_ERROR_COUNT;
|
||||
}
|
||||
@@ -93,12 +93,12 @@ public sealed class VoiceProxy : IVoiceProxy
|
||||
|
||||
public Task StartSpeakingAsync()
|
||||
{
|
||||
return RunGatewayAction((gw) => gw.SendSpeakingAsync(VoiceSpeaking.State.Microphone));
|
||||
return RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.Microphone));
|
||||
}
|
||||
|
||||
public Task StopSpeakingAsync()
|
||||
{
|
||||
return RunGatewayAction((gw) => gw.SendSpeakingAsync(VoiceSpeaking.State.None));
|
||||
return RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.None));
|
||||
}
|
||||
|
||||
public async Task StartGateway()
|
||||
@@ -108,7 +108,7 @@ public sealed class VoiceProxy : IVoiceProxy
|
||||
|
||||
public Task StopGateway()
|
||||
{
|
||||
if(_gateway is VoiceGateway gw)
|
||||
if(_gateway is { } gw)
|
||||
return gw.StopAsync();
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
@@ -37,7 +37,7 @@ public sealed class LocalTrackResolver : ILocalTrackResolver
|
||||
DirectoryInfo dir;
|
||||
try
|
||||
{
|
||||
dir = new DirectoryInfo(dirPath);
|
||||
dir = new(dirPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -32,46 +32,46 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
|
||||
_google = google;
|
||||
|
||||
_ytdlPlaylistOperation =
|
||||
new YtdlOperation("-4 " +
|
||||
"--geo-bypass " +
|
||||
"--encoding UTF8 " +
|
||||
"-f bestaudio " +
|
||||
"-e " +
|
||||
"--get-url " +
|
||||
"--get-id " +
|
||||
"--get-thumbnail " +
|
||||
"--get-duration " +
|
||||
"--no-check-certificate " +
|
||||
"-i " +
|
||||
"--yes-playlist " +
|
||||
"-- \"{0}\"");
|
||||
new("-4 " +
|
||||
"--geo-bypass " +
|
||||
"--encoding UTF8 " +
|
||||
"-f bestaudio " +
|
||||
"-e " +
|
||||
"--get-url " +
|
||||
"--get-id " +
|
||||
"--get-thumbnail " +
|
||||
"--get-duration " +
|
||||
"--no-check-certificate " +
|
||||
"-i " +
|
||||
"--yes-playlist " +
|
||||
"-- \"{0}\"");
|
||||
|
||||
_ytdlIdOperation =
|
||||
new YtdlOperation("-4 " +
|
||||
"--geo-bypass " +
|
||||
"--encoding UTF8 " +
|
||||
"-f bestaudio " +
|
||||
"-e " +
|
||||
"--get-url " +
|
||||
"--get-id " +
|
||||
"--get-thumbnail " +
|
||||
"--get-duration " +
|
||||
"--no-check-certificate " +
|
||||
"-- \"{0}\"");
|
||||
new("-4 " +
|
||||
"--geo-bypass " +
|
||||
"--encoding UTF8 " +
|
||||
"-f bestaudio " +
|
||||
"-e " +
|
||||
"--get-url " +
|
||||
"--get-id " +
|
||||
"--get-thumbnail " +
|
||||
"--get-duration " +
|
||||
"--no-check-certificate " +
|
||||
"-- \"{0}\"");
|
||||
|
||||
_ytdlSearchOperation =
|
||||
new YtdlOperation("-4 " +
|
||||
"--geo-bypass " +
|
||||
"--encoding UTF8 " +
|
||||
"-f bestaudio " +
|
||||
"-e " +
|
||||
"--get-url " +
|
||||
"--get-id " +
|
||||
"--get-thumbnail " +
|
||||
"--get-duration " +
|
||||
"--no-check-certificate " +
|
||||
"--default-search " +
|
||||
"\"ytsearch:\" -- \"{0}\"");
|
||||
new("-4 " +
|
||||
"--geo-bypass " +
|
||||
"--encoding UTF8 " +
|
||||
"-f bestaudio " +
|
||||
"-e " +
|
||||
"--get-url " +
|
||||
"--get-id " +
|
||||
"--get-thumbnail " +
|
||||
"--get-duration " +
|
||||
"--no-check-certificate " +
|
||||
"--default-search " +
|
||||
"\"ytsearch:\" -- \"{0}\"");
|
||||
}
|
||||
|
||||
private readonly struct YtTrackData
|
||||
@@ -114,7 +114,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
|
||||
? dataArray[3].Trim()
|
||||
: string.Empty;
|
||||
|
||||
return new YtTrackData(
|
||||
return new(
|
||||
dataArray[0],
|
||||
dataArray[1],
|
||||
thumbnail,
|
||||
@@ -190,7 +190,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
return DataToInfo(new YtTrackData(
|
||||
return DataToInfo(new(
|
||||
cachedData.Title,
|
||||
cachedData.Id,
|
||||
cachedData.Thumbnail,
|
||||
@@ -337,7 +337,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
|
||||
return trackInfo;
|
||||
}
|
||||
|
||||
return DataToInfo(new YtTrackData(
|
||||
return DataToInfo(new(
|
||||
cachedData.Title,
|
||||
cachedData.Id,
|
||||
cachedData.Thumbnail,
|
||||
|
@@ -110,7 +110,7 @@ public sealed partial class Music
|
||||
mpl = uow.MusicPlaylists.GetWithSongs(id);
|
||||
}
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(page, (cur) =>
|
||||
await ctx.SendPaginatedConfirmAsync(page, cur =>
|
||||
{
|
||||
var i = 0;
|
||||
var str = string.Join("\n", mpl.Songs
|
||||
@@ -146,7 +146,7 @@ public sealed partial class Music
|
||||
MusicPlaylist playlist;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
playlist = new MusicPlaylist
|
||||
playlist = new()
|
||||
{
|
||||
Name = name,
|
||||
Author = ctx.User.Username,
|
||||
|
@@ -180,7 +180,7 @@ public sealed class AyuVoiceStateService : INService
|
||||
|
||||
var current = _voiceProxies.AddOrUpdate(
|
||||
guildId,
|
||||
(gid) => new VoiceProxy(CreateVoiceGatewayLocal()),
|
||||
gid => new VoiceProxy(CreateVoiceGatewayLocal()),
|
||||
(gid, currentProxy) =>
|
||||
{
|
||||
_ = currentProxy.StopGateway();
|
||||
|
@@ -46,9 +46,9 @@ public sealed class MusicService : IMusicService
|
||||
_ytLoader = ytLoader;
|
||||
_eb = eb;
|
||||
|
||||
_players = new ConcurrentDictionary<ulong, IMusicPlayer>();
|
||||
_players = new();
|
||||
_outputChannels = new ConcurrentDictionary<ulong, (ITextChannel, ITextChannel?)>();
|
||||
_settings = new ConcurrentDictionary<ulong, MusicPlayerSettings>();
|
||||
_settings = new();
|
||||
|
||||
_client.LeftGuild += ClientOnLeftGuild;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public sealed class MusicService : IMusicService
|
||||
var settings = await GetSettingsInternalAsync(guildId);
|
||||
|
||||
ITextChannel? overrideChannel = null;
|
||||
if (settings.MusicChannelId is ulong channelId)
|
||||
if (settings.MusicChannelId is { } channelId)
|
||||
{
|
||||
overrideChannel = _client.GetGuild(guildId)?.GetTextChannel(channelId);
|
||||
|
||||
@@ -170,7 +170,7 @@ public sealed class MusicService : IMusicService
|
||||
|
||||
mp.SetRepeat(settings.PlayerRepeat);
|
||||
|
||||
if (settings.Volume >= 0 && settings.Volume <= 100)
|
||||
if (settings.Volume is >= 0 and <= 100)
|
||||
{
|
||||
mp.SetVolume(settings.Volume);
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public sealed class MusicService : IMusicService
|
||||
}
|
||||
|
||||
private Func<IMusicPlayer, Task> OnQueueStopped(ulong guildId)
|
||||
=> (mp) =>
|
||||
=> mp =>
|
||||
{
|
||||
if (_settings.TryGetValue(guildId, out var settings))
|
||||
{
|
||||
|
Reference in New Issue
Block a user