52 lines
1.0 KiB
C
52 lines
1.0 KiB
C
|
#include "irc.h"
|
||
|
#define IF_NULL(client) (client.msg != NULL || client.nick != NULL || client.channel != NULL)
|
||
|
|
||
|
IRCC_client client;
|
||
|
|
||
|
void die(char *msg){
|
||
|
puts(msg);
|
||
|
IRCC_close(&client);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
int main(void){
|
||
|
IRCC_init(&client, 250);
|
||
|
int status = IRCC_connect(&client, "irc.libera.chat", 6667);
|
||
|
if (status == IRCC_ERROR)
|
||
|
die("Conn refused");
|
||
|
|
||
|
IRCC_register(&client, "bot");
|
||
|
sleep(5);
|
||
|
send(client.socket, "JOIN #channel\r\n", strlen("JOIN #channel\r\n"), 0);
|
||
|
|
||
|
while (1){
|
||
|
unsigned int irc_status = IRCC_recv(&client);
|
||
|
if (irc_status == IRCC_DISCONNECTED)
|
||
|
die("Disconnected");
|
||
|
|
||
|
if (IF_NULL(client)) {
|
||
|
client.msg++;
|
||
|
switch (irc_status) {
|
||
|
case IRCC_PRIVMSG:
|
||
|
printf("%s %s %s\n", client.channel, client.nick, client.msg);
|
||
|
break;
|
||
|
|
||
|
case IRCC_NICK:
|
||
|
printf("%s is know as %s", client.nick, client.msg);
|
||
|
break;
|
||
|
|
||
|
case IRCC_JOIN:
|
||
|
printf("< %s\n", client.nick);
|
||
|
break;
|
||
|
|
||
|
case IRCC_PART:
|
||
|
printf("> %s\n", client.nick);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|