/* * puffnotes.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 #include "../../settings.h" #include "../../globals.h" #include "../../bottypes.h" #define NAME "puffNotes" #define VERSION 1.00 void puffnotes_addnote_msg(struct arm *arm, char *a); void puffnotes_addnote(int uid, time_t time, char *message); void puffnotes_list_msg(struct arm *arm, char *a); void remind(void); 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) { } /* Add notes */ void puffnotes_addnote_msg(struct arm *arm, char *a) { char date[512] = ""; char note[512] = ""; int i = 0; int j = 0; time_t unixtime; while (a[i] != ' ' && a[i] != '\0') { date[j] = a[i]; ++i; ++j; } date[j] = ' '; ++i; ++j; while (a[i] != ' ' && a[i] != '\0') { date[j] = a[i]; ++i; ++j; } ++i; j = 0; while (a[i] != '\0') { note[j] = a[i]; ++i; ++j; } if((unixtime = UnixtimeFromDate(date)) < 0) { say(arm->parsevars->sender, "Your date is incorrect. Date should be in form: yy-mm-dd hh:mm (GMT+1)", arm, arm->parsevars->u); return; } /* Add note */ puffnotes_addnote(arm->parsevars->u->userid, unixtime, note); say(arm->parsevars->sender, "Note added.", arm, arm->parsevars->u); } void puffnotes_addnote(int uid, time_t time, char *message) { char query[MAX_QUERY], *esmessage; esmessage = escapequery(message); /* Escape */ snprintf(query, MAX_QUERY, "INSERT INTO `puffnotes` (`uid`, `time`, `message`) VALUES ('%i', '%i', '%s')", uid, (int) time, esmessage); dbquery(query); EndDbQuery(); free(esmessage); } /* List notes */ void puffnotes_list_msg(struct arm *arm, char *a) { char query[MAX_QUERY]; struct tm *tmstruct; time_t unixtime; char tmstr[100]; snprintf(query, MAX_QUERY, "SELECT `time`,`message` FROM `puffnotes` WHERE `uid` = %i", arm->parsevars->u->userid); dbquery(query); while((row = mysql_fetch_row(res))) { /* Human readable time */ unixtime = (time_t) atoi(row[0]); tmstruct = localtime(&unixtime); strftime(tmstr, 100, "%F %H:%M", tmstruct); /* Put to client */ sayf(arm->parsevars->sender, arm, arm->parsevars->u, "%c%s%c %s", BOLD, tmstr, BOLD, row[1]); } EndDbQuery(); } /* Loop */ void remind(void) { char query[MAX_QUERY]; struct activeuser *u; snprintf(query, MAX_QUERY, "SELECT `uid`, `message` FROM `puffnotes` WHERE `time` < %i", (int) time(NULL)); dbquery(query); while((row = mysql_fetch_row(res))) for(u = firstauser; u != NULL; u = u->next) if(u->userid == atoi(row[0])) privmsgf(u->nick, "%cReminder:%c %s", BOLD, BOLD, row[1]); EndDbQuery(); /* Cleanup old */ snprintf(query, MAX_QUERY, "DELETE FROM `puffnotes` WHERE `time` < %i", (int) time(NULL)); dbquery(query); EndDbQuery(); }