Automatically add “fascism” tag if “nazism” is present.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2021-01-23 23:18:03 +01:00
parent ed1972a011
commit 2816116136
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 24 additions and 0 deletions

View File

@ -77,6 +77,7 @@ entry_type parse_formdata()
}
entry.instance = cgi("instance");
if (!cgi("tags").empty()) // Old form.
{
entry.tags = string_to_vector(cgi("tags"));
@ -87,6 +88,8 @@ entry_type parse_formdata()
}
transform(entry.tags.begin(), entry.tags.end(), entry.tags.begin(),
[](const auto &tag) { return tolower(tag); });
add_tags(entry);
if (!cgi("receipts").empty()) // Old form.
{
entry.receipts = string_to_vector(cgi("receipts"));
@ -95,6 +98,7 @@ entry_type parse_formdata()
{
entry.receipts = get_array("receipts[]");
}
entry.description = cgi("description");
entry.report_time = time::to_string(system_clock::now());
@ -237,6 +241,17 @@ bool is_spam(const entry_type &entry)
return false;
}
void add_tags(entry_type &entry)
{
for (const auto &tag : entry.tags)
{
if (tag == "nazism")
{
entry.tags.emplace_back("fascism");
}
}
}
} // namespace FediBlock::cgi
const char *SpamException::what() const noexcept

View File

@ -56,6 +56,15 @@ bool captcha_valid(std::uint8_t id, string_view answer);
bool is_spam(const entry_type &entry);
/*!
* @brief Add automatic tags.
*
* Example: If tag nazism is present, add fascism.
*
* @since 0.1.0
*/
void add_tags(entry_type &entry);
} // namespace FediBlock::cgi
class SpamException : public std::exception