master
const an teen 2021-05-20 13:34:45 +03:00
parent 69818ced89
commit cf4573c069
3 changed files with 14 additions and 25 deletions

View File

@ -26,13 +26,13 @@ int write_log(std::string msg)
std::ofstream out;
if (boost::filesystem::exists("/usr/share/kiwiirc/irc-log")) // unix, продакшен
if (boost::filesystem::exists("/var/www/html/doc/irc-log")) // unix, продакшен
{
if (! boost::filesystem::exists("/usr/share/kiwiirc/irc-log/" + year + "/" + month))
if (! boost::filesystem::exists("/var/www/html/doc/irc-log/" + year + "/" + month))
{
boost::filesystem::create_directories("/usr/share/kiwiirc/irc-log/" + year + "/" + month);
boost::filesystem::create_directories("/var/www/html/doc/irc-log/" + year + "/" + month);
}
out.open("/usr/share/kiwiirc/irc-log/" + year + "/" + month + "/" + day + ".txt", std::ios::app);
out.open("/var/www/html/doc/irc-log/" + year + "/" + month + "/" + day + ".txt", std::ios::app);
if (! out.is_open()) return 1;
}
else if (boost::filesystem::exists("D:\\irc-log")) // win, тесты
@ -103,10 +103,9 @@ int main(int argc, char * argv[])
if(tsc->to_read) { // Есть сообщения, адресованные боту
std::string msg = tsc->get_msg();
if(msg != ERROR_START_FAILED) {
tsc->write_to_channel(tsc->get_msg_nick() + ", лог чата: " +
"http://irc.acetone.i2p/irc-log || " +
"http://[324:9de3:fea4:f6ac::41]/irc-log || " +
"http://ilitafrzzgxymv6umx2ux7kbz3imyeko6cnqkvy4nisjjj4qpqkrptid.onion/irc-log");
tsc->write_to_channel(tsc->get_msg_nick() + ", лог чата: http://acetone.i2p/doc/irc-log/ #" +
" http://[324:9de3:fea4:f6ac::ace]/doc/irc-log/ #" +
" http://acetonemadzhxzi2e5tomavam6xpucdfwn2g35vrsz6izgaxv5bmuhad.onion/doc/irc-log/");
}
else break;
}

View File

@ -1,13 +1,9 @@
#include "tcpsyncclient.h"
template <typename T>
void TcpSyncClient::log(T message)
void TcpSyncClient::log(std::string message)
{
#ifdef WIN32
std::cout << "[TSC] " << message;
#else
std::cout << "[TSC] " << message << std::endl;
#endif
if (message[message.size() - 1] != '\n') std::cout << std::endl;
}
TcpSyncClient::TcpSyncClient(boost::asio::ip::tcp::endpoint ep, boost::asio::io_service& s,
@ -20,9 +16,9 @@ TcpSyncClient::TcpSyncClient(boost::asio::ip::tcp::endpoint ep, boost::asio::io_
m_mynick(n),
m_password(p)
{
log(ep.address().to_string());
log(ep.port());
log(m_channel);
log (ep.address().to_string());
log (std::to_string (ep.port()) );
log (m_channel);
}
bool TcpSyncClient::write(std::string msg)
@ -130,10 +126,6 @@ void TcpSyncClient::process_msg()
log("[MSG] " + msg);
if (msg.find("PING :") == 0) answer_to_ping(msg.substr(6));
/* if (msg.find("JOIN :" + m_channel) != std::string::npos && msg.find(m_mynick) == std::string::npos) {
write_to_channel(msg.substr(1, msg.find('!') - 1) + ", welcome to " + m_channel + "!");
} */
// Парсинг сообщений, адресованных боту. Сохраняет ник отправителя и текст.
if (msg.find("PRIVMSG " + m_channel + " :" + m_mynick) != std::string::npos)
{
@ -144,8 +136,7 @@ void TcpSyncClient::process_msg()
}
// Парсинг всех сообщений на канале. Сохраняет ник отправителя и текст.
else if (msg.find("PRIVMSG " + m_channel + " :") != std::string::npos &&
msg.find(m_mynick) == std::string::npos)
else if (msg.find("PRIVMSG " + m_channel + " :") != std::string::npos)
{
m_raw = msg.substr(msg.find(m_channel + " :") + 2 + m_channel.size() );
while (m_raw[0] == ' ') m_raw = m_raw.substr(1);

View File

@ -28,8 +28,7 @@ public:
bool to_raw;
private:
template <typename T>
void log(T);
void log(std::string);
bool connect_to_ep();
size_t read_complete(const error_code&, size_t);
void read_answer();