mirror of https://notabug.org/acetone/ircabot.git
sorted search
parent
8c68713f0c
commit
2be6bdae5c
32
main.cpp
32
main.cpp
|
@ -25,53 +25,61 @@ std::map<std::string, std::string> conf =
|
||||||
std::string search(std::string text)
|
std::string search(std::string text)
|
||||||
{
|
{
|
||||||
constexpr int maxSize = 10;
|
constexpr int maxSize = 10;
|
||||||
|
uint64_t success = 0;
|
||||||
|
uint64_t found = 0;
|
||||||
std::string values;
|
std::string values;
|
||||||
std::vector<std::string> matches;
|
std::vector<std::string> matches;
|
||||||
std::regex regex(".*" + text + ".*", std::regex_constants::extended | std::regex_constants::icase);
|
std::regex regex(".*" + text + ".*", std::regex_constants::extended | std::regex_constants::icase);
|
||||||
|
|
||||||
boost::filesystem::recursive_directory_iterator dir(conf["logpath"]), end;
|
boost::filesystem::recursive_directory_iterator dir(conf["logpath"]), end;
|
||||||
uint64_t success = 0;
|
|
||||||
for (; dir != end; ++dir)
|
for (; dir != end; ++dir)
|
||||||
{
|
{
|
||||||
if (! boost::filesystem::is_directory(dir->path()))
|
if (boost::filesystem::is_directory(dir->path())) continue;
|
||||||
{
|
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
std::ifstream log(dir->path().c_str());
|
std::ifstream log(dir->path().c_str());
|
||||||
|
|
||||||
while(getline(log, buffer))
|
while(getline(log, buffer))
|
||||||
{
|
{
|
||||||
if (std::regex_match(buffer, regex))
|
if (std::regex_match(buffer, regex))
|
||||||
{
|
{
|
||||||
++success;
|
|
||||||
std::string date = buffer.substr(0, buffer.find(' '));
|
std::string date = buffer.substr(0, buffer.find(' '));
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto entry: matches)
|
for (auto entry: matches)
|
||||||
{
|
{
|
||||||
if (entry.find(date) != std::string::npos) first = false;
|
if (entry.find(date) != std::string::npos)
|
||||||
|
{
|
||||||
|
++found;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
matches.push_back(date);
|
||||||
|
++success;
|
||||||
}
|
}
|
||||||
if (first) matches.push_back(date);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.close();
|
log.close();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (matches.size() > 0)
|
if (matches.size() > 0)
|
||||||
{
|
{
|
||||||
std::sort(matches.begin(), matches.end());
|
std::sort(matches.begin(), matches.end());
|
||||||
values += "(" + std::to_string(success) + ") ";
|
values += "(" + std::to_string(found) + ") ";
|
||||||
|
|
||||||
for (int i = matches.size()-1, count = 0; i >= 0 && count < maxSize ; --i, ++count)
|
for (int i = matches.size()-1, count = 0; i >= 0 && count < maxSize ; --i, ++count)
|
||||||
{ // Компоновка выходной строки
|
{ // Компоновка выходной строки
|
||||||
if (values.find('-') != std::string::npos) values += ", ";
|
if (values.find('-') != std::string::npos) values += ", ";
|
||||||
values += matches[i];
|
values += matches[i];
|
||||||
}
|
}
|
||||||
if (values != "") values += ".";
|
|
||||||
|
|
||||||
for (auto it = values.begin(), end = values.end(); it != end; ++it)
|
for (auto it = values.begin(), end = values.end(); it != end; ++it)
|
||||||
{ // Замена тире на слеш
|
{ // Замена тире на слеш
|
||||||
if (*it == '-') *it = '/';
|
if (*it == '-') *it = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (success > maxSize) values += "...";
|
||||||
|
else values += ".";
|
||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +135,7 @@ int write_log(std::string msg)
|
||||||
}
|
}
|
||||||
else return 2;
|
else return 2;
|
||||||
|
|
||||||
out << year << "-" << month << "-" << day << " " << msg;
|
out << year << "-" << month << "-" << day << " " << msg << std::endl;
|
||||||
out.close();
|
out.close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,8 @@ void TcpSyncClient::process_msg()
|
||||||
m_raw_nickname = msg.substr(1, msg.find('!') - 1);
|
m_raw_nickname = msg.substr(1, msg.find('!') - 1);
|
||||||
|
|
||||||
while (m_raw[0] == ' ') m_raw = m_raw.substr(1);
|
while (m_raw[0] == ' ') m_raw = m_raw.substr(1);
|
||||||
while (m_raw[m_raw.size() - 1] == '\n') m_raw.pop_back();
|
while (m_raw[m_raw.size() - 1] == '\n'||
|
||||||
|
m_raw[m_raw.size() - 1] == '\r') m_raw.pop_back();
|
||||||
|
|
||||||
if (m_raw.find("ACTION") == 0) {
|
if (m_raw.find("ACTION") == 0) {
|
||||||
m_raw = "-" + m_raw.substr(7);
|
m_raw = "-" + m_raw.substr(7);
|
||||||
|
|
Loading…
Reference in New Issue