From 9a2ce8a4b91511bc99558e99956cccc6e0e38bc0 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 15 Feb 2023 11:43:32 -0500 Subject: Added profane filter --- lingo.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'lingo.cpp') diff --git a/lingo.cpp b/lingo.cpp index b461ad8..c4d9b6c 100644 --- a/lingo.cpp +++ b/lingo.cpp @@ -428,6 +428,15 @@ public: scoreboard_endpoint_ = config["scoreboard_endpoint"].as(); scoreboard_secret_code_ = config["scoreboard_secret_code"].as(); + std::string profaneFilename = config["profane"].as(); + { + std::ifstream profaneFile(profaneFilename); + std::string line; + while (std::getline(profaneFile, line)) { + profane_.insert(line); + } + } + for (;;) { sendPuzzle(channel); @@ -479,6 +488,20 @@ private: return false; } + bool isProfane(const verbly::form& clue) const { + if (clue.getComplexity() == 1) { + return profane_.count(clue.getText()); + } else { + auto words = hatkirby::split>(clue.getText(), " "); + for (const std::string& word : words) { + if (profane_.count(word)) { + return true; + } + } + return false; + } + } + void generatePuzzle() { std::cout << "Generating puzzle..." << std::endl; @@ -637,6 +660,11 @@ private: std::cout << "Solution decided: " << solution.getText() << std::endl; + if (isProfane(solution)) { + std::cout << "Solution is profane" << std::endl; + continue; + } + std::array, kHeightCount> chosenHints; bool made_puzzle = false; @@ -645,6 +673,7 @@ private: verbly::filter admissible = cleanFilter && (verbly::form::proper == false) && (verbly::form::length == static_cast(solution.getText().size())); std::ostringstream msg_stream; bool trivial = false; + bool profane = false; for (int i=0; i(kHeightCount); i++) { Height height = static_cast(i); std::optional& colour = parts[i]; @@ -663,6 +692,9 @@ private: trivial = true; break; } + if (isProfane(questionPart)) { + profane = true; + } admissible &= makeHintFilter(questionPart, height, *colour, kTowardSolution); } @@ -674,6 +706,11 @@ private: std::cout << "Puzzle is trivial." << std::endl; continue; } + if (profane) + { + std::cout << "Puzzle is profane." << std::endl; + continue; + } if (parts[static_cast(kTop)].has_value() && !parts[static_cast(kMiddle)].has_value() @@ -933,6 +970,7 @@ private: std::string scoreboard_secret_code_; std::unique_ptr wanderlust_; std::string fontpath_; + std::set profane_; std::map answer_by_message_; std::set solved_puzzles_; -- cgit 1.4.1