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
all:
$(CC) *.c $(CFLAGS) -obot

View File

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

13
cfg.h
View File

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

21
main.c
View File

@ -40,7 +40,7 @@ void WriteToFile(void) {
return;
}
fprintf(fp, FORMAT, client.nick, client.msg + 1);
fprintf(fp, FORMAT, client.nick, client.msg);
fclose(fp);
}
@ -52,9 +52,6 @@ void recvinfo(void) {
else if (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG)
WriteToFile();
else if (irc_status == IRCC_CONNECTED)
return;
}
}
@ -72,21 +69,9 @@ int main(void) {
IRCC_register(&client, NICK);
//Recv motd and join in channel
recvinfo();
sleep(5);
for (size_t i = 0; i < sizeof(channels) / sizeof(char *); i++) {
if (channels[i] == NULL)
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(channels) / sizeof(struct CHANNEL); i++)
IRCC_join(&client, channels[i].channel, channels[i].key);
for (size_t i = 0; i < sizeof(send_after_join) / sizeof(char *); i++) {
if (send_after_join[i] == NULL)