#include "posts.h" #include "config.h" #include #include #include #include using namespace posts; static std::regex vkRegex("«\\s*#[A-Za-z0-9\\-_.А-Яа-яЁё]+@mmcs_quotes\\s*»"); static std::regex tgRegex1("#цитат(а|ы)"); static std::regex tgRegex2("- "); bool posts::filter_and_transform(AbstractPost &post) { if (post.sourceType == SRC_VK) { bool hasHashtag = std::regex_search(post.text, vkRegex); if (!hasHashtag) return false; return true; } else { if (std::regex_search(post.text, tgRegex1)) return true; int lastLinebreak = post.text.find_last_of('\n'); std::string lastLine = post.text.substr(lastLinebreak == -1 ? 0 : lastLinebreak, post.text.size()); if (std::regex_search(lastLine, tgRegex2)) { post.text = post.text.substr(0, lastLinebreak); return true; } return false; } } std::string_view posts::add_signature(AbstractPost &post, config::AppConfig *cfg) { int oldPostLength = post.text.length() + 1; std::string signature = "\nРепостнуто автоматически из "; if (post.sourceType == SRC_VK) { auto &wallId = cfg->vkSources[post.source].id; std::string shortname = std::holds_alternative(wallId) ? std::get(wallId) : cfg->vkSources[post.source].link; if (!shortname.empty()) signature += "vk.com/" + shortname; else signature += "VK"; post.text += signature; } else { std::string shortname = cfg->tgSources[post.source].link; if (!shortname.empty()) signature += "t.me/" + shortname; else signature += "Telegram"; post.text += signature; } return std::string_view(post.text.c_str() + oldPostLength, signature.length()); }