public void StartPoll(ChallengePollOptions options) { if (_IsPollRunning == true) { _Logger.LogWarning($"Not starting new poll: already running"); return; } if (options.Possible.Count <= 0) { _Logger.LogWarning($"Not starting new poll: no options given"); return; } if (options.VoteTime <= 0) { _Logger.LogWarning($"Not starting new poll: vote time is equal to or less than 0"); return; } _PollTimerLeft = options.VoteTime; _TimerLastTick = DateTime.UtcNow; _IsPollRunning = true; _PollOptions = options; _PollTotalTicks = 0; _PollResults = new ChallengePollResults(); int index = 1; foreach (int challengeID in options.Possible) { IRunChallenge?challenge = _AllChallenges.FirstOrDefault(iter => iter.ID == challengeID); if (challenge == null) { _Logger.LogWarning($"Failed to find challenge {challengeID}"); continue; } _PollResults.Options.Add(index++, new ChallengePollResult(challenge) { ChallengeID = challengeID }); _Logger.LogTrace($"Added challenge {challenge.ID}/{challenge.Name} to poll at index {index - 1}"); } _ChallengeEvents.EmitPollStarted(_PollResults); _ChallengeEvents.EmitPollTimerUpdate(_PollTimerLeft); _PollTimer.Start(); _Logger.LogDebug($"Starting new poll, will finish after {options.VoteTime}"); }
private void StartAutoChallenge() { if (_AutoSettings.OptionCount <= 0) { _Logger.LogWarning($"Cannot start auto poll, there are 0 options"); return; } List <IRunChallenge> challenges = _Challenges.GetActive().Shuffle(); if (_AutoSettings.OptionCount > challenges.Count) { _Logger.LogWarning($"Setting auto challenge option count to {challenges.Count}, was {_AutoSettings.OptionCount}, which is more than options available"); _AutoSettings.OptionCount = challenges.Count; } ChallengePollOptions options = new ChallengePollOptions() { Possible = challenges.Take(_AutoSettings.OptionCount).Select(i => i.ID).ToList(), VoteTime = _AutoSettings.PollTime }; _Challenges.StartPoll(options); }