Пример #1
0
        public async Task QueueAsync()
        {
            var    audioQueue = AudioQueues.GetAudioQueue(Context.Guild);
            string avatar     = Context.Message.Author.GetAvatarUrl() ?? Context.Message.Author.GetDefaultAvatarUrl();

            if (audioQueue.Queue.ElementAtOrDefault(0) == null)
            {
                EmbedBuilder builderNull = new EmbedBuilder();
                builderNull
                .WithAuthor(Context.Message.Author.Username, avatar)
                .WithDescription("\n Kolejka jest pusta")
                .WithColor(Color.DarkRed);

                await ReplyAsync("", false, builderNull.Build());

                return;
            }

            List <string>         queue        = new List <string>();
            List <List <string> > pagesContent = new List <List <string> >(5);

            queue        = AudioQueuesManagment.CreateListOfSongs(Context.Channel, audioQueue.Queue, Context.Message.Author.Username, avatar);
            pagesContent = AudioQueuesManagment.CreateListOfPages(queue);
            string[] pages = new string[5];
            pages = AudioQueuesManagment.AssignContentToPages(pages, pagesContent);

            await PagedReplyAsync(pages);
        }
Пример #2
0
        public async Task SkipAsync()
        {
            var    audioQueue        = AudioQueues.GetAudioQueue(Context.Guild);
            string skippedTrackTitle = audioQueue.Queue[audioQueue.PlayingTrackIndex].Title;
            await AudioService.SkipAsync(Context.Guild);

            await ReplyAsync($":fast_forward: {skippedTrackTitle} skipped");
        }
Пример #3
0
        private static async Task RemoveAllTracks(SocketGuild guild)
        {
            var audioQueue = AudioQueues.GetAudioQueue(guild);

            audioQueue.Queue.Clear();
            AudioQueues.SaveQueues();
            await Task.CompletedTask;
        }
        public static async Task RemoveAndPlay(LavalinkPlayer player, LavalinkTrack track)
        {
            var audioQueue = AudioQueues.GetAudioQueue(player.VoiceChannel.Guild as SocketGuild);

            RemoveTrack(audioQueue, track);
            await player.StopAsync();

            await PlayNextAfterRemove(audioQueue, player);
        }
        private static async Task PlayNextAfterRemove(AudioQueue audioQueue, LavalinkPlayer player)
        {
            if (audioQueue.Queue.ElementAtOrDefault(0) != null)
            {
                audioQueue.PlayingTrackIndex = 0;
                AudioQueues.SaveQueues();
                LavalinkTrack track = audioQueue.Queue.ElementAtOrDefault(0);
                await player.PlayAsync(track);
            }

            await Task.CompletedTask;
        }
Пример #6
0
        public static async Task PlayAsync(SocketCommandContext context, string song, int choose, YoutubeVideo video = null)
        {
            // Create used objects
            SocketGuild           guild        = context.Guild;
            SocketUserMessage     message      = context.Message;
            IVoiceChannel         voiceChannel = (context.User as IVoiceState).VoiceChannel;
            ISocketMessageChannel channel      = context.Channel;
            Utilities             utilities    = new Utilities(guild);

            // Checking if voice channel is null (and sending an error message)
            // If not, creating or getting a lavalink player
            // Checking if a given string is empty (if true, and there is a song in queue that is stopped, resuming it
            if (await VoiceChannelIsNull(channel, voiceChannel, utilities) is true)
            {
                return;
            }
            LavalinkPlayer player = lavalinkManager.GetPlayer(guild.Id) ?? await lavalinkManager.JoinAsync(voiceChannel);

            var audioQueue = AudioQueues.GetAudioQueue(guild);

            if (await SongIsEmpty(channel, utilities, player, audioQueue, song) is true)
            {
                return;
            }

            LoadTracksResponse response = await lavalinkManager.GetTracksAsync(song);

            LavalinkTrack track = response.Tracks.First();

            // Maximum songs in queue is 50
            if (await QueueIsFull(channel, utilities, audioQueue.Queue.Count) is true)
            {
                return;
            }

            // Adding a track to queue
            audioQueue.Queue = AudioQueues.GetOrCreateGuildQueue(track, audioQueue);

            // A check if a song is first in the queue, or if it's been added
            string songAlert = "PLAY_ADDED_SONG";

            if (await SongIsFirst(player, audioQueue, track, video, context, songAlert, choose) is false)
            {
                return;
            }
            // If a user gives a link to a youtube video, we don't need to send song info
            if (choose != -1)
            {
                await SongInfo(channel, message, video, choose, songAlert);
            }
        }
Пример #7
0
        private static async Task <bool> SongIsFirst(LavalinkPlayer player, AudioQueue audioQueue, LavalinkTrack track, YoutubeVideo video, SocketCommandContext context, string songAlert, int choose)
        {
            ISocketMessageChannel channel     = context.Channel;
            SocketUserMessage     message     = context.Message;
            LavalinkTrack         secondTrack = audioQueue.Queue.ElementAtOrDefault(1);

            if (secondTrack == null)
            {
                audioQueue.PlayingTrackIndex = 0;
                AudioQueues.SaveQueues();

                await player.PlayAsync(track);

                if (video != null)
                {
                    songAlert = "PLAY_PLAYED_SONG";
                    await SongInfo(channel, message, video, choose, songAlert);
                }

                return(true);
            }

            return(false);
        }
 private static void RemoveTrack(AudioQueue audioQueue, LavalinkTrack track)
 {
     audioQueue.Queue.Remove(audioQueue.Queue[audioQueue.PlayingTrackIndex]);
     AudioQueues.SaveQueues();
     return;
 }