Пример #1
0
        private async Task <SpotifyWebAPI> GetClient(ulong userId, IMessageChannel responseChannel, bool otherUser)
        {
            var account = await _accountsService.GetUserAccountAsync(userId, CancellationToken.None);

            if (account != null)
            {
                try
                {
                    var result = await SpotifyHelpers.RefreshToken(account.RefreshToken, _integrationOptions.Value.SpotifyId, _integrationOptions.Value.SpotifyKey);

                    return(new SpotifyWebAPI()
                    {
                        AccessToken = result.Token,
                        TokenType = "Bearer"
                    });
                }
                catch (WebException ex) when((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.BadRequest)
                {
                    // Failed to connect, fall through
                }
            }

            var author = new EmbedAuthorBuilder()
                         .WithName(otherUser ? "Account not connected" : "Connect your Spotify")
                         .WithUrl(_websiteWalker.SpotifyConnectUrl)
                         .WithIconUrl(_websiteWalker.SpotifyIconUrl);

            var embed = new EmbedBuilder()
                        .WithAuthor(author)
                        .WithDescription((otherUser ? "This user hasn't connected their account yet." : "You have not connected your account yet.") + $" Click [here]({_websiteWalker.SpotifyConnectUrl}) to connect.");

            await _communicator.SendMessage(responseChannel, embed.Build());

            throw new AbortException();
        }
Пример #2
0
        public void UpdateTitle()
        {
            var newTitle = SpotifyHelpers.GetWindowTitle();

            if (WindowTitle != newTitle)
            {
                WindowTitle = newTitle;
                UpdateLyrics();
            }
        }
Пример #3
0
        private async Task <SpotifyWebAPI> GetClient()
        {
            var token = await SpotifyHelpers.GetClientToken(_integrationOptions.Value.SpotifyId, _integrationOptions.Value.SpotifyKey);

            return(new SpotifyWebAPI()
            {
                AccessToken = token.Token,
                TokenType = "Bearer"
            });
        }