Загрузить файлы в «»

This commit is contained in:
8nlight 2023-08-17 07:46:35 +03:00
parent 5aa03515c3
commit 0fe7c77157
2 changed files with 17 additions and 17 deletions

15
cfg.h
View File

@ -1,13 +1,16 @@
#define NICK "history"
#define HOST "irc.server.net"
//Settings
#define NICK "historybot"
#define HOST "localhost"
#define PORT 6667
#define DIR "tmp/"
#define DIR "./"
char *channels[] = {"#channel"};
//Output
#define FORMAT_TXT "<%s> %s\n"
#define FORMAT_TXT "<%s> %s\n"
#define FORMAT_HTML "[%s] %s<br>\n"
#define FORMAT FORMAT_TXT
#define FORMAT_AWK "%s %s\n"
#define FORMAT FORMAT_AWK
#define EXT ".txt"
//File ext
#define EXT ".awk"

19
main.c
View File

@ -44,14 +44,11 @@ void WriteToFile(void) {
fclose(fp);
}
void recvinfo(int ignore) {
void recvinfo(void) {
while (1) {
unsigned int irc_status = IRCC_recv(&client);
if (irc_status == IRCC_DISCONNECTED) {
if (!ignore)
die("Disconnected");
return;
}
if (irc_status == IRCC_DISCONNECTED)
die("Disconnected");
else if (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG)
WriteToFile();
@ -66,22 +63,22 @@ int main(void) {
die("Cant chdir");
//512 - size of raw buffer (max irc)
IRCC_init(&client, 512);
IRCC_init(&client, IRCC_MSG_MAX);
int status = IRCC_connect(&client, HOST, PORT);
if (status == IRCC_ERROR)
die("Conn refused");
//Socket timeout
struct timeval tv = {5, 5};
struct timeval tv = {IRCC_PING_TIMEOUT, IRCC_PING_TIMEOUT};
if (setsockopt(client.socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
die("setsockopt");
//Register
recvinfo(1);
recvinfo();
IRCC_register(&client, NICK);
//Recv motd and join in channel
recvinfo(0);
recvinfo();
sleep(5);
for (size_t i = 0; i < sizeof(channels) / sizeof(char *); i++) {
if (channels[i] == NULL)
@ -97,6 +94,6 @@ int main(void) {
free(tmp);
}
recvinfo(0);
recvinfo();
}