private async void PotentialGuess(object sender, MessageEventArgs e) { try { if (e.Channel.IsPrivate) { return; } if (e.Server != server) { return; } if (e.User.Id == WizBot.Client.CurrentUser.Id) { return; } var guess = false; await _guessLock.WaitAsync().ConfigureAwait(false); try { if (GameActive && CurrentQuestion.IsAnswerCorrect(e.Message.Text) && !triviaCancelSource.IsCancellationRequested) { Users.TryAdd(e.User, 0); //add if not exists Users[e.User]++; //add 1 point to the winner guess = true; } } finally { _guessLock.Release(); } if (!guess) { return; } triviaCancelSource.Cancel(); await channel.SendMessage($"☑️ {e.User.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**").ConfigureAwait(false); if (Users[e.User] != WinRequirement) { return; } ShouldStopGame = true; await channel.Send($":exclamation: We have a winner! It's {e.User.Mention}.").ConfigureAwait(false); // add points to the winner await FlowersHandler.AddFlowersAsync(e.User, "Won Trivia", 2).ConfigureAwait(false); } catch { } }
private async void PotentialGuess(object sender, MessageEventArgs e) { try { if (e.Channel.IsPrivate) { return; } if (e.Server != _server) { return; } bool guess = false; lock (_guessLock) { if (GameActive && CurrentQuestion.IsAnswerCorrect(e.Message.Text) && !triviaCancelSource.IsCancellationRequested) { users.TryAdd(e.User, 0); //add if not exists users[e.User]++; //add 1 point to the winner guess = true; } } if (guess) { triviaCancelSource.Cancel(); await _channel.SendMessage($"☑️ {e.User.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**"); if (users[e.User] == WinRequirement) { ShouldStopGame = true; await _channel.Send($":exclamation: We have a winner! Its {e.User.Mention}."); // add points to the winner await FlowersHandler.AddFlowersAsync(e.User, "Won Trivia", 2); } } } catch { } }
private async void PotentialGuess(object sender, MessageEventArgs e) { try { var guess = false; await _guessLock.WaitAsync().ConfigureAwait(false); try { if (GameActive && CurrentQuestion.IsAnswerCorrect(e.Message.Text) && !TriviaCancelSource.IsCancellationRequested) { Users.TryAdd(e.User, 0); Users[e.User]++; guess = true; } } finally { _guessLock.Release(); } if (!guess) { return; } TriviaCancelSource.Cancel(); await Channel.SendMessage("correct answer guessed").ConfigureAwait(false); if (Users[e.User] != WinRequirement) { return; } ShouldStopGame = true; await Channel.SendMessage("winner winner chicken dinner"); } catch { } }