/* * op.c * (C) Peter Salanki 2002 * This program is copyright, and covered by the Gnu Public License. * The Natasha bot. * sorcer@linux.se */ #include #include #include #include #include #include #include #include "../../settings.h" #include "../../globals.h" #include "../../bottypes.h" #include "settings.h" #define BASHCOLORS "\003" #define BASHBOLD "\002" #define BASHUNDERLINE "\0031" #define NAME "bash" #define VERSION 1.00 int ticket(struct arm *arm); char *getwebdata (char address[256]); char *secondstostr(int seconds, char *string); MODULE_INIT _module_init(MODULE m); MODULE_DESTROY _module_destroy(MODULE m); MODULE_INIT _module_init(MODULE m) { strncpy(m->name, NAME, 20); strncpy(m->compiledate, __DATE__ " " __TIME__, 30); m->version = VERSION; } MODULE_DESTROY _module_destroy(MODULE m) { } char *getwebdata (char address[256]) { FILE *pFile = NULL; long lSize; char *buffer = NULL; char *retbuf = NULL; char tmp[512]; printf("Getdata: %s\n", address); snprintf(tmp, 512, "wget --timeout=6 --tries=6 --output-document=webtmp \"%s\"", address); system(tmp); pFile = fopen ("webtmp" , "r"); if (pFile==NULL) return NULL; fseek (pFile , 0 , SEEK_END); lSize = ftell (pFile); rewind (pFile); buffer = (char*) malloc (lSize); retbuf = (char*) malloc (lSize*2); if (buffer == NULL) return NULL; memcpy(buffer, "", lSize); memcpy(retbuf, "", lSize*2); fgets(buffer, lSize, pFile); fclose (pFile); STR_replace_c (buffer, "%B", BASHBOLD, retbuf); STR_replace_c (retbuf, "%C", BASHCOLORS, retbuf); STR_replace_c (retbuf, "%U", BASHUNDERLINE, retbuf); free(buffer); return retbuf; } char *secondstostr(int seconds, char *string) { char tmp[60]; int days, hours, minutes; days = hours = minutes = 0; if(seconds > 86400) { /* We have days */ days = seconds/86400; seconds = seconds-(days*86400); } if(seconds > 3600) { /* We have hours */ hours = seconds/3600; seconds = seconds-(hours*3600); } if(seconds > 60) { /* We have minutes */ minutes = seconds/60; seconds = seconds-(minutes*60); } if(days != 0) snprintf(string, 512, "%i days", days); if(hours != 0) { snprintf(tmp, 60, " %i hours", hours); strcat(string, tmp); } if(minutes != 0) { snprintf(tmp, 60, " %i minutes", minutes); strcat(string, tmp); } if(seconds != 0) { snprintf(tmp, 60, " %i seconds", seconds); strcat(string, tmp); } printf("Str: %s\n", string); return &(string[0]); } int ticket(struct arm *arm) { printf("here\n"); if(irc_strcmp(BASHCHANNEL, arm->parsevars->args[0]) == 0) { printf("here2\n"); privmsg(arm->parsevars->c->name, getwebdata("http://bash.dayhost.net/?pop=1&page=botinfo&action=tickets")); } return 1; } int sz_time(struct arm *arm) { time_t diff; char local[512] = ""; if(time(NULL) >= SZTIME) { privmsg(arm->parsevars->c->name, "The party has already begun."); return 1; } diff = difftime(SZTIME, time(NULL)); privmsgf(arm->parsevars->args[0], "Remedy SceneZone: %c%s%c and counting.", BOLD, secondstostr(diff, local), BOLD); return 1; } int gz_time(struct arm *arm) { time_t diff; char local[512] = ""; if(time(NULL) >= GZTIME) { privmsg(arm->parsevars->c->name, "The party has already begun."); return 1; } diff = difftime(GZTIME, time(NULL)); privmsgf(arm->parsevars->args[0], "Remedy GameZone: %c%s%c and counting.", BOLD, secondstostr(diff, local), BOLD); return 1; }