mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
More common refactorings like renaming variables, removing empty statements and unused variables, etc
This commit is contained in:
@@ -16,15 +16,15 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
Q = 2, Queue = 2, Playlist = 2, Pl = 2
|
||||
}
|
||||
|
||||
public const string MusicIconUrl = "http://i.imgur.com/nhKS3PT.png";
|
||||
public const string MUSIC_ICON_URL = "http://i.imgur.com/nhKS3PT.png";
|
||||
|
||||
private const int LQ_ITEMS_PER_PAGE = 9;
|
||||
|
||||
private static readonly SemaphoreSlim voiceChannelLock = new(1, 1);
|
||||
private static readonly SemaphoreSlim _voiceChannelLock = new(1, 1);
|
||||
private readonly ILogCommandService _logService;
|
||||
|
||||
public Music(ILogCommandService _logService)
|
||||
=> this._logService = _logService;
|
||||
public Music(ILogCommandService logService)
|
||||
=> _logService = logService;
|
||||
|
||||
private async Task<bool> ValidateAsync()
|
||||
{
|
||||
@@ -50,7 +50,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
private async Task EnsureBotInVoiceChannelAsync(ulong voiceChannelId, IGuildUser botUser = null)
|
||||
{
|
||||
botUser ??= await ctx.Guild.GetCurrentUserAsync();
|
||||
await voiceChannelLock.WaitAsync();
|
||||
await _voiceChannelLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (botUser.VoiceChannel?.Id is null || !_service.TryGetMusicPlayer(ctx.Guild.Id, out _))
|
||||
@@ -58,7 +58,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
}
|
||||
finally
|
||||
{
|
||||
voiceChannelLock.Release();
|
||||
_voiceChannelLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
.WithAuthor(GetText(strs.queued_song) + " #" + (index + 1), MusicIconUrl)
|
||||
.WithAuthor(GetText(strs.queued_song) + " #" + (index + 1), MUSIC_ICON_URL)
|
||||
.WithDescription($"{trackInfo.PrettyName()}\n{GetText(strs.queue)} ")
|
||||
.WithFooter(trackInfo.Platform.ToString());
|
||||
|
||||
@@ -272,7 +272,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
return;
|
||||
}
|
||||
|
||||
IEmbedBuilder printAction(int curPage)
|
||||
IEmbedBuilder PrintAction(int curPage)
|
||||
{
|
||||
var desc = string.Empty;
|
||||
var current = mp.GetCurrentTrack(out var currentIndex);
|
||||
@@ -317,7 +317,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
var embed = _eb.Create()
|
||||
.WithAuthor(GetText(strs.player_queue(curPage + 1, (tracks.Count / LQ_ITEMS_PER_PAGE) + 1)),
|
||||
MusicIconUrl)
|
||||
MUSIC_ICON_URL)
|
||||
.WithDescription(desc)
|
||||
.WithFooter($" {mp.PrettyVolume()} | 🎶 {tracks.Count} | ⌛ {mp.PrettyTotalTime()} ")
|
||||
.WithOkColor();
|
||||
@@ -325,7 +325,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
return embed;
|
||||
}
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(page, printAction, tracks.Count, LQ_ITEMS_PER_PAGE, false);
|
||||
await ctx.SendPaginatedConfirmAsync(page, PrintAction, tracks.Count, LQ_ITEMS_PER_PAGE, false);
|
||||
}
|
||||
|
||||
// search
|
||||
@@ -409,7 +409,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
}
|
||||
|
||||
var embed = _eb.Create()
|
||||
.WithAuthor(GetText(strs.removed_song) + " #" + index, MusicIconUrl)
|
||||
.WithAuthor(GetText(strs.removed_song) + " #" + index, MUSIC_ICON_URL)
|
||||
.WithDescription(song.PrettyName())
|
||||
.WithFooter(song.PrettyInfo())
|
||||
.WithErrorColor();
|
||||
@@ -578,7 +578,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
var embed = _eb.Create()
|
||||
.WithTitle(track.Title.TrimTo(65))
|
||||
.WithAuthor(GetText(strs.song_moved), MusicIconUrl)
|
||||
.WithAuthor(GetText(strs.song_moved), MUSIC_ICON_URL)
|
||||
.AddField(GetText(strs.from_position), $"#{from + 1}", true)
|
||||
.AddField(GetText(strs.to_position), $"#{to + 1}", true)
|
||||
.WithOkColor();
|
||||
@@ -667,7 +667,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
.WithAuthor(GetText(strs.now_playing), MusicIconUrl)
|
||||
.WithAuthor(GetText(strs.now_playing), MUSIC_ICON_URL)
|
||||
.WithDescription(currentTrack.PrettyName())
|
||||
.WithThumbnailUrl(currentTrack.Thumbnail)
|
||||
.WithFooter(
|
||||
|
@@ -23,7 +23,7 @@ public sealed partial class Music
|
||||
private async Task EnsureBotInVoiceChannelAsync(ulong voiceChannelId, IGuildUser botUser = null)
|
||||
{
|
||||
botUser ??= await ctx.Guild.GetCurrentUserAsync();
|
||||
await voiceChannelLock.WaitAsync();
|
||||
await _voiceChannelLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (botUser.VoiceChannel?.Id is null || !_service.TryGetMusicPlayer(ctx.Guild.Id, out _))
|
||||
@@ -31,7 +31,7 @@ public sealed partial class Music
|
||||
}
|
||||
finally
|
||||
{
|
||||
voiceChannelLock.Release();
|
||||
_voiceChannelLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public sealed partial class Music
|
||||
}
|
||||
|
||||
var embed = _eb.Create(ctx)
|
||||
.WithAuthor(GetText(strs.playlists_page(num)), MusicIconUrl)
|
||||
.WithAuthor(GetText(strs.playlists_page(num)), MUSIC_ICON_URL)
|
||||
.WithDescription(string.Join("\n",
|
||||
playlists.Select(r => GetText(strs.playlists(r.Id, r.Name, r.Author, r.Songs.Count)))))
|
||||
.WithOkColor();
|
||||
|
@@ -189,7 +189,7 @@ public sealed class MusicService : IMusicService
|
||||
_ = lastFinishedMessage?.DeleteAsync();
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
.WithAuthor(GetText(guildId, strs.finished_song), Music.MusicIconUrl)
|
||||
.WithAuthor(GetText(guildId, strs.finished_song), Music.MUSIC_ICON_URL)
|
||||
.WithDescription(trackInfo.PrettyName())
|
||||
.WithFooter(trackInfo.PrettyTotalTime());
|
||||
|
||||
@@ -205,7 +205,7 @@ public sealed class MusicService : IMusicService
|
||||
_ = lastPlayingMessage?.DeleteAsync();
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
.WithAuthor(GetText(guildId, strs.playing_song(index + 1)), Music.MusicIconUrl)
|
||||
.WithAuthor(GetText(guildId, strs.playing_song(index + 1)), Music.MUSIC_ICON_URL)
|
||||
.WithDescription(trackInfo.PrettyName())
|
||||
.WithFooter($"{mp.PrettyVolume()} | {trackInfo.PrettyInfo()}");
|
||||
|
||||
|
@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Music.Common;
|
||||
|
||||
public sealed class MultimediaTimer : IDisposable
|
||||
{
|
||||
private LpTimeProcDelegate _lpTimeProc;
|
||||
private LpTimeProcDelegate lpTimeProc;
|
||||
private readonly uint _eventId;
|
||||
private readonly Action<object> _callback;
|
||||
private readonly object _state;
|
||||
@@ -18,8 +18,8 @@ public sealed class MultimediaTimer : IDisposable
|
||||
_callback = callback;
|
||||
_state = state;
|
||||
|
||||
_lpTimeProc = CallbackInternal;
|
||||
_eventId = timeSetEvent((uint)period, 1, _lpTimeProc, 0, TimerMode.Periodic);
|
||||
lpTimeProc = CallbackInternal;
|
||||
_eventId = timeSetEvent((uint)period, 1, lpTimeProc, 0, TimerMode.Periodic);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,13 +58,13 @@ public sealed class MultimediaTimer : IDisposable
|
||||
/// <summary>
|
||||
/// The timeKillEvent function cancels a specified timer event.
|
||||
/// </summary>
|
||||
/// <param name="uTimerID">
|
||||
/// <param name="uTimerId">
|
||||
/// Identifier of the timer event to cancel.
|
||||
/// This identifier was returned by the timeSetEvent function when the timer event was set up.
|
||||
/// </param>
|
||||
/// <returns>Returns TIMERR_NOERROR if successful or MMSYSERR_INVALPARAM if the specified timer event does not exist.</returns>
|
||||
[DllImport("Winmm.dll")]
|
||||
private static extern int timeKillEvent(uint uTimerID);
|
||||
private static extern int timeKillEvent(uint uTimerId);
|
||||
|
||||
private void CallbackInternal(
|
||||
uint uTimerId,
|
||||
@@ -76,12 +76,12 @@ public sealed class MultimediaTimer : IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_lpTimeProc = default;
|
||||
lpTimeProc = default;
|
||||
timeKillEvent(_eventId);
|
||||
}
|
||||
|
||||
private delegate void LpTimeProcDelegate(
|
||||
uint uTimerID,
|
||||
uint uTimerId,
|
||||
uint uMsg,
|
||||
int dwUser,
|
||||
int dw1,
|
||||
|
@@ -22,7 +22,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
|
||||
public float Volume { get; private set; } = 1.0f;
|
||||
|
||||
private readonly AdjustVolumeDelegate AdjustVolume;
|
||||
private readonly AdjustVolumeDelegate _adjustVolume;
|
||||
private readonly VoiceClient _vc;
|
||||
|
||||
private readonly IMusicQueue _queue;
|
||||
@@ -30,8 +30,8 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
private readonly IVoiceProxy _proxy;
|
||||
private readonly ISongBuffer _songBuffer;
|
||||
|
||||
private bool _skipped;
|
||||
private int? _forceIndex;
|
||||
private bool skipped;
|
||||
private int? forceIndex;
|
||||
private readonly Thread _thread;
|
||||
private readonly Random _rng;
|
||||
|
||||
@@ -48,9 +48,9 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
|
||||
_vc = GetVoiceClient(qualityPreset);
|
||||
if (_vc.BitDepth == 16)
|
||||
AdjustVolume = AdjustVolumeInt16;
|
||||
_adjustVolume = AdjustVolumeInt16;
|
||||
else
|
||||
AdjustVolume = AdjustVolumeFloat32;
|
||||
_adjustVolume = AdjustVolumeFloat32;
|
||||
|
||||
_songBuffer = new PoopyBufferImmortalized(_vc.InputLength);
|
||||
|
||||
@@ -95,9 +95,9 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_skipped)
|
||||
if (skipped)
|
||||
{
|
||||
_skipped = false;
|
||||
skipped = false;
|
||||
_queue.Advance();
|
||||
continue;
|
||||
}
|
||||
@@ -182,9 +182,9 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
{
|
||||
// doing the skip this way instead of in the condition
|
||||
// ensures that a song will for sure be skipped
|
||||
if (_skipped)
|
||||
if (skipped)
|
||||
{
|
||||
_skipped = false;
|
||||
skipped = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -268,10 +268,9 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
_ = OnCompleted?.Invoke(this, track);
|
||||
|
||||
HandleQueuePostTrack();
|
||||
_skipped = false;
|
||||
skipped = false;
|
||||
|
||||
_ = _proxy.StopSpeakingAsync();
|
||||
;
|
||||
|
||||
await Task.Delay(100);
|
||||
}
|
||||
@@ -285,16 +284,16 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
// if nothing is read from the buffer, song is finished
|
||||
if (data.Length == 0) return null;
|
||||
|
||||
AdjustVolume(data, Volume);
|
||||
_adjustVolume(data, Volume);
|
||||
return _proxy.SendPcmFrame(vc, data, length);
|
||||
}
|
||||
|
||||
private void HandleQueuePostTrack()
|
||||
{
|
||||
if (_forceIndex is { } forceIndex)
|
||||
if (this.forceIndex is { } forceIndex)
|
||||
{
|
||||
_queue.SetIndex(forceIndex);
|
||||
_forceIndex = null;
|
||||
this.forceIndex = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -419,7 +418,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
public void Clear()
|
||||
{
|
||||
_queue.Clear();
|
||||
_skipped = true;
|
||||
skipped = true;
|
||||
}
|
||||
|
||||
public IReadOnlyCollection<IQueuedTrackInfo> GetQueuedTracks()
|
||||
@@ -430,7 +429,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
|
||||
public void Next()
|
||||
{
|
||||
_skipped = true;
|
||||
skipped = true;
|
||||
IsStopped = false;
|
||||
IsPaused = false;
|
||||
}
|
||||
@@ -439,8 +438,8 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
{
|
||||
if (_queue.SetIndex(index))
|
||||
{
|
||||
_forceIndex = index;
|
||||
_skipped = true;
|
||||
forceIndex = index;
|
||||
skipped = true;
|
||||
IsStopped = false;
|
||||
IsPaused = false;
|
||||
return true;
|
||||
@@ -463,7 +462,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
IsKilled = true;
|
||||
IsStopped = true;
|
||||
IsPaused = false;
|
||||
_skipped = true;
|
||||
skipped = true;
|
||||
}
|
||||
|
||||
public bool TryRemoveTrackAt(int index, out IQueuedTrackInfo? trackInfo)
|
||||
@@ -472,7 +471,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
return false;
|
||||
|
||||
if (isCurrent)
|
||||
_skipped = true;
|
||||
skipped = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -91,7 +91,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
|
||||
var currentNode = tracks.First!;
|
||||
int i;
|
||||
for (i = 1; i <= this.index; i++)
|
||||
for (i = 1; i <= index; i++)
|
||||
currentNode = currentNode.Next!; // can't be null because index is always in range of the count
|
||||
|
||||
var added = new QueuedTrackInfo(trackInfo, queuer);
|
||||
@@ -110,7 +110,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
foreach (var track in toEnqueue)
|
||||
{
|
||||
var added = new QueuedTrackInfo(track, queuer);
|
||||
this.tracks.AddLast(added);
|
||||
tracks.AddLast(added);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
if (newIndex < 0 || newIndex >= tracks.Count)
|
||||
return false;
|
||||
|
||||
this.index = newIndex;
|
||||
index = newIndex;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -170,11 +170,11 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
trackInfo = removedNode.Value;
|
||||
tracks.Remove(removedNode);
|
||||
|
||||
if (i <= this.index)
|
||||
--this.index;
|
||||
if (i <= index)
|
||||
--index;
|
||||
|
||||
if (this.index < 0)
|
||||
this.index = Count;
|
||||
if (index < 0)
|
||||
index = Count;
|
||||
|
||||
// if it was the last song in the queue
|
||||
// // wrap back to start
|
||||
@@ -303,7 +303,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
if (remoteAt < 0 || remoteAt >= tracks.Count)
|
||||
return false;
|
||||
|
||||
if (remoteAt == this.index) isCurrent = true;
|
||||
if (remoteAt == index) isCurrent = true;
|
||||
|
||||
RemoveAtInternal(remoteAt, out trackInfo);
|
||||
|
||||
|
@@ -5,12 +5,12 @@ namespace NadekoBot.Modules.Music;
|
||||
|
||||
public sealed class YtdlYoutubeResolver : IYoutubeResolver
|
||||
{
|
||||
private static readonly string[] durationFormats =
|
||||
private static readonly string[] _durationFormats =
|
||||
{
|
||||
"ss", "m\\:ss", "mm\\:ss", "h\\:mm\\:ss", "hh\\:mm\\:ss", "hhh\\:mm\\:ss"
|
||||
};
|
||||
|
||||
private static readonly Regex expiryRegex = new(@"(?:[\?\&]expire\=(?<timestamp>\d+))");
|
||||
private static readonly Regex _expiryRegex = new(@"(?:[\?\&]expire\=(?<timestamp>\d+))");
|
||||
|
||||
|
||||
private static readonly Regex _simplePlaylistRegex = new(@"&list=(?<id>[\w\-]{12,})", RegexOptions.Compiled);
|
||||
@@ -85,7 +85,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
|
||||
return default;
|
||||
}
|
||||
|
||||
if (!TimeSpan.TryParseExact(dataArray[4], durationFormats, CultureInfo.InvariantCulture, out var time))
|
||||
if (!TimeSpan.TryParseExact(dataArray[4], _durationFormats, CultureInfo.InvariantCulture, out var time))
|
||||
time = TimeSpan.Zero;
|
||||
|
||||
var thumbnail = Uri.IsWellFormedUriString(dataArray[3], UriKind.Absolute) ? dataArray[3].Trim() : string.Empty;
|
||||
@@ -108,7 +108,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
|
||||
|
||||
private static TimeSpan GetExpiry(string streamUrl)
|
||||
{
|
||||
var match = expiryRegex.Match(streamUrl);
|
||||
var match = _expiryRegex.Match(streamUrl);
|
||||
if (match.Success && double.TryParse(match.Groups["timestamp"].ToString(), out var timestamp))
|
||||
{
|
||||
var realExpiry = timestamp.ToUnixTimestamp() - DateTime.UtcNow;
|
||||
|
Reference in New Issue
Block a user