Ejemplo n.º 1
0
        public async Task <ActionResult> PlayTrack(TrackPlayRequestDto trackPlayDto)
        {
            var track = await _unitOfWork.TrackRepository.GetTrackByYoutubeIdAsync(trackPlayDto.YoutubeId);

            if (track == null)
            {
                return(NotFound("Track with YoutubeId " + trackPlayDto.YoutubeId + "Not Found"));
            }

            ulong discordId;

            ulong.TryParse(User.GetDiscordId(), out discordId);

            var user = _client.GetUser(discordId);

            if (user != null)
            {
                var guild = user.MutualGuilds.FirstOrDefault();

                await _musicService.PlayTrack("https://youtu.be/" + track.YoutubeId, user, guild, trackPlayDto.PlayNow);

                return(Ok());
            }
            else
            {
                return(BadRequest("You must be connected to a Voice channel to play a track"));
            }
        }
Ejemplo n.º 2
0
        public ActionResult <UserDto> GetUserInfo()
        {
            var discordIdStr = User.GetDiscordId();

            if (discordIdStr != null)
            {
                var username  = User.GetUsername();
                var avatarUrl = User.GetAvatarUrl();

                var identity = User.Identity;

                ulong discordId;
                UInt64.TryParse(discordIdStr, out discordId);

                var userDto = new UserDto {
                    AvatarUrl = avatarUrl,
                    DiscordId = discordId,
                    Username  = username
                };

                return(Ok(userDto));
            }

            return(Ok(null));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <IEnumerable <TrackDto> > > GetTracks([FromQuery] PaginationParams paginationParams)
        {
            var tracks = await _unitOfWork.TrackRepository.GetTracks(paginationParams);

            var   discordIdStr = User.GetDiscordId();
            ulong discordId;

            UInt64.TryParse(discordIdStr, out discordId);

            // Set Liked Flag on Tracks
            foreach (var track in tracks)
            {
                track.LikedByUser = track.UserLikes.FirstOrDefault(user => user.DiscordId == discordId)?.Liked;;
            }

            Response.AddPaginationHeader(tracks.CurrentPage, tracks.ItemsPerPage, tracks.TotalPages, tracks.TotalCount);

            return(Ok(tracks));
        }