コード例 #1
0
        public async Task <TwitchRequests.TwitchUser> GetTwitchUserAsync(ISession session, string token = null)
        {
            var str = session.GetString(TwitchUser);

            if (string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(token))
            {
                var twitch = new TwitchRequests(token);
                var user   = await twitch.GetUsersAsync();

                if (user != null)
                {
                    await SetTwitchUserAsync(session, user);
                }
                str = user;
            }

            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }

            try
            {
                return(JSON.Parse <TwitchRequests.TwitchUserData>(str).Data?.FirstOrDefault());
            }
            catch (Exception exc)
            {
                await logger.WriteErrorAsync("GET TWITCH USER (" + session.Id + "): " + str + " --- PARSE ERROR (EXCEPTION): " + exc);

                return(JSON.Parse <TwitchRequests.TwitchUser>(str));
            }
        }
コード例 #2
0
        public async Task <string> GetTwitchUser()
        {
            if (!this.sessionInfoProvider.TryGetTwitchToken(HttpContext.Session, out var key))
            {
                return("nope");
            }

            var twitch     = new TwitchRequests(key);
            var twitchUser = await twitch.GetUsersAsync();

            await this.sessionInfoProvider.SetTwitchUserAsync(HttpContext.Session, twitchUser);

            return(twitchUser);
        }