示例#1
0
 //Downloads users that meet minutes watched criteria
 private async Task <List <string> > downloadMinuteEntries(int minutes, List <string> entries)
 {
     return(await WebCalls.downloadMinuteEntries(minutes, entries));
 }
示例#2
0
        // Async drawing function, accepts param bool indicating a redraw, returns bool indicating success
        private async Task <bool> processDrawAsync(bool redraw = false)
        {
            //Validate drawing process
            if (redraw == true)
            {
                enteredViewers.Remove(activeWinner);
            }
            if (enteredViewers.Count < raffleProperties.Raffle_Minimum_Entries)
            {
                claimTimer.Stop();
                Common.ChatClient.SendMessage(string.Format("/me GIVEAWAY ERROR: Entry count below minimum ({0}) required for giveaway to proceed. [FATAL]", raffleProperties.Raffle_Minimum_Entries), Common.DryRun);
                return(false);
            }
            //Check filters
            List <string> filteredEntries = null;
            List <string> masterList      = enteredViewers;

            switch (raffleProperties.Raffle_Filter)
            {
            case RaffleProperties.Filters.DOUBLOONS:
                filteredEntries = await WebCalls.downloadDoubloonEntries(raffleProperties.Raffle_Filter_Amount, enteredViewers);

                masterList = filteredEntries;
                break;

            case RaffleProperties.Filters.MINUTES:
                filteredEntries = await WebCalls.downloadMinuteEntries(raffleProperties.Raffle_Filter_Amount, enteredViewers);

                masterList = filteredEntries;
                break;

            case RaffleProperties.Filters.NONE:
                break;
            }
            //Validate filters
            if (raffleProperties.Raffle_Filter != RaffleProperties.Filters.NONE && (filteredEntries == null || filteredEntries.Count < raffleProperties.Raffle_Minimum_Entries))
            {
                Common.ChatClient.SendMessage("/me GIVEAWAY ERROR: Filtered raffle entry results failed or falls below minimum required entries.  Resorting to original entry list [NON-FATAL]", Common.DryRun);
                masterList = enteredViewers;
            }
            //Draw winner and perform follower/sub only checks
            bool   resultFound = false;
            string winner      = "";
            //Create local list of non-blocked users
            List <string> drawFromList = new List <string>();

            foreach (string entry in masterList)
            {
                if (!raffleProperties.Blocked_Viewers.Contains(entry))
                {
                    drawFromList.Add(entry);
                }
            }
            while (resultFound == false)
            {
                if (drawFromList.Count < raffleProperties.Raffle_Minimum_Entries)
                {
                    resultFound = true;
                    Common.ChatClient.SendMessage("/me GIVEAWAY ERROR: Entry count has fallen below required minimum entry count. [FATAL]", Common.DryRun);
                    return(false);
                }

                winner = drawFromList[new Random().Next(0, drawFromList.Count)];
                if (raffleProperties.Follower_Only)
                {
                    if (!await TwitchLib.TwitchApi.UserFollowsChannel(winner, "burkeblack"))
                    {
                        drawFromList.Remove(winner);
                        Common.ChatClient.SendMessage(string.Format("Winner ({0}) does not follow BurkeBlack! Redrawing..."), Common.DryRun);
                        continue;
                    }
                }
                if (raffleProperties.Sub_Only)
                {
                    if (!TwitchLib.TwitchApi.ChannelHasUserSubscribed(winner, "burkeblack", Properties.Settings.Default.BurkeOAuth).Result)
                    {
                        drawFromList.Remove(winner);
                        Common.ChatClient.SendMessage(string.Format("Winner ({0}) is not subscribed BurkeBlack! Redrawing..."), Common.DryRun);
                        continue;
                    }
                }
                resultFound = true;
            }
            if (!redraw)
            {
                Common.ChatClient.SendMessage(string.Format("/me GIVEAWAY WINNER: {0} (out of {1} total entries, draw percentage: {2}%)", winner, masterList.Count, (Math.Round(((double)1 / masterList.Count), 2) * 100)), Common.DryRun);
            }
            else
            {
                Common.ChatClient.SendMessage(string.Format("/me GIVEAWAY REDRAW WINNER: {0} (out of {1} total entries, draw percentage: {2}%)", winner, masterList.Count, (Math.Round(((double)1 / masterList.Count), 2) * 100)), Common.DryRun);
            }
            Common.ChatClient.SendMessage(string.Format("/me You have {0} minutes to claim your giveaway, {1}. Use !claim to claim. Use !pass to pass on the giveaway and have the bot draw a new winner.", raffleProperties.Raffle_Claim_Length, winner), Common.DryRun);
            claimCurrentSecond = 0;
            activeWinner       = winner;
            claimTimer.Start();
            Common.initialize("Claim timer started.");
            return(true);
        }