Exemple #1
0
        public async Task NowPlayingAsync()
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));

                return;
            }

            if (player.PlayerState != PlayerState.Playing)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("Woaaah there, I'm not playing any tracks."));

                return;
            }

            var track = player.Track;

            var requestingUser = _musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id)
                                 .QueuedItems.First().RequestingUser;

            var embed = await ProduceNowPlayingEmbed(track, requestingUser);

            await this.ReplyAsync(embed : embed.Build());
        }
Exemple #2
0
        private async Task EnqueueSingleTrack(SearchResponse searchResponse, LavaPlayer player)
        {
            var track = searchResponse.Tracks[0];

            if (!string.IsNullOrWhiteSpace(searchResponse.Playlist.Name))
            {
                for (var i = 0; i < searchResponse.Tracks.Count; i++)
                {
                    if (i == 0)
                    {
                        await player.PlayAsync(track);

                        _musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id).QueuedItems
                        .Add(new QueuedItem(track, this.Context.User));
                        await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"Now Playing: {track.Title}"));
                    }
                    else
                    {
                        player.Queue.Enqueue(searchResponse.Tracks[i]);
                        _musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id).QueuedItems
                        .Add(new QueuedItem(searchResponse.Tracks[i], this.Context.User));
                    }
                }

                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"Enqueued {searchResponse.Tracks.Count} tracks."));
            }
            else
            {
                await player.PlayAsync(track);

                _musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id).QueuedItems
                .Add(new QueuedItem(track, this.Context.User));
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"Now Playing: {track.Title}"));
            }
        }
Exemple #3
0
        public async Task ServerInfoAsync(ulong?guid = null)
        {
            if (guid == null)
            {
                guid = this.Context.Guild.Id;
            }
            var info = await DynamoSystem.GetItemAsync <GuildInfo>(guid.ToString()).ConfigureAwait(false);

            Embed embed;

            if (info == null || string.IsNullOrEmpty(info.GuildGuid))
            {
                embed = EmbedHandler.GenerateEmbedResponse(
                    "No Server was found with that GUID",
                    Color.Orange);
            }
            else
            {
                embed = EmbedHandler.GenerateEmbedResponse(
                    $"GuildGuid: {info.GuildGuid}\r\n" +
                    $"GuildName: {info.GuildName}");
            }

            await this.ReplyAsync("", false, embed).ConfigureAwait(false);
        }
Exemple #4
0
        public async Task ServerInfoAsync([Remainder] string name)
        {
            var response = await DynamoSystem.QueryItemAsync <GuildInfo>("GuildName", QueryOperator.Equal, name)
                           .ConfigureAwait(false);

            Embed embed;

            if (response.Count < 1)
            {
                embed = EmbedHandler.GenerateEmbedResponse(
                    "No servers were found with that name",
                    Color.Orange);
            }
            else
            {
                var message = response.Aggregate("Found the following servers:\r\n",
                                                 (current, guildInfo) =>
                                                 current + $"GuildGuid: {guildInfo.GuildGuid}\r\n" +
                                                 $"GuildName: {guildInfo.GuildName}\r\n\r\n");

                embed = EmbedHandler.GenerateEmbedResponse(
                    message);
            }

            await this.ReplyAsync("", false, embed).ConfigureAwait(false);
        }
Exemple #5
0
        public async Task DeleteFromQueue(int selection1, int selection2 = 0)
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));

                return;
            }
            if (selection2 == 0)
            {
                var track = (LavaTrack)player.Queue.ElementAt(selection1 - 1);

                _musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id).QueuedItems
                .RemoveAll(x => x.Track.Id == track.Id);

                player.Queue.RemoveAt(selection1 - 1);

                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"Removed song {selection1} from the queue", Color.Green));
            }
            else
            {
                player.Queue.RemoveRange(selection1 - 1, selection2 - 2);
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"Removed songs {selection1} to {selection2} from the queue", Color.Green));
            }
        }
Exemple #6
0
        public async Task AddServerInfoAsync()
        {
            var response = await DynamoSystem.QueryItemAsync <GuildInfo>("GuildName", QueryOperator.Equal, this.Context.Guild.Name)
                           .ConfigureAwait(false);

            if (response.Count < 1)
            {
                var existsResponse = EmbedHandler.GenerateEmbedResponse(
                    "This server already exists in the DB",
                    Color.Teal);
                await this.ReplyAsync("", false, existsResponse).ConfigureAwait(false);

                return;
            }

            var item = new GuildInfo
            {
                GuildGuid = this.Context.Guild.Id.ToString(),
                GuildName = this.Context.Guild.Name
            };
            await DynamoSystem.PutItemAsync(item).ConfigureAwait(false);

            var addedResponse = EmbedHandler.GenerateEmbedResponse(
                "This server has been added to the DB",
                Color.Green);

            await this.ReplyAsync("", false, addedResponse).ConfigureAwait(false);
        }
Exemple #7
0
        private async Task <SearchResponse> ValidationCheck([CanBeNull] string query, SearchType?type = null)
        {
            SearchResponse searchResponse;

            if (string.IsNullOrWhiteSpace(query))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("Please provide search terms."));
            }

            if (!this._lavaNode.HasPlayer(this.Context.Guild))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));
            }


            searchResponse = type switch
            {
                SearchType.Youtube => await this._lavaNode.SearchYouTubeAsync(query),
                SearchType.Soundcloud => await this._lavaNode.SearchSoundCloudAsync(query),
                null => await this._lavaNode.SearchAsync(query),
            };

            if (searchResponse.LoadStatus == LoadStatus.LoadFailed ||
                searchResponse.LoadStatus == LoadStatus.NoMatches)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"I wasn't able to find anything for `{query}`."));
            }

            return(searchResponse);
        }
Exemple #8
0
        private async Task OnTrackEnded(TrackEndedEventArgs args)
        {
            if (!args.Reason.ShouldPlayNext())
            {
                return;
            }

            var player = args.Player;

            MusicTrackQueues.Single(x => x.GuildId == args.Player.VoiceChannel.GuildId).QueuedItems
            .RemoveAll(x => x.Track.Id == args.Track.Id);

            if (!player.Queue.TryDequeue(out var queueable))
            {
                await player.TextChannel.SendMessageAsync("", false, EmbedHandler.GenerateEmbedResponse("No more tracks to play."));

                return;
            }

            if (!(queueable is LavaTrack track))
            {
                await player.TextChannel.SendMessageAsync("", false, EmbedHandler.GenerateEmbedResponse("Next item in queue is not a track."));

                return;
            }

            await args.Player.PlayAsync(track);

            var artwork = await track.FetchArtworkAsync();

            var requestingUser = MusicTrackQueues.Single(x => x.GuildId == args.Player.VoiceChannel.GuildId).QueuedItems.First().RequestingUser;

            var embed = new EmbedBuilder
            {
                Title        = track.Title,
                Description  = track.Author,
                ThumbnailUrl = artwork,
                Url          = track.Url,
                Author       = new EmbedAuthorBuilder
                {
                    Name = "Next Up!"
                },
                Footer = new EmbedFooterBuilder
                {
                    Text =
                        $"This track was requested by {requestingUser.Username}#{requestingUser.Discriminator}",
                    IconUrl = requestingUser.GetAvatarUrl()
                },
                Color = Color.Green
            }
            .AddField("Duration", $@"{track.Duration:mm\:ss}");

            //await args.Player.TextChannel.SendMessageAsync("", false, EmbedHandler.GenerateEmbedResponse($"{args.Reason}: {args.Track.Title}\nNow playing: {track.Title}"));
            await args.Player.TextChannel.SendMessageAsync("", false, embed.Build());
        }
Exemple #9
0
        public async Task SkipAsync()
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));

                return;
            }

            if (player.PlayerState != PlayerState.Playing)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("Woaaah there, I can't skip when nothing is playing."));

                return;
            }

            var voiceChannelUsers = (player.VoiceChannel as SocketVoiceChannel).Users.Where(x => !x.IsBot).ToArray();

            if (this._musicService.VoteQueue.Contains(this.Context.User.Id))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("You can't vote again."));

                return;
            }

            this._musicService.VoteQueue.Add(this.Context.User.Id);
            var percentage = this._musicService.VoteQueue.Count / voiceChannelUsers.Length * 100;

            if (percentage < 85)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("You need more than 85% votes to skip this song."));

                return;
            }

            try
            {
                var oldTrack     = player.Track;
                var currentTrack = await player.SkipAsync();

                _musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id).QueuedItems
                .RemoveAll(x => x.Track.Id == oldTrack.Id);

                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"Skipped: {oldTrack.Title}\nNow Playing: {currentTrack.Title}"));
            }
            catch (Exception exception)
            {
                await this.ReplyAsync(exception.Message);
            }
        }
Exemple #10
0
        public async Task ExportQueue()
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));

                return;
            }

            if (player.Queue.Count == 0)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("There is nothing queued to play right now."));

                return;
            }

            var embed = new EmbedBuilder
            {
                Author = new EmbedAuthorBuilder
                {
                    Name = "Queued Tracks (next 10)"
                },
                Footer = new EmbedFooterBuilder
                {
                    Text =
                        $"There is a total of {_musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id).QueuedItems.Count} songs in the queue",
                    IconUrl = this.Context.Client.CurrentUser.GetAvatarUrl()
                },
                Color = Color.Green
            };

            foreach (var queuedItem in _musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id).QueuedItems)
            {
                embed.Fields.Add(new EmbedFieldBuilder
                {
                    IsInline = false,
                    Name     = $"[{queuedItem.Track.Title} - {queuedItem.Track.Author}]{queuedItem.Track.Url}",
                    Value    =
                        $"Requested by {queuedItem.RequestingUser.Username}#{queuedItem.RequestingUser.Discriminator}"
                });

                if (embed.Fields.Count == 10)
                {
                    break;
                }
            }

            await this.ReplyAsync("", false, embed.Build());
        }
        public static async Task HandleChannelPair([NotNull] SocketUser user, SocketVoiceState oldVoiceState,
                                                   SocketVoiceState newVoiceState, DiscordSocketClient discord)
        {
            var oldGuild = oldVoiceState.VoiceChannel?.Guild;
            var newGuild = newVoiceState.VoiceChannel?.Guild;

            var oldChannelGuid = oldVoiceState.VoiceChannel == null ? string.Empty : oldVoiceState.VoiceChannel.Id.ToString();
            var newChannelGuid = newVoiceState.VoiceChannel == null ? string.Empty : newVoiceState.VoiceChannel.Id.ToString();

            var oldPair = string.IsNullOrEmpty(oldChannelGuid) ? null : await DynamoSystem.GetItemAsync <ChannelPair>(oldChannelGuid);

            var newPair = string.IsNullOrEmpty(newChannelGuid) ? null : await DynamoSystem.GetItemAsync <ChannelPair>(newChannelGuid);

            if (oldPair == null && newPair == null)
            {
                return;
            }

            var oldGuildUser = oldGuild?.GetUser(user.Id);
            var newGuildUser = newGuild?.GetUser(user.Id);

            if (oldPair != null && oldGuild != null)
            {
                var role = oldGuild?.Roles.SingleOrDefault(x => x.Id.ToString() == oldPair.RoleGuid);
                if (role != null)
                {
                    await oldGuildUser.RemoveRoleAsync(role);
                }
                var embed = EmbedHandler.GenerateEmbedResponse(
                    $"\u274C {user.Username} has left {oldVoiceState.VoiceChannel?.Name}",
                    Color.Red);
                await oldGuild.TextChannels.Single(x => x.Id.ToString() == oldPair.TextChannelGuid)
                .SendMessageAsync("", false, embed);
            }

            if (newPair != null && newGuild != null)
            {
                var role = newGuild?.Roles.SingleOrDefault(x => x.Id.ToString() == newPair.RoleGuid);
                if (role != null)
                {
                    await newGuildUser.AddRoleAsync(role);
                }
                var embed = EmbedHandler.GenerateEmbedResponse(
                    $"\u2705 {user.Username} has joined {newVoiceState.VoiceChannel?.Name}",
                    Color.Green);
                await newGuild.TextChannels.Single(x => x.Id.ToString() == newPair.TextChannelGuid)
                .SendMessageAsync("", false, embed);
            }
        }
Exemple #12
0
        private static async Task OnJoiningGuild([NotNull] SocketGuild arg)
        {
            var item = new GuildInfo
            {
                GuildGuid = arg.Id.ToString(),
                GuildName = arg.Name
            };

            await DynamoSystem.PutItemAsync(item).ConfigureAwait(false);

            var embed = EmbedHandler.GenerateEmbedResponse(
                "Hey friends! Nice to meet you!\r\n" +
                "Type `!help` to get to know me more and find out what I can do!");
            await arg.DefaultChannel.SendMessageAsync("", false, embed);
        }
Exemple #13
0
        public async Task ShowOVHLyrics()
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));

                return;
            }

            if (player.PlayerState != PlayerState.Playing)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("Woaaah there, I'm not playing any tracks."));

                return;
            }

            var lyrics = await player.Track.FetchLyricsFromOVHAsync();

            if (string.IsNullOrWhiteSpace(lyrics))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"No lyrics found for {player.Track.Title}"));

                return;
            }

            var splitLyrics   = lyrics.Split('\n');
            var stringBuilder = new StringBuilder();

            foreach (var line in splitLyrics)
            {
                if (Range.Contains(stringBuilder.Length))
                {
                    await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"```{stringBuilder}```"));

                    stringBuilder.Clear();
                }
                else
                {
                    stringBuilder.AppendLine(line);
                }
            }

            await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"```{stringBuilder}```"));
        }
Exemple #14
0
        public async Task ResumeAsync()
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));

                return;
            }

            if (player.PlayerState != PlayerState.Paused)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I cannot resume when I'm not playing anything"));

                return;
            }

            await player.ResumeAsync();

            await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"Resumed: {player.Track.Title}"));
        }
Exemple #15
0
        public async Task VolumeAsync(ushort volume)
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));

                return;
            }

            try
            {
                await player.UpdateVolumeAsync(volume);

                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"I've changed the player volume to {volume}."));
            }
            catch (Exception exception)
            {
                await this.ReplyAsync(exception.Message);
            }
        }
Exemple #16
0
        public async Task StopAsync()
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));

                return;
            }

            if (player.PlayerState == PlayerState.Stopped)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("Woaaah there, I can't stop the stopped forced."));

                return;
            }


            await player.StopAsync();

            await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("No longer playing anything."));
        }
Exemple #17
0
        private async Task EnqueueTracks(SearchResponse searchResponse, LavaPlayer player)
        {
            if (!string.IsNullOrWhiteSpace(searchResponse.Playlist.Name))
            {
                foreach (var track in searchResponse.Tracks)
                {
                    player.Queue.Enqueue(track);
                    _musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id).QueuedItems
                    .Add(new QueuedItem(track, this.Context.User));
                }

                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"Enqueued {searchResponse.Tracks.Count} tracks."));
            }
            else
            {
                var track = searchResponse.Tracks[0];
                player.Queue.Enqueue(track);
                _musicService.MusicTrackQueues.Single(x => x.GuildId == this.Context.Guild.Id).QueuedItems
                .Add(new QueuedItem(track, this.Context.User));
                await this.ReplyAsync("", false, (await ProduceNowPlayingEmbed(track, this.Context.User)).Build());
            }
        }
Exemple #18
0
        public async Task SeekAsync([Remainder] string time)
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to a voice channel."));

                return;
            }

            if (player.PlayerState != PlayerState.Playing)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("Woaaah there, I can't seek when nothing is playing."));

                return;
            }


            var timeSpan = TimeSpan.Parse(time);
            await player.SeekAsync(timeSpan);

            await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"I've seeked `{player.Track.Title}` to {timeSpan}."));
        }
Exemple #19
0
        public async Task LeaveAsync()
        {
            if (!this._lavaNode.TryGetPlayer(this.Context.Guild, out var player))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm not connected to any voice channels"));

                return;
            }

            var voiceChannel = ((IVoiceState)this.Context.User).VoiceChannel ?? player.VoiceChannel;

            if (voiceChannel == null)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("Not sure which voice channel to disconnect from."));

                return;
            }

            await this._lavaNode.LeaveAsync(voiceChannel);

            await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"I've left {voiceChannel.Name}"));
        }
Exemple #20
0
        public async Task JoinAsync(ushort volume = 100)
        {
            if (volume > 100 || volume < 1)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("Sorry, I can't work out how loud you want me to be, try a number between 1 and 100", Color.Red));

                return;
            }

            if (this._lavaNode.HasPlayer(this.Context.Guild))
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("I'm already connected to a voice channel!", Color.Orange));

                return;
            }

            var voiceState = this.Context.User as IVoiceState;

            if (voiceState?.VoiceChannel == null)
            {
                await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse("You must be connected to a voice channel!", Color.Red));

                return;
            }

            await this._lavaNode.JoinAsync(voiceState.VoiceChannel, this.Context.Channel as ITextChannel);

            if (_musicService.MusicTrackQueues.All(x => x.GuildId != this.Context.Guild.Id))
            {
                _musicService.MusicTrackQueues.Add(new GuildTrackQueue(this.Context.Guild.Id));
            }

            //this._lavaNode.TryGetPlayer(this.Context.Guild, out var player);
            //await player.UpdateVolumeAsync(volume);
            await this.ReplyAsync("", false, EmbedHandler.GenerateEmbedResponse($"Joined {voiceState.VoiceChannel.Name}, my volume is {volume}"));
        }