new filter: fwdfrom & chat

This commit is contained in:
mrbesen 2021-06-06 22:44:54 +02:00
parent 038dde8d8f
commit ae48fe6510
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
5 changed files with 40 additions and 0 deletions

View File

@ -30,6 +30,8 @@ void loadFilter() {
filterlist.insert({"Filename", new FilenameFilter()});
filterlist.insert({"RegexFilename", new RegexFilenameFilter()});
filterlist.insert({"Date", new DateFilter()});
filterlist.insert({"Chat", new FilterChat()});
filterlist.insert({"ForwordedFrom", new ForwardedFromChatFilter()});
}
void removeFilter() {

View File

@ -12,4 +12,24 @@ void HasMediaFilter::setup(std::ostream& o, std::istream& str) {
bool HasMediaFilter::filter(const Message& m) const {
return m.hasFile() == needMedia;
}
void FilterChat::setup(std::ostream& o, std::istream& str) {
o << "Enter Chatid: ";
str >> chatid;
}
bool FilterChat::filter(const Message& m) const {
return m.chatid == chatid;
}
void ForwardedFromChatFilter::setup(std::ostream& o, std::istream& str) {
o << "Enter ChatName: ";
std::getline(str, chatname);
}
bool ForwardedFromChatFilter::filter(const Message& m) const {
return m.fwdFrom == chatname;
}

View File

@ -7,4 +7,18 @@ struct HasMediaFilter : public Filter {
virtual bool filter(const Message& m) const;
protected:
bool needMedia; // true = msg should have media; false = mmessage should not have media
};
struct FilterChat : public Filter {
virtual void setup(std::ostream& o, std::istream& str);
virtual bool filter(const Message& m) const;
protected:
int64_t chatid;
};
struct ForwardedFromChatFilter : public Filter {
virtual void setup(std::ostream& o, std::istream& str);
virtual bool filter(const Message& m) const;
protected:
std::string chatname;
};

View File

@ -32,6 +32,9 @@ Message::Message(const json& m, int64_t chatid) : chatid(chatid) {
if(m.contains("from_id") && m["from_id"].is_number_unsigned())
senderid = m["from_id"];
if(m.contains("forwarded_from") && m["forwarded_from"].is_string())
fwdFrom = m["forwarded_from"];
if(m.contains("date")) {
tm parsedTime;
::strptime(m["date"].get_ref<const std::string&>().c_str(), "%Y-%m-%dT%T", &parsedTime);

View File

@ -8,6 +8,7 @@ struct Message {
int64_t chatid = 0;
int64_t messageid = 0;
int64_t senderid = 0;
std::string fwdFrom;
std::string text = "";
std::string filename = ""; //empty filename = no file
time_t date = 0;