Upload files to "/"
This commit is contained in:
parent
d716e164e4
commit
aa28da18fe
4
cfg.h
4
cfg.h
@ -1,6 +1,6 @@
|
||||
//Settings
|
||||
#define NICK "historybotd"
|
||||
#define HOST "irc.rizon.net" //localhost"
|
||||
#define NICK "histbot"
|
||||
#define HOST "192.168.0.184" //localhost"
|
||||
#define PORT 6667
|
||||
#define DIR "./"
|
||||
|
||||
|
24
main.c
24
main.c
@ -1,6 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <time.h>
|
||||
#include "irc.h"
|
||||
#include "cfg.h"
|
||||
#include <time.h>
|
||||
|
||||
IRCC_client client;
|
||||
|
||||
void die(char *msg) {
|
||||
@ -18,17 +23,17 @@ char *GetFilename(void) {
|
||||
//Get filename + date
|
||||
struct tm tm = GetTime();
|
||||
|
||||
size_t filename_size = strlen(client.channel + 1) + (sizeof(tm.tm_year) * 3) + strlen(EXT) + 3;
|
||||
size_t filename_size = strlen(client.irc_channel + 1) + (sizeof(tm.tm_year) * 3) + strlen(EXT) + 3;
|
||||
char *filename = malloc(filename_size + 1);
|
||||
if (filename == NULL)
|
||||
die("malloc returned NULL");
|
||||
|
||||
snprintf(filename, filename_size, "%s-%d-%d-%d%s", client.channel + 1, tm.tm_year + 1900, tm.tm_mon, tm.tm_mday, EXT);
|
||||
snprintf(filename, filename_size, "%s_%d-%d-%d%s", client.irc_channel + 1, tm.tm_mday, tm.tm_mon, tm.tm_year, EXT);
|
||||
return filename;
|
||||
}
|
||||
|
||||
void WriteToFile(void) {
|
||||
if (client.msg[1] == '.' || client.channel[0] != '#')
|
||||
if (client.irc_msg[1] == '.' || client.irc_channel[0] != '#')
|
||||
return;
|
||||
|
||||
char *filename = GetFilename();
|
||||
@ -36,21 +41,22 @@ void WriteToFile(void) {
|
||||
free(filename);
|
||||
|
||||
if (fp == NULL) {
|
||||
printf("Cant open file %s\n", client.channel);
|
||||
printf("Cant open file %s\n", client.irc_channel);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(fp, FORMAT, client.nick, client.msg);
|
||||
fprintf(fp, FORMAT, client.irc_nick, client.irc_msg);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void recvinfo(void) {
|
||||
while (1) {
|
||||
unsigned int irc_status = IRCC_recv(&client);
|
||||
int irc_status = IRCC_recv(&client);
|
||||
if (irc_status == IRCC_DISCONNECTED)
|
||||
die("Disconnected");
|
||||
|
||||
else if (client.nick != NULL && client.channel != NULL && client.msg != NULL && irc_status == IRCC_PRIVMSG)
|
||||
irc_status = IRCC_parse(&client);
|
||||
if (client.irc_nick != NULL && client.irc_channel != NULL && client.irc_msg != NULL && irc_status == IRCC_PRIVMSG)
|
||||
WriteToFile();
|
||||
}
|
||||
}
|
||||
@ -77,7 +83,7 @@ int main(void) {
|
||||
if (send_after_join[i] == NULL)
|
||||
break;
|
||||
|
||||
send(client.socket, send_after_join[i], strlen(send_after_join[i]), 0);
|
||||
send(client.irc_socket, send_after_join[i], strlen(send_after_join[i]), 0);
|
||||
}
|
||||
|
||||
recvinfo();
|
||||
|
Loading…
Reference in New Issue
Block a user