public SongsController(ISongRepository songRepository, IAlbumRepository albumRepository, ISingerRepository singerRepository) { this._songRepository = songRepository; this._albumRepository = albumRepository; this._singerRepository = singerRepository; this._handler = new SongHandler(_songRepository, _albumRepository, _singerRepository); }
public void UseRepositoryWhenSongIsAdded() { // arrange var userId = UserId.Parse("12345"); var playlistId = PlaylistId.Parse("100"); var songId = SongId.Parse("001"); var title = "title"; var artist = "artist"; var mockedSongRepository = SongRepositoryBuilder.Create(); var songRepository = mockedSongRepository.Build(); var songHandler = new SongHandler(songRepository); // act songHandler.Handle(new SongAdded(userId, playlistId, songId, title, artist)); // assert var(actualUserId, actualPlaylistId, actualSongId, actualTitle, actualArtist) = mockedSongRepository.Songs.First(); Assert.AreEqual(userId, actualUserId); Assert.AreEqual(playlistId, actualPlaylistId); Assert.AreEqual(songId, actualSongId); Assert.AreEqual(title, actualTitle); Assert.AreEqual(artist, actualArtist); }
public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("#app"); var musicBrainzClient = new HttpClient { BaseAddress = new Uri("https://musicbrainz.org/ws/2/"), }; musicBrainzClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); IMusicInfoApiClient musicClient = new MusicInfoApiClient(musicBrainzClient); builder.Services.AddScoped(sp => musicClient); var lyricsOvhClient = new HttpClient { BaseAddress = new Uri("https://api.lyrics.ovh/v1/"), }; lyricsOvhClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); ILyricsApiClient lyricsClient = new LyricsApiClient(lyricsOvhClient); builder.Services.AddScoped(sp => lyricsClient); ISongHandler songHandler = new SongHandler(musicClient, lyricsClient); builder.Services.AddScoped(sp => songHandler); ILyricsHandler lyricsHandler = new LyricsHandler(); builder.Services.AddScoped(sp => lyricsHandler); await builder.Build().RunAsync(); }
public static async Task QueueSong(IGuildUser queuer, ITextChannel textCh, IVoiceChannel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal) { if (voiceCh == null || voiceCh.Guild != textCh.Guild) { if (!silent) { await textCh.SendErrorAsync($"💢 You need to be in a voice channel on this server.").ConfigureAwait(false); } throw new ArgumentNullException(nameof(voiceCh)); } if (string.IsNullOrWhiteSpace(query) || query.Length < 3) { throw new ArgumentException("💢 Invalid query for queue song.", nameof(query)); } var musicPlayer = MusicPlayers.GetOrAdd(textCh.Guild.Id, server => { float vol = 1;// SpecificConfigurations.Default.Of(server.Id).DefaultMusicVolume; using (var uow = DbHandler.UnitOfWork()) { vol = uow.GuildConfigs.For(textCh.Guild.Id, set => set).DefaultMusicVolume; } var mp = new MusicPlayer(voiceCh, textCh, vol); IUserMessage playingMessage = null; IUserMessage lastFinishedMessage = null; mp.OnCompleted += async(s, song) => { try { lastFinishedMessage?.DeleteAfter(0); try { lastFinishedMessage = await mp.OutputTextChannel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Finished Song").WithMusicIcon()) .WithDescription(song.PrettyName) .WithFooter(ef => ef.WithText(song.PrettyInfo))) .ConfigureAwait(false); } catch { // ignored } if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.ProviderType == MusicType.Normal) { var relatedVideos = (await NadekoBot.Google.GetRelatedVideosAsync(song.SongInfo.Query, 4)).ToList(); if (relatedVideos.Count > 0) { await QueueSong(await queuer.Guild.GetCurrentUserAsync(), textCh, voiceCh, relatedVideos[new NadekoRandom().Next(0, relatedVideos.Count)], true).ConfigureAwait(false); } } } catch { } }; mp.OnStarted += async(player, song) => { try { await mp.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { // ignored } var sender = player as MusicPlayer; if (sender == null) { return; } try { playingMessage?.DeleteAfter(0); playingMessage = await mp.OutputTextChannel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon()) .WithDescription(song.PrettyName) .WithFooter(ef => ef.WithText(song.PrettyInfo))) .ConfigureAwait(false); } catch { } }; mp.OnPauseChanged += async(paused) => { try { IUserMessage msg; if (paused) { msg = await mp.OutputTextChannel.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false); } else { msg = await mp.OutputTextChannel.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); } msg?.DeleteAfter(10); } catch { } }; mp.SongRemoved += async(song, index) => { try { var embed = new EmbedBuilder() .WithAuthor(eab => eab.WithName("Removed song #" + (index + 1)).WithMusicIcon()) .WithDescription(song.PrettyName) .WithFooter(ef => ef.WithText(song.PrettyInfo)) .WithErrorColor(); await mp.OutputTextChannel.EmbedAsync(embed).ConfigureAwait(false); } catch { // ignored } }; return(mp); }); Song resolvedSong; try { musicPlayer.ThrowIfQueueFull(); resolvedSong = await SongHandler.ResolveSong(query, musicType).ConfigureAwait(false); if (resolvedSong == null) { throw new SongNotFoundException(); } musicPlayer.AddSong(resolvedSong, queuer.Username); } catch (PlaylistFullException) { try { await textCh.SendConfirmAsync($"🎵 Queue is full at **{musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}**."); } catch { } throw; } if (!silent) { try { //var queuedMessage = await textCh.SendConfirmAsync($"🎵 Queued **{resolvedSong.SongInfo.Title}** at `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); var queuedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Queued Song #" + (musicPlayer.Playlist.Count + 1)).WithMusicIcon()) .WithDescription($"{resolvedSong.PrettyName}\nQueue ") .WithThumbnailUrl(resolvedSong.Thumbnail) .WithFooter(ef => ef.WithText(resolvedSong.PrettyProvider))) .ConfigureAwait(false); queuedMessage?.DeleteAfter(10); } catch { // ignored } // if queued message sending fails, don't attempt to delete it } }
public NextSongMenuHandler(SongHandler songhandler, MenuController menu) : base(songhandler, menu) { Label = "Next"; }
public CloseMenuHandler(SongHandler songhandler, MenuController menu) : base(songhandler, menu) { Label = "Close"; Enabled = true; }
public VolumeMenuHandler(SongHandler songhandler, MenuController menu) : base(songhandler, menu) { Label = "Volume"; // Text displayed when selecting stuff Enabled = true; // Enables the control all the time, including when no songs are playing }
public TrackMenuHandler(SongHandler songhandler, MenuController menu) : base(songhandler, menu) { Label = "Track"; }
public PreviousSongMenuHandler(SongHandler songhandler, MenuController menu) : base(songhandler, menu) { Label = "Previous"; }
public PositionMenuHandler(SongHandler songhandler, MenuController menu) : base(songhandler, menu) { Label = "Position"; }