diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 3c8e3df9..9e267aee 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -256,6 +256,8 @@ static const CRPCCommand vRPCCommands[] = { "getmentions", &getmentions, false, true, false }, { "setspammsg", &setspammsg, false, false, false }, { "getspammsg", &getspammsg, false, false, false }, + { "setpreferredspamlang", &setpreferredspamlang, false, false, false }, + { "getpreferredspamlang", &getpreferredspamlang, false, false, false }, { "follow", &follow, false, true, false }, { "unfollow", &unfollow, false, true, false }, { "getfollowing", &getfollowing, false, true, false }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index d8776202..c1062254 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -209,6 +209,8 @@ extern json_spirit::Value getdirectmsgs(const json_spirit::Array& params, bool f extern json_spirit::Value getmentions(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value setspammsg(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getspammsg(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value setpreferredspamlang(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getpreferredspamlang(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value follow(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value unfollow(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getfollowing(const json_spirit::Array& params, bool fHelp); diff --git a/src/twister.cpp b/src/twister.cpp index dd78ab45..51e4022c 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1490,7 +1490,7 @@ void receivedSpamMessage(std::string const &message, std::string const &user) { LOCK(cs_spamMsg); bool hasSingleLangCode = (message.find("[") == message.rfind("[")); - bool hasPreferredLang = m_preferredSpamLang.length(); + bool hasPreferredLang = m_preferredSpamLang.length() > 2; bool isSameLang = hasPreferredLang && hasSingleLangCode && message.find(m_preferredSpamLang) != string::npos; bool currentlyEmpty = !m_receivedSpamMsgStr.length(); @@ -2325,6 +2325,38 @@ Value getspammsg(const Array& params, bool fHelp) return ret; } +Value setpreferredspamlang(const Array& params, bool fHelp) +{ + if (fHelp || (params.size() != 1)) + throw runtime_error( + "setpreferredspamlang \n" + "Set preferred spam language (or 'none')"); + + string strLangCode = params[0].get_str(); + + if (strLangCode == "none") { + m_preferredSpamLang = "[]"; + } else { + if( strLangCode.find("[") == string::npos ) { + m_preferredSpamLang = "[" + strLangCode + "]"; + } else { + m_preferredSpamLang = strLangCode; + } + } + + return Value(); +} + +Value getpreferredspamlang(const Array& params, bool fHelp) +{ + if (fHelp || (params.size() != 0)) + throw runtime_error( + "getpreferredspamlang\n" + "get preferred spam language"); + + return Value(m_preferredSpamLang); +} + Value follow(const Array& params, bool fHelp) { if (fHelp || (params.size() != 2))