From 98a2c7ff4e0345170910b805b3747151113641b9 Mon Sep 17 00:00:00 2001 From: Phil B Date: Tue, 8 Nov 2022 22:40:28 +0100 Subject: [PATCH] feat: added automod regex support --- include/dpp/automod.h | 13 +++++++++++-- src/dpp/automod.cpp | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/dpp/automod.h b/include/dpp/automod.h index aade98259f..cceaca6d15 100644 --- a/include/dpp/automod.h +++ b/include/dpp/automod.h @@ -107,9 +107,10 @@ enum automod_trigger_type : uint8_t { */ struct DPP_EXPORT automod_metadata : public json_interface { /** - * @brief @brief Substrings which will be searched for in content. + * @brief @brief Substrings which will be searched for in content (Maximum of 1000). * - * Each keyword can be a phrase which contains multiple words. All keywords are case insensitive. + * Each keyword can be a phrase which contains multiple words. + * All keywords are case insensitive and can be up to 30 characters. * * Wildcard symbols (`*`) can be used to customize how each keyword will be matched. * @@ -146,6 +147,14 @@ struct DPP_EXPORT automod_metadata : public json_interface { */ std::vector keywords; + /** + * @brief Regular expression patterns which will be matched against content (Maximum of 10). + * + * Only Rust flavored regex is currently supported, which can be tested in online editors such as [Rustexp](https://rustexp.lpil.uk/). + * Each regex pattern must be 75 characters or less. + */ + std::vector regex_patterns; + /** * @brief Preset keyword list types to moderate * @see automod_preset_type diff --git a/src/dpp/automod.cpp b/src/dpp/automod.cpp index f09f085997..db00455a0e 100644 --- a/src/dpp/automod.cpp +++ b/src/dpp/automod.cpp @@ -78,6 +78,9 @@ automod_metadata& automod_metadata::fill_from_json(nlohmann::json* j) { for (auto k : (*j)["keyword_filter"]) { keywords.push_back(k); } + for (auto k : (*j)["regex_patterns"]) { + regex_patterns.push_back(k); + } for (auto k : (*j)["presets"]) { presets.push_back((automod_preset_type)k.get()); } @@ -91,15 +94,19 @@ automod_metadata& automod_metadata::fill_from_json(nlohmann::json* j) { std::string automod_metadata::build_json(bool with_id) const { json j; j["keyword_filter"] = json::array(); + j["regex_patterns"] = json::array(); j["presets"] = json::array(); j["allow_list"] = json::array(); - for (auto v : keywords) { + for (auto &v : keywords) { j["keyword_filter"].push_back(v); } + for (auto &v : regex_patterns) { + j["regex_patterns"].push_back(v); + } for (auto v : presets) { j["presets"].push_back((uint32_t)v); } - for (auto v : allow_list) { + for (auto &v : allow_list) { j["allow_list"].push_back(v); } j["mention_total_limit"] = mention_total_limit;