private async Task PotentialGuess(SocketMessage msg) { try { if (!(msg is SocketUserMessage)) { return; } if (msg.Channel != GameChannel) { return; // message's channel has to be the same as game's } if (msg.Content.Length == 1) // message must be 1 char long { if (++MessagesSinceLastPost > 10) { MessagesSinceLastPost = 0; try { await GameChannel.SendConfirmAsync("Hangman Game", ScrambledWord + "\n" + GetHangman(), footer : string.Join(" ", Guesses)).ConfigureAwait(false); } catch { } } if (!(char.IsLetter(msg.Content[0]) || char.IsDigit(msg.Content[0])))// and a letter or a digit { return; } var guess = char.ToUpperInvariant(msg.Content[0]); if (Guesses.Contains(guess)) { MessagesSinceLastPost = 0; ++Errors; if (Errors < MaxErrors) { await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` has already been used.\n" + ScrambledWord + "\n" + GetHangman(), footer : string.Join(" ", Guesses)).ConfigureAwait(false); } else { await End().ConfigureAwait(false); } return; } Guesses.Add(guess); /*int HangmanCurrencyRewardAll = 5; * int HangmanCurrencyRewardLetter = 1;*/ if (Term.Word.ToUpperInvariant().Contains(guess)) { if (GuessedAll) { try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!").ConfigureAwait(false); } catch { } // giving reward if (NadekoBot.BotConfig.HangmanCurrencyRewardAll > 0) { await CurrencyHandler.AddCurrencyAsync(msg.Author, $"Received {NadekoBot.BotConfig.CurrencyPluralName}", NadekoBot.BotConfig.HangmanCurrencyRewardAll, false).ConfigureAwait(false); await GameChannel.SendConfirmAsync($"**{msg.Author}** received {NadekoBot.BotConfig.HangmanCurrencyRewardAll} {NadekoBot.BotConfig.CurrencySign}!").ConfigureAwait(false); } await End().ConfigureAwait(false); return; } MessagesSinceLastPost = 0; try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!\n" + ScrambledWord + "\n" + GetHangman(), footer : string.Join(" ", Guesses)).ConfigureAwait(false); if (NadekoBot.BotConfig.HangmanCurrencyRewardLetter > 0) { await CurrencyHandler.AddCurrencyAsync(msg.Author, $"Received {NadekoBot.BotConfig.CurrencyPluralName}", NadekoBot.BotConfig.HangmanCurrencyRewardLetter, false).ConfigureAwait(false); await GameChannel.SendConfirmAsync($"**{msg.Author}** received {NadekoBot.BotConfig.HangmanCurrencyRewardLetter} {NadekoBot.BotConfig.CurrencySign}!").ConfigureAwait(false); } } catch { } } else { MessagesSinceLastPost = 0; ++Errors; if (Errors < MaxErrors) { await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` does not exist.\n" + ScrambledWord + "\n" + GetHangman(), footer : string.Join(" ", Guesses)).ConfigureAwait(false); } else { await End().ConfigureAwait(false); } } } } catch (Exception ex) { _log.Warn(ex); } }
private async Task PotentialGuess(SocketMessage msg) { try { if (!(msg is SocketUserMessage)) { return; } if (msg.Channel != GameChannel) { return; // message's channel has to be the same as game's } if (msg.Content.Length == 1) // message must be 1 char long { if (++MessagesSinceLastPost > 10) { MessagesSinceLastPost = 0; try { await GameChannel.SendConfirmAsync("Hangman Game", ScrambledWord + "\n" + GetHangman(), footer : string.Join(" ", Guesses)).ConfigureAwait(false); } catch { } } if (!(char.IsLetter(msg.Content[0]) || char.IsDigit(msg.Content[0])))// and a letter or a digit { return; } var guess = char.ToUpperInvariant(msg.Content[0]); if (Guesses.Contains(guess)) { MessagesSinceLastPost = 0; ++Errors; if (Errors < MaxErrors) { await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` has already been used.\n" + ScrambledWord + "\n" + GetHangman(), footer : string.Join(" ", Guesses)).ConfigureAwait(false); } else { await End().ConfigureAwait(false); } return; } Guesses.Add(guess); if (Term.Word.ToUpperInvariant().Contains(guess)) { if (GuessedAll) { try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!").ConfigureAwait(false); } catch { } await End().ConfigureAwait(false); return; } MessagesSinceLastPost = 0; try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!\n" + ScrambledWord + "\n" + GetHangman(), footer : string.Join(" ", Guesses)).ConfigureAwait(false); } catch { } } else { MessagesSinceLastPost = 0; ++Errors; if (Errors < MaxErrors) { await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` does not exist.\n" + ScrambledWord + "\n" + GetHangman(), footer : string.Join(" ", Guesses)).ConfigureAwait(false); } else { await End().ConfigureAwait(false); } } } } catch (Exception ex) { _log.Warn(ex); } }
private Task PotentialGuess(IMessage msg) { if (msg.Channel != GameChannel) { return(Task.CompletedTask); // message's channel has to be the same as game's } if (msg.Content.Length != 1) // message must be 1 char long { if (++MessagesSinceLastPost > 10) { MessagesSinceLastPost = 0; Task.Run(async() => { try { await GameChannel.SendConfirmAsync("Hangman Game", ScrambledWord + "\n" + GetHangman()).ConfigureAwait(false); } catch { } }); } return(Task.CompletedTask); } if (!(char.IsLetter(msg.Content[0]) || char.IsDigit(msg.Content[0])))// and a letter or a digit { return(Task.CompletedTask); } var guess = char.ToUpperInvariant(msg.Content[0]); // todo hmmmm // how do i want to limit the users on guessing? // one guess every 5 seconds if wrong? Task.Run(async() => { try { if (Guesses.Contains(guess)) { ++Errors; if (Errors < MaxErrors) { await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` has already been used.\n" + ScrambledWord + "\n" + GetHangman()).ConfigureAwait(false); } else { await End().ConfigureAwait(false); } return; } Guesses.Add(guess); if (Term.Word.ToUpperInvariant().Contains(guess)) { if (GuessedAll) { try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!").ConfigureAwait(false); } catch { } await End().ConfigureAwait(false); return; } try { await GameChannel.SendConfirmAsync("Hangman Game", $"{msg.Author.Mention} guessed a letter `{guess}`!\n" + ScrambledWord + "\n" + GetHangman()).ConfigureAwait(false); } catch { } } else { ++Errors; if (Errors < MaxErrors) { await GameChannel.SendErrorAsync("Hangman Game", $"{msg.Author.Mention} Letter `{guess}` does not exist.\n" + ScrambledWord + "\n" + GetHangman()).ConfigureAwait(false); } else { await End().ConfigureAwait(false); } } } catch { } }); return(Task.CompletedTask); }