예제 #1
0
        /// <summary>
        /// Gets the Bits leaderboard for the current channel.
        /// </summary>
        /// <param name="startedAt">The date when the leaderboard should start</param>
        /// <param name="period">The period to get the leaderboard for</param>
        /// <param name="userID">An optional user to get bits leaderboard data specifically for</param>
        /// <param name="count">The total amount of users to include</param>
        /// <returns>The Bits leaderboard</returns>
        public async Task <BitsLeaderboardModel> GetBitsLeaderboard(DateTimeOffset?startedAt = null, BitsLeaderboardPeriodEnum period = BitsLeaderboardPeriodEnum.All, string userID = null, int count = 10)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            if (startedAt != null)
            {
                parameters.Add("started_at", startedAt.GetValueOrDefault().ToRFC3339String());
            }
            if (userID != null)
            {
                parameters.Add("user_id", userID);
            }
            parameters.Add("period", period.ToString().ToLower());
            parameters.Add("count", count.ToString());

            string  parameterString = string.Join("&", parameters.Select(kvp => kvp.Key + "=" + kvp.Value));
            JObject jobj            = await this.GetJObjectAsync("bits/leaderboard?" + parameterString);

            if (jobj != null)
            {
                BitsLeaderboardModel result = new BitsLeaderboardModel();
                result.users      = ((JArray)jobj["data"]).ToTypedArray <BitsLeaderboardUserModel>();
                result.started_at = jobj["date_range"]["started_at"].ToString();
                result.ended_at   = jobj["date_range"]["ended_at"].ToString();
                return(result);
            }
            return(null);
        }
예제 #2
0
        public void GetBitsLeaderboard()
        {
            TestWrapper(async(TwitchConnection connection) =>
            {
                BitsLeaderboardModel result = await connection.NewAPI.Bits.GetBitsLeaderboard();

                Assert.IsNotNull(result);
                Assert.IsTrue(result.users.Count > 0);
            });
        }
예제 #3
0
        public override async Task <JObject> GetProcessedItem(UserViewModel user, IEnumerable <string> arguments, Dictionary <string, string> extraSpecialIdentifiers, StreamingPlatformTypeEnum platform)
        {
            List <OverlayLeaderboardItem> items = new List <OverlayLeaderboardItem>();

            if (this.LeaderboardType == OverlayLeaderboardListItemTypeEnum.CurrencyRank)
            {
                if (ChannelSession.Settings.Currency.ContainsKey(this.CurrencyID))
                {
                    CurrencyModel currency = ChannelSession.Settings.Currency[this.CurrencyID];
                    IEnumerable <UserDataModel> userDataList = SpecialIdentifierStringBuilder.GetUserOrderedCurrencyList(currency);
                    for (int i = 0; i < userDataList.Count() && items.Count < this.TotalToShow; i++)
                    {
                        UserDataModel userData = userDataList.ElementAt(i);
                        if (!userData.IsCurrencyRankExempt)
                        {
                            items.Add(new OverlayLeaderboardItem(new UserViewModel(userData), currency.GetAmount(userData).ToString()));
                        }
                    }
                }
            }
            else if (this.LeaderboardType == OverlayLeaderboardListItemTypeEnum.Bits && this.lastQuery.TotalMinutesFromNow() > 1)
            {
                BitsLeaderboardModel bitsLeaderboard = null;
                switch (this.BitsLeaderboardDateRange)
                {
                case BitsLeaderboardPeriodEnum.Day:
                    bitsLeaderboard = await ChannelSession.TwitchUserConnection.GetBitsLeaderboard(BitsLeaderboardPeriodEnum.Day, this.TotalToShow);

                    break;

                case BitsLeaderboardPeriodEnum.Week:
                    bitsLeaderboard = await ChannelSession.TwitchUserConnection.GetBitsLeaderboard(BitsLeaderboardPeriodEnum.Week, this.TotalToShow);

                    break;

                case BitsLeaderboardPeriodEnum.Month:
                    bitsLeaderboard = await ChannelSession.TwitchUserConnection.GetBitsLeaderboard(BitsLeaderboardPeriodEnum.Month, this.TotalToShow);

                    break;

                case BitsLeaderboardPeriodEnum.Year:
                    bitsLeaderboard = await ChannelSession.TwitchUserConnection.GetBitsLeaderboard(BitsLeaderboardPeriodEnum.Year, this.TotalToShow);

                    break;

                case BitsLeaderboardPeriodEnum.All:
                    bitsLeaderboard = await ChannelSession.TwitchUserConnection.GetBitsLeaderboard(BitsLeaderboardPeriodEnum.All, this.TotalToShow);

                    break;
                }
                this.lastQuery = DateTimeOffset.Now;

                if (bitsLeaderboard != null && bitsLeaderboard.users != null)
                {
                    foreach (BitsLeaderboardUserModel bitsUser in bitsLeaderboard.users.OrderBy(u => u.rank).Take(this.TotalToShow))
                    {
                        items.Add(new OverlayLeaderboardItem(bitsUser.user_name, bitsUser.score.ToString()));
                    }
                }
            }

            if (items.Count > 0)
            {
                await this.ProcessLeaderboardItems(items);
            }

            return(await base.GetProcessedItem(user, arguments, extraSpecialIdentifiers, platform));
        }