Cleanup, .smp is reimplemented, and will now show in .lq too
This commit is contained in:
		| @@ -246,6 +246,9 @@ namespace NadekoBot.Modules.Music | ||||
|                 var add = ""; | ||||
|                 if (mp.Stopped) | ||||
|                     add += Format.Bold(GetText("queue_stopped", Format.Code(Prefix + "play"))) + "\n"; | ||||
|                 var mps = mp.MaxPlaytimeSeconds; | ||||
|                 if (mps > 0) | ||||
|                     add += Format.Bold(GetText("song_skips_after", TimeSpan.FromSeconds(mps).ToString("g"))) + "\n"; | ||||
|                 if (mp.RepeatCurrentSong) | ||||
|                     add += "🔂 " + GetText("repeating_cur_song") + "\n"; | ||||
|                 else if (mp.Shuffle) | ||||
| @@ -259,7 +262,7 @@ namespace NadekoBot.Modules.Music | ||||
|                 } | ||||
|  | ||||
|                 if (!string.IsNullOrWhiteSpace(add)) | ||||
|                     desc += add + "\n"; | ||||
|                     desc = add + "\n" + desc; | ||||
|                  | ||||
|                 var embed = new EmbedBuilder() | ||||
|                     .WithAuthor(eab => eab.WithName(GetText("player_queue", curPage + 1, lastPage + 1)) | ||||
| @@ -795,24 +798,21 @@ namespace NadekoBot.Modules.Music | ||||
|                 await ReplyConfirmLocalized("max_queue_x", size).ConfigureAwait(false); | ||||
|         } | ||||
|  | ||||
|         //[NadekoCommand, Usage, Description, Aliases] | ||||
|         //[RequireContext(ContextType.Guild)] | ||||
|         //public async Task SetMaxPlaytime(uint seconds) | ||||
|         //{ | ||||
|         //    if (seconds < 15 && seconds != 0) | ||||
|         //        return; | ||||
|         [NadekoCommand, Usage, Description, Aliases] | ||||
|         [RequireContext(ContextType.Guild)] | ||||
|         public async Task SetMaxPlaytime(uint seconds) | ||||
|         { | ||||
|             if (seconds < 15 && seconds != 0) | ||||
|                 return; | ||||
|  | ||||
|             var mp = await _music.GetOrCreatePlayer(Context); | ||||
|             mp.MaxPlaytimeSeconds = seconds; | ||||
|             if (seconds == 0) | ||||
|                 await ReplyConfirmLocalized("max_playtime_none").ConfigureAwait(false); | ||||
|             else | ||||
|                 await ReplyConfirmLocalized("max_playtime_set", seconds).ConfigureAwait(false); | ||||
|         } | ||||
|  | ||||
|         //    var channel = (ITextChannel)Context.Channel; | ||||
|         //    MusicPlayer musicPlayer; | ||||
|         //    if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null) | ||||
|         //        return; | ||||
|         //    musicPlayer.MaxPlaytimeSeconds = seconds; | ||||
|         //    if (seconds == 0) | ||||
|         //        await ReplyConfirmLocalized("max_playtime_none").ConfigureAwait(false); | ||||
|         //    else | ||||
|         //        await ReplyConfirmLocalized("max_playtime_set", seconds).ConfigureAwait(false); | ||||
|         //} | ||||
|          | ||||
|         [NadekoCommand, Usage, Description, Aliases] | ||||
|         [RequireContext(ContextType.Guild)] | ||||
|         public async Task ReptCurSong() | ||||
|   | ||||
| @@ -1198,7 +1198,7 @@ | ||||
|     <value>`{0}drawnew` or `{0}drawnew 5`</value> | ||||
|   </data> | ||||
|   <data name="shuffleplaylist_cmd" xml:space="preserve"> | ||||
|     <value>playlistshuffle plsh</value> | ||||
|     <value>shuffle plsh</value> | ||||
|   </data> | ||||
|   <data name="shuffleplaylist_desc" xml:space="preserve"> | ||||
|     <value>Shuffles the current playlist.</value> | ||||
|   | ||||
| @@ -50,6 +50,13 @@ namespace NadekoBot.Services.Music | ||||
|             get => Queue.MaxQueueSize; | ||||
|             set => Queue.MaxQueueSize = value; | ||||
|         } | ||||
|         public uint MaxPlaytimeSeconds { get; set; } | ||||
|  | ||||
|  | ||||
|         const int _frameBytes = 3840; | ||||
|         const float _miliseconds = 20.0f; | ||||
|         public TimeSpan CurrentTime => TimeSpan.FromSeconds(_bytesSent / (float)_frameBytes / (1000 / _miliseconds)); | ||||
|         private int _bytesSent = 0; | ||||
|  | ||||
|         private IAudioClient _audioClient; | ||||
|         private readonly object locker = new object(); | ||||
| @@ -78,6 +85,7 @@ namespace NadekoBot.Services.Music | ||||
|              { | ||||
|                  while (!Exited) | ||||
|                  { | ||||
|                      _bytesSent = 0; | ||||
|                      CancellationToken cancelToken; | ||||
|                      (int Index, SongInfo Song) data; | ||||
|                      lock (locker) | ||||
| @@ -122,12 +130,14 @@ namespace NadekoBot.Services.Music | ||||
|                              int bytesRead = 0; | ||||
|                              try | ||||
|                              { | ||||
|                                  while ((bytesRead = await b.ReadAsync(buffer, 0, buffer.Length, cancelToken).ConfigureAwait(false)) > 0) | ||||
|                                  while ((bytesRead = await b.ReadAsync(buffer, 0, buffer.Length, cancelToken).ConfigureAwait(false)) > 0  | ||||
|                                     && (MaxPlaytimeSeconds <= 0 || MaxPlaytimeSeconds >= CurrentTime.TotalSeconds)) | ||||
|                                  { | ||||
|                                      var vol = Volume; | ||||
|                                      if (vol != 1) | ||||
|                                          AdjustVolume(buffer, vol); | ||||
|                                      await pcm.WriteAsync(buffer, 0, bytesRead, cancelToken).ConfigureAwait(false); | ||||
|                                      unchecked { _bytesSent += bytesRead; } | ||||
|  | ||||
|                                      await (pauseTaskSource?.Task ?? Task.CompletedTask); | ||||
|                                  } | ||||
|   | ||||
| @@ -69,6 +69,7 @@ Check the guides for your platform on how to setup ffmpeg correctly: | ||||
|     Linux Guide:  https://goo.gl/ShjCUo"); | ||||
|                 } | ||||
|                 catch (OperationCanceledException) { } | ||||
|                 catch (InvalidOperationException) { } // when ffmpeg is disposed | ||||
|                 catch (Exception ex) | ||||
|                 { | ||||
|                     _log.Info(ex); | ||||
|   | ||||
| @@ -455,6 +455,7 @@ | ||||
|   "music_songs_shuffle_disable": "Songs will no longer shuffle.", | ||||
|   "music_song_moved": "Song moved", | ||||
|   "music_song_not_found": "No song found.", | ||||
|   "music_song_skips_after": "Songs will skip after {0}", | ||||
|   "music_time_format": "{0}h {1}m {2}s", | ||||
|   "music_to_position": "To position", | ||||
|   "music_unlimited": "unlimited", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user