new filter: fwdfrom & chat
This commit is contained in:
parent
038dde8d8f
commit
ae48fe6510
|
@ -30,6 +30,8 @@ void loadFilter() {
|
||||||
filterlist.insert({"Filename", new FilenameFilter()});
|
filterlist.insert({"Filename", new FilenameFilter()});
|
||||||
filterlist.insert({"RegexFilename", new RegexFilenameFilter()});
|
filterlist.insert({"RegexFilename", new RegexFilenameFilter()});
|
||||||
filterlist.insert({"Date", new DateFilter()});
|
filterlist.insert({"Date", new DateFilter()});
|
||||||
|
filterlist.insert({"Chat", new FilterChat()});
|
||||||
|
filterlist.insert({"ForwordedFrom", new ForwardedFromChatFilter()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeFilter() {
|
void removeFilter() {
|
||||||
|
|
|
@ -13,3 +13,23 @@ void HasMediaFilter::setup(std::ostream& o, std::istream& str) {
|
||||||
bool HasMediaFilter::filter(const Message& m) const {
|
bool HasMediaFilter::filter(const Message& m) const {
|
||||||
return m.hasFile() == needMedia;
|
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;
|
||||||
|
}
|
|
@ -8,3 +8,17 @@ struct HasMediaFilter : public Filter {
|
||||||
protected:
|
protected:
|
||||||
bool needMedia; // true = msg should have media; false = mmessage should not have media
|
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;
|
||||||
|
};
|
|
@ -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())
|
if(m.contains("from_id") && m["from_id"].is_number_unsigned())
|
||||||
senderid = m["from_id"];
|
senderid = m["from_id"];
|
||||||
|
|
||||||
|
if(m.contains("forwarded_from") && m["forwarded_from"].is_string())
|
||||||
|
fwdFrom = m["forwarded_from"];
|
||||||
|
|
||||||
if(m.contains("date")) {
|
if(m.contains("date")) {
|
||||||
tm parsedTime;
|
tm parsedTime;
|
||||||
::strptime(m["date"].get_ref<const std::string&>().c_str(), "%Y-%m-%dT%T", &parsedTime);
|
::strptime(m["date"].get_ref<const std::string&>().c_str(), "%Y-%m-%dT%T", &parsedTime);
|
||||||
|
|
|
@ -8,6 +8,7 @@ struct Message {
|
||||||
int64_t chatid = 0;
|
int64_t chatid = 0;
|
||||||
int64_t messageid = 0;
|
int64_t messageid = 0;
|
||||||
int64_t senderid = 0;
|
int64_t senderid = 0;
|
||||||
|
std::string fwdFrom;
|
||||||
std::string text = "";
|
std::string text = "";
|
||||||
std::string filename = ""; //empty filename = no file
|
std::string filename = ""; //empty filename = no file
|
||||||
time_t date = 0;
|
time_t date = 0;
|
||||||
|
|
Loading…
Reference in New Issue