Improve command handler to support leading whitespace
This commit is contained in:
parent
e38e0d7575
commit
0a0a7bbaa9
18
src/irc.c
18
src/irc.c
@ -122,7 +122,8 @@ event_connect(irc_session_t * lsession,
|
|||||||
#ifdef INITIAL_ASSIGNMENT_MESSAGE
|
#ifdef INITIAL_ASSIGNMENT_MESSAGE
|
||||||
if(is_no_assignment(creds.channel))
|
if(is_no_assignment(creds.channel))
|
||||||
{
|
{
|
||||||
ircmsg(creds.channel, IRC_RED "No assignment for this channel. Finding a new..." IRC_STOP);
|
ircmsg(creds.channel,
|
||||||
|
IRC_RED "No assignment for this channel. Finding a new..." IRC_STOP);
|
||||||
random_assign(creds.channel);
|
random_assign(creds.channel);
|
||||||
}
|
}
|
||||||
ircmsg(creds.channel, remind(creds.channel));
|
ircmsg(creds.channel, remind(creds.channel));
|
||||||
@ -187,34 +188,34 @@ parse_command(char const * cmd)
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
char * msgswp = NULL;
|
char * msgswp = NULL;
|
||||||
/* size_t len = strlen(cmd); */
|
/* size_t len = strlen(cmd); */
|
||||||
printf("Handling '%s'\n", cmd);
|
|
||||||
if (!(i = has_arg(cmd)))
|
if (!(i = has_arg(cmd)))
|
||||||
{
|
{
|
||||||
|
printf("NARG Handling '%s'\n", cmd);
|
||||||
/* NO ARGUMENTS */
|
/* NO ARGUMENTS */
|
||||||
if (strcmp(cmd, "remind") == 0)
|
if (strncmp(cmd, "remind", 6) == 0)
|
||||||
{
|
{
|
||||||
msgswp = remind(current_username);
|
msgswp = remind(current_username);
|
||||||
ircmsg(creds.channel, "%s: %s", current_username, msgswp);
|
ircmsg(creds.channel, "%s: %s", current_username, msgswp);
|
||||||
}
|
}
|
||||||
else if (strcmp(cmd, "help") == 0)
|
else if (strncmp(cmd, "help", 4) == 0)
|
||||||
{ ircmsg(creds.channel, help_msg); }
|
{ ircmsg(creds.channel, help_msg); }
|
||||||
else if (strcmp(cmd, "magic") == 0)
|
else if (strncmp(cmd, "magic", 5) == 0)
|
||||||
{ ircmsg(creds.channel, "%s: " IRC_YELLOW "%d" IRC_STOP, current_username, (rand() % 100) + 1); }
|
{ ircmsg(creds.channel, "%s: " IRC_YELLOW "%d" IRC_STOP, current_username, (rand() % 100) + 1); }
|
||||||
#ifndef NO_VULN_COMMANDS
|
#ifndef NO_VULN_COMMANDS
|
||||||
else if (strcmp(cmd, "dump") == 0)
|
else if (strncmp(cmd, "dump", 4) == 0)
|
||||||
{
|
{
|
||||||
ircmsg(creds.channel, "%s: All projects:", current_username);
|
ircmsg(creds.channel, "%s: All projects:", current_username);
|
||||||
msgswp = dump();
|
msgswp = dump();
|
||||||
ircmsg(creds.channel, msgswp);
|
ircmsg(creds.channel, msgswp);
|
||||||
}
|
}
|
||||||
#endif /* !NO_VULN_COMMANDS */
|
#endif /* !NO_VULN_COMMANDS */
|
||||||
else if (strcmp(cmd, "reroll") == 0)
|
else if (strncmp(cmd, "reroll", 6) == 0)
|
||||||
{
|
{
|
||||||
purge_assignments(current_username);
|
purge_assignments(current_username);
|
||||||
random_assign(current_username);
|
random_assign(current_username);
|
||||||
ircmsg(creds.channel, "%s: %s", current_username, remind(current_username));
|
ircmsg(creds.channel, "%s: %s", current_username, remind(current_username));
|
||||||
}
|
}
|
||||||
else if (strcmp(cmd, "stop") == 0)
|
else if (strncmp(cmd, "stop", 4) == 0)
|
||||||
{
|
{
|
||||||
if (vote_count)
|
if (vote_count)
|
||||||
{
|
{
|
||||||
@ -225,6 +226,7 @@ parse_command(char const * cmd)
|
|||||||
}
|
}
|
||||||
else /* HAS ARGUMENTS */
|
else /* HAS ARGUMENTS */
|
||||||
{
|
{
|
||||||
|
printf("ARG Handling '%s'\n", cmd);
|
||||||
static int yes, no;
|
static int yes, no;
|
||||||
char const * const arg = cmd + i;
|
char const * const arg = cmd + i;
|
||||||
/* fprintf(stderr, "argoff: %p; i: %ld; arg: %sEOA\n", cmd + i + 1, i, arg); */
|
/* fprintf(stderr, "argoff: %p; i: %ld; arg: %sEOA\n", cmd + i + 1, i, arg); */
|
||||||
|
Reference in New Issue
Block a user