Загрузить файлы в «C»
This commit is contained in:
parent
a1c28f22e0
commit
a25dbc52fd
4 changed files with 246 additions and 0 deletions
51
C/main.c
Normal file
51
C/main.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue