Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added automod regex support #547

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions include/dpp/automod.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ enum automod_trigger_type : uint8_t {
*/
struct DPP_EXPORT automod_metadata : public json_interface<automod_metadata> {
/**
* @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.
*
Expand Down Expand Up @@ -146,6 +147,14 @@ struct DPP_EXPORT automod_metadata : public json_interface<automod_metadata> {
*/
std::vector<std::string> 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<std::string> regex_patterns;

/**
* @brief Preset keyword list types to moderate
* @see automod_preset_type
Expand Down
11 changes: 9 additions & 2 deletions src/dpp/automod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>());
}
Expand All @@ -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;
Expand Down