Minor changes
This commit is contained in:
parent
f0026bd5e3
commit
5b7f599a76
@ -49,7 +49,7 @@ api_rope(void)
|
|||||||
DECL char *
|
DECL char *
|
||||||
remind(char * who)
|
remind(char * who)
|
||||||
{
|
{
|
||||||
char * r;
|
char * r = NULL;
|
||||||
char * title;
|
char * title;
|
||||||
char * desc = NULL;
|
char * desc = NULL;
|
||||||
/* char * repo; */
|
/* char * repo; */
|
||||||
|
66
src/irc.c
66
src/irc.c
@ -42,10 +42,15 @@ IRC_GREEN "!reroll " IRC_STOP " : Rerolls assignment\n"
|
|||||||
/* IRC_GREEN "!repo <link>" IRC_STOP " : Sets project repository link\n" */
|
/* IRC_GREEN "!repo <link>" IRC_STOP " : Sets project repository link\n" */
|
||||||
/* IRC_GREEN "!raw <sql> " IRC_STOP " : Execute raw SQL\n" */
|
/* IRC_GREEN "!raw <sql> " IRC_STOP " : Execute raw SQL\n" */
|
||||||
/* IRC_GREEN "!dump " IRC_STOP " : List all possible projects\n" */
|
/* IRC_GREEN "!dump " IRC_STOP " : List all possible projects\n" */
|
||||||
IRC_GREEN "!request " IRC_STOP " : Request personal project\n"
|
/* IRC_GREEN "!request " IRC_STOP " : Request personal project\n" */
|
||||||
IRC_GREEN "!remind " IRC_STOP " : Prints your assignment\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 void parse_command(char const * cmd);
|
||||||
|
DECL size_t parse_secondary_username(char const * msg);
|
||||||
|
|
||||||
DECL char *
|
DECL char *
|
||||||
get_username(const char * origin)
|
get_username(const char * origin)
|
||||||
@ -136,17 +141,19 @@ event_channel(irc_session_t * lsession,
|
|||||||
(void) lsession;
|
(void) lsession;
|
||||||
(void) event;
|
(void) event;
|
||||||
(void) origin;
|
(void) origin;
|
||||||
/* (void) channel; */
|
|
||||||
(void) message;
|
(void) message;
|
||||||
(void) count;
|
(void) count;
|
||||||
/* Logs the message */
|
|
||||||
printf("%s\n", message);
|
|
||||||
/* parses the command */
|
/* parses the command */
|
||||||
if (*message == PREFIX_COMMAND_CHAR)
|
if (*message == PREFIX_COMMAND_CHAR)
|
||||||
{ current_username = get_username(origin); }
|
{ current_username = get_username(origin); }
|
||||||
if (!current_username ||
|
if (!current_username ||
|
||||||
message[1] == '\0')
|
message[1] == '\0')
|
||||||
{ return; }
|
{ 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);
|
parse_command(message+1);
|
||||||
free(current_username);
|
free(current_username);
|
||||||
current_username = NULL;
|
current_username = NULL;
|
||||||
@ -178,10 +185,8 @@ has_arg(char const * cmd)
|
|||||||
DECL void
|
DECL void
|
||||||
parse_command(char const * cmd)
|
parse_command(char const * cmd)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
|
||||||
static int vote_count;
|
static int vote_count;
|
||||||
static int yes, no;
|
size_t i = 0;
|
||||||
static int vote_on = 0;
|
|
||||||
char * msgswp = NULL;
|
char * msgswp = NULL;
|
||||||
/* size_t len = strlen(cmd); */
|
/* size_t len = strlen(cmd); */
|
||||||
printf("Handling '%s'\n", cmd);
|
printf("Handling '%s'\n", cmd);
|
||||||
@ -213,12 +218,16 @@ parse_command(char const * cmd)
|
|||||||
}
|
}
|
||||||
else if (strcmp(cmd, "stop") == 0)
|
else if (strcmp(cmd, "stop") == 0)
|
||||||
{
|
{
|
||||||
vote_on = vote_count = 0;
|
if (vote_count)
|
||||||
ircmsg(creds.channel, "POLL STOP");
|
{
|
||||||
|
ircmsg(creds.channel, "poll: stop");
|
||||||
|
vote_count = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* HAS ARGUMENTS */
|
else /* HAS ARGUMENTS */
|
||||||
{
|
{
|
||||||
|
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); */
|
||||||
#ifndef NO_VULN_COMMANDS
|
#ifndef NO_VULN_COMMANDS
|
||||||
@ -244,35 +253,44 @@ parse_command(char const * cmd)
|
|||||||
else if (strncmp(cmd, "poll", 4) == 0)
|
else if (strncmp(cmd, "poll", 4) == 0)
|
||||||
{
|
{
|
||||||
yes = no = 0;
|
yes = no = 0;
|
||||||
vote_on = 1;
|
vote_count = atoi(arg) + 1;
|
||||||
vote_count = atoi(arg);
|
|
||||||
if (!vote_count)
|
if (!vote_count)
|
||||||
{ ircmsg(creds.channel, "!poll NUMBER_OF_VOTES What your voting on ..."); }
|
{ ircmsg(creds.channel, "!poll NUMBER_OF_VOTES What your voting on ..."); }
|
||||||
else
|
else
|
||||||
{ ircmsg(creds.channel, "poll: start"); }
|
{ ircmsg(creds.channel, "poll start"); }
|
||||||
}
|
}
|
||||||
else if (strncmp(cmd, "vote", 4) == 0)
|
else if (strncmp(cmd, "vote", 4) == 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "y%d n%d vote_count %d\n", yes, no, vote_count);
|
/* fprintf(stderr, "y%d n%d vote_count %d\n", yes, no, vote_count); */
|
||||||
if (vote_on && vote_count)
|
if (vote_count)
|
||||||
{
|
{
|
||||||
switch (*arg)
|
switch (*arg)
|
||||||
{
|
{
|
||||||
case 'Y': case 'y': ERRMSG("YYY"); ++yes; break;
|
case 'Y': case 'y': ++yes; break;
|
||||||
case 'N': case 'n': ERRMSG("NNN"); ++no; break;
|
case 'N': case 'n': ++no; break;
|
||||||
default: ircmsg(creds.channel, "Unknown vote meaning: '%c', use y/n", *arg); goto stop;
|
default: ircmsg(creds.channel, "Unknown: '%c', use y/n", *arg); goto stop;
|
||||||
}
|
}
|
||||||
if (--vote_count)
|
if (--vote_count)
|
||||||
{ ircmsg(creds.channel, "Votes remaining: %d", vote_count); }
|
{ ircmsg(creds.channel, "Votes remaining: %d", vote_count - 1); }
|
||||||
else
|
else
|
||||||
{
|
{ ircmsg(creds.channel, "poll results: %s", MAX(yes,no) ? "PASSED" : "REJECTED"); }
|
||||||
ircmsg(creds.channel, "poll results: %s",
|
|
||||||
MAX(yes,no) ? "PASSED" : "REJECTED");
|
|
||||||
vote_on = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stop:
|
stop:
|
||||||
free(msgswp);
|
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;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user