コード例 #1
0
        public async Task PlayAsync([Remainder] string song = "")
        {
            Utilities utilities    = new Utilities(Context.Guild);
            var       guildAccount = GuildAccounts.GetGuildAccount(Context.Guild);
            string    avatar       = Context.Message.Author.GetAvatarUrl() ?? Context.Message.Author.GetDefaultAvatarUrl();
            int       choose       = -1;

            if (!song.Contains(".com") && song != "")
            {
                if ((Context.User as IVoiceState).VoiceChannel == null)
                {
                    await ReplyAsync(Utilities.GetAlert("PLAY_NULL_CHANNEL"));

                    return;
                }

                var          searchList   = AudioService.GetYoutubeAsync(song, Context.Guild.Id, (Context.User as IVoiceState).VoiceChannel);
                var          searchResult = searchList.Items[0];
                YoutubeVideo video        = new YoutubeVideo();
                video.SetInfoVideo(Context.Guild, searchResult.Snippet.Description, searchResult.Snippet.Thumbnails.High.Url,
                                   searchResult.Id.VideoId, searchResult.Snippet.Title);
                choose = 0;
                song   = $"https://www.youtube.com/watch?v={video.link[choose]}";

                await AudioService.PlayAsync(Context, song, choose, video);

                return;
            }

            await AudioService.PlayAsync(Context, song, 0);
        }
コード例 #2
0
        public async Task YoutubeAsync([Remainder] string query = "")
        {
            Utilities utilities = new Utilities(Context.Guild);
            string    avatar    = Context.Message.Author.GetAvatarUrl() ?? Context.Message.Author.GetDefaultAvatarUrl();

            if (query == "")
            {
                await ReplyAsync(Utilities.GetAlert("PLAY_NULL_QUERY"));

                return;
            }

            var          searchList = AudioService.GetYoutubeAsync(query, Context.Guild.Id, (Context.User as IVoiceState).VoiceChannel);
            YoutubeVideo video      = new YoutubeVideo();

            video.SetMultipleVideosInfo(Context.Guild, video, searchList);

            EmbedBuilder builder = new EmbedBuilder();

            builder
            .WithAuthor(Context.Message.Author.Username, avatar)
            .WithThumbnailUrl("http://i65.tinypic.com/2uqk3yr.png")
            .WithTitle(Utilities.GetAlert("YOUTUBE_FILMEMBED"))
            .WithDescription($"{string.Join("\n", video.videosList)}")
            .WithColor(Color.Red);

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

            var response = await NextMessageAsync(true, true, timeout : TimeSpan.FromSeconds(30));

            string answer = response.ToString();

            string[] wholeMsg = answer.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int      choose   = InteractiveUtil.ConvertToInt(answer);

            if (Utilities.GetAlert("answerCancel").Contains(wholeMsg[0]))
            {
                await ReplyAsync(Utilities.GetAlert("PLAY_CANCEL"));

                return;
            }
            if (choose == 0)
            {
                return;
            }

            choose = choose - 1;
            string song = $"https://www.youtube.com/watch?v={video.link[choose]}";
            await AudioService.PlayAsync(Context, song, choose, video);

            return;
        }
コード例 #3
0
        // This is a TODO, i really need to improve creating the queue because it's slow and inefficient af
        public static List <string> CreateListOfSongs(ISocketMessageChannel channel, List <LavalinkTrack> queue, string username, string avatar)
        {
            YoutubeVideo video = new YoutubeVideo();
            int          count = 1;

            //int i = 0;

            foreach (var track in queue)
            {
                video.videosList.Add($"{count}. [{track.Title}]({track.Url}) `{track.Length}` \n");
                //video.link[i] = track.Url;
                //video.title[i] = track.Title;
                count++;
                //i++;
            }

            return(video.videosList);
        }
コード例 #4
0
        public void SetMultipleVideosInfo(SocketGuild guild, YoutubeVideo video, Google.Apis.YouTube.v3.Data.SearchListResponse searchList)
        {
            int count = 1;
            int i     = 0;

            foreach (var searchResult in searchList.Items)
            {
                Utilities utilities = new Utilities(guild);
                video.videosList.Add($"{count}. {searchResult.Snippet.Title} \n");
                video.link[i]  = searchResult.Id.VideoId;
                video.title[i] = searchResult.Snippet.Title;
                video.desc[i]  = searchResult.Snippet.Description;
                video.image[i] = searchResult.Snippet.Thumbnails.High.Url;
                if (video.desc[i] == null || video.desc[i] == "")
                {
                    video.desc[i] = Utilities.GetAlert("PLAY_NULL_DESC");
                }
                count++;
                i++;
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
0
        private static async Task SongInfo(ISocketMessageChannel channel, SocketUserMessage message, YoutubeVideo video, int choose, string playOrAdded)
        {
            string avatar = message.Author.GetAvatarUrl() ?? message.Author.GetDefaultAvatarUrl();

            EmbedBuilder builder = new EmbedBuilder();

            builder
            .WithAuthor(message.Author.Username, avatar)
            .WithThumbnailUrl(video.image[choose])
            .AddField(Utilities.GetAlert(playOrAdded), $"[{video.title[choose]}](https://www.youtube.com/watch?v={video.link[choose]})")
            .AddField(Utilities.GetAlert("PLAY_VIDEO_DESC"), video.desc[choose])
            .WithColor(Color.DarkRed);

            await channel.SendMessageAsync("", false, builder.Build());
        }
コード例 #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);
        }