rewrite parser

This commit is contained in:
Your Name 2023-12-13 16:41:27 +03:00
parent 79a504e10b
commit d716e164e4
4 changed files with 14 additions and 24 deletions

View File

@ -1,4 +1,4 @@
CFLAGS?= -s -Os -flto -pedantic CFLAGS?= -s -Os -flto -pedantic -Wall
CC?=cc CC?=cc
all: all:
$(CC) *.c $(CFLAGS) -obot $(CC) *.c $(CFLAGS) -obot

View File

@ -1,2 +0,0 @@
# history

13
cfg.h
View File

@ -1,10 +1,17 @@
//Settings //Settings
#define NICK "historybot" #define NICK "historybotd"
#define HOST "localhost" #define HOST "irc.rizon.net" //localhost"
#define PORT 6667 #define PORT 6667
#define DIR "./" #define DIR "./"
char *channels[] = {"#channel", NULL}; struct CHANNEL {
char *channel;
char *key;
};
struct CHANNEL channels[] = {
{"#hp", NULL}
};
//Put \r\n after string end //Put \r\n after string end
//Exp: {..., "PRIVMSG NickServ IDENTIFY mypassword\r\n", ..., NULL}; //Exp: {..., "PRIVMSG NickServ IDENTIFY mypassword\r\n", ..., NULL};

21
main.c
View File

@ -40,7 +40,7 @@ void WriteToFile(void) {
return; return;
} }
fprintf(fp, FORMAT, client.nick, client.msg + 1); fprintf(fp, FORMAT, client.nick, client.msg);
fclose(fp); fclose(fp);
} }
@ -52,9 +52,6 @@ void recvinfo(void) {
else if (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG) else if (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG)
WriteToFile(); WriteToFile();
else if (irc_status == IRCC_CONNECTED)
return;
} }
} }
@ -72,21 +69,9 @@ int main(void) {
IRCC_register(&client, NICK); IRCC_register(&client, NICK);
//Recv motd and join in channel //Recv motd and join in channel
recvinfo();
sleep(5); sleep(5);
for (size_t i = 0; i < sizeof(channels) / sizeof(char *); i++) { for (size_t i = 0; i < sizeof(channels) / sizeof(struct CHANNEL); i++)
if (channels[i] == NULL) IRCC_join(&client, channels[i].channel, channels[i].key);
break;
size_t join_size = strlen("JOIN \r\n") + strlen(channels[i]) + 1;
char *tmp = malloc(join_size);
if (tmp == NULL)
die("malloc retured NULL");
snprintf(tmp, join_size, "JOIN %s\r\n", channels[i]);
send(client.socket, tmp, join_size, 0);
free(tmp);
}
for (size_t i = 0; i < sizeof(send_after_join) / sizeof(char *); i++) { for (size_t i = 0; i < sizeof(send_after_join) / sizeof(char *); i++) {
if (send_after_join[i] == NULL) if (send_after_join[i] == NULL)