Ejemplo n.º 1
0
 public GuildMusicConfig()
 {
     Repeat         = false;
     MaxQueueTimes  = null;
     UserQueueTimes = new ConcurrentDictionary <ulong, int>();
     IsPlayed       = false;
     Queue          = new CQueue <LavaTrack>();
 }
Ejemplo n.º 2
0
        public async Task <bool> PlayTracksAsync(string url,
                                                 ICommandContext Context,
                                                 ITextChannel textChannel,
                                                 bool sendError = true,
                                                 bool clear     = true, bool shuffled = false)
        {
            var tplayer = await JoinAsync(Context, textChannel, true, false);

            var player = tplayer.Item2;
            var guild  = _guildConfigs.GetOrAdd(player.VoiceChannel.GuildId, new GuildMusicConfig());

            if (tplayer.Item1 != Successful && tplayer.Item1 != SameChannel)
            {
                if (sendError)
                {
                    await textChannel.SendMessageAsync($"{Context.User.Mention} {GetError(11)}");
                }
                return(false);
            }


            SocketVoiceChannel myChannel = player.VoiceChannel as SocketVoiceChannel;

            if ((player.IsPlaying && myChannel.Users.Count > 2 && !(Context.User as IGuildUser).ContainsRole("DJ")))
            {
                if (sendError)
                {
                    await textChannel.SendMessageAsync($"{Context.User.Mention} {GetError(12)}");
                }
                return(false);
            }
            if (guild.Queue.Count == 0 && !clear && !guild.IsPlayed)
            {
                return(await PlayTracksAsync(url, Context, textChannel, sendError, true));
            }

            if (clear)
            {
                guild.Queue.Clear();
            }

            var tracks = new CQueue <LavaTrack>((await LavaRestClient.SearchTracksAsync(url, true)).Tracks);

            if (shuffled)
            {
                tracks.Shuffle();
            }
            foreach (var track in tracks)
            {
                if (track == tracks.FirstOrDefault())
                {
                    continue;
                }
                guild.Queue.Enqueue(track);
            }

            if (clear)
            {
                var track = tracks.FirstOrDefault();
                if (sendError)
                {
                    EmbedBuilder Embed = new EmbedBuilder
                    {
                        Title       = "Playing Song",
                        Description = $"[{track.Title}]({track.Uri.AbsoluteUri})"
                    };

                    Embed.AddField("Length", track.Length.ToString(), true);
                    Embed.AddField("Tracks in Queue", (guild.Queue.Count).ToString(), true);
                    Embed.AddField("Next Track", guild.Queue.Count == 0 ? "No tracks" : (guild.Queue[0] as LavaTrack).Title, true);

                    Embed.ImageUrl = await track.FetchThumbnailAsync();

                    await textChannel.SendMessageAsync("", false, Embed.Build());
                }
                await player.PlayAsync(track);
            }
            return(true);
        }