diff --git a/src/api.c b/src/api.c index 02e2462..d76efb8 100644 --- a/src/api.c +++ b/src/api.c @@ -49,7 +49,7 @@ api_rope(void) DECL char * remind(char * who) { - char * r; + char * r = NULL; char * title; char * desc = NULL; /* char * repo; */ diff --git a/src/irc.c b/src/irc.c index 73aab74..b2f18cc 100644 --- a/src/irc.c +++ b/src/irc.c @@ -42,10 +42,15 @@ IRC_GREEN "!reroll " IRC_STOP " : Rerolls assignment\n" /* IRC_GREEN "!repo " IRC_STOP " : Sets project repository link\n" */ /* IRC_GREEN "!raw " IRC_STOP " : Execute raw SQL\n" */ /* IRC_GREEN "!dump " IRC_STOP " : List all possible projects\n" */ -IRC_GREEN "!request " IRC_STOP " : Request personal project\n" -IRC_GREEN "!remind " IRC_STOP " : Prints your assignment\n"; +/* IRC_GREEN "!request " IRC_STOP " : Request personal project\n" */ +IRC_GREEN "!remind " IRC_STOP " : Prints your assignment\n" +IRC_GREEN "!poll " IRC_STOP " : Start the democratic process (N message ...])\n" +IRC_GREEN "!vote " IRC_STOP " : Casts a vote (y/n [message ...])\n" +IRC_GREEN "!stop " IRC_STOP " : Stop the current polling\n" +IRC_BLUE "!magic " IRC_STOP " : A random value at or below 100 or (N)\n"; DECL void parse_command(char const * cmd); +DECL size_t parse_secondary_username(char const * msg); DECL char * get_username(const char * origin) @@ -136,17 +141,19 @@ event_channel(irc_session_t * lsession, (void) lsession; (void) event; (void) origin; - /* (void) channel; */ (void) message; (void) count; - /* Logs the message */ - printf("%s\n", message); /* parses the command */ if (*message == PREFIX_COMMAND_CHAR) { current_username = get_username(origin); } if (!current_username || message[1] == '\0') { return; } + /* Logs the message */ + printf("<%s> %s\n", current_username, message); + /* Detects any re specified names */ + /* message += parse_secondary_username(message); */ + /* Parse any commands */ parse_command(message+1); free(current_username); current_username = NULL; @@ -178,10 +185,8 @@ has_arg(char const * cmd) DECL void parse_command(char const * cmd) { - size_t i = 0; static int vote_count; - static int yes, no; - static int vote_on = 0; + size_t i = 0; char * msgswp = NULL; /* size_t len = strlen(cmd); */ printf("Handling '%s'\n", cmd); @@ -213,12 +218,16 @@ parse_command(char const * cmd) } else if (strcmp(cmd, "stop") == 0) { - vote_on = vote_count = 0; - ircmsg(creds.channel, "POLL STOP"); + if (vote_count) + { + ircmsg(creds.channel, "poll: stop"); + vote_count = 0; + } } } else /* HAS ARGUMENTS */ { + static int yes, no; char const * const arg = cmd + i; /* fprintf(stderr, "argoff: %p; i: %ld; arg: %sEOA\n", cmd + i + 1, i, arg); */ #ifndef NO_VULN_COMMANDS @@ -244,35 +253,44 @@ parse_command(char const * cmd) else if (strncmp(cmd, "poll", 4) == 0) { yes = no = 0; - vote_on = 1; - vote_count = atoi(arg); + vote_count = atoi(arg) + 1; if (!vote_count) { ircmsg(creds.channel, "!poll NUMBER_OF_VOTES What your voting on ..."); } else - { ircmsg(creds.channel, "poll: start"); } + { ircmsg(creds.channel, "poll start"); } } else if (strncmp(cmd, "vote", 4) == 0) { - fprintf(stderr, "y%d n%d vote_count %d\n", yes, no, vote_count); - if (vote_on && vote_count) + /* fprintf(stderr, "y%d n%d vote_count %d\n", yes, no, vote_count); */ + if (vote_count) { switch (*arg) { - case 'Y': case 'y': ERRMSG("YYY"); ++yes; break; - case 'N': case 'n': ERRMSG("NNN"); ++no; break; - default: ircmsg(creds.channel, "Unknown vote meaning: '%c', use y/n", *arg); goto stop; + case 'Y': case 'y': ++yes; break; + case 'N': case 'n': ++no; break; + default: ircmsg(creds.channel, "Unknown: '%c', use y/n", *arg); goto stop; } if (--vote_count) - { ircmsg(creds.channel, "Votes remaining: %d", vote_count); } + { ircmsg(creds.channel, "Votes remaining: %d", vote_count - 1); } else - { - ircmsg(creds.channel, "poll results: %s", - MAX(yes,no) ? "PASSED" : "REJECTED"); - vote_on = 0; - } + { ircmsg(creds.channel, "poll results: %s", MAX(yes,no) ? "PASSED" : "REJECTED"); } } } } stop: free(msgswp); } + +/* mutates current_username and returns positional offset to the first character that isn't related to the uname */ +DECL size_t +parse_secondary_username(char const * msg) +{ + int ret = 0; +#define SECONDARY_NAMES_BOT "cnile" + if (strcmp(current_username,SECONDARY_NAMES_BOT) == 0) + if (*msg == '<') + { while (msg[++ret] != '\0' || + msg[ret] != '>'); } + fprintf(stderr, "msg[ret] = %c", msg[ret]); + return ret; +}