Added new options for voting
This commit is contained in:
parent
a627bcaa6f
commit
9dc569a55c
@ -12,7 +12,7 @@ VERSION 2
|
||||
|
||||
Moved NVULN to config.h
|
||||
Added option -identify
|
||||
Added commands !magic, !say
|
||||
Added commands !magic, !say, !poll N, !vote y|n|u
|
||||
Added ENABLE_SSL=1 to enable SSL non-functional support
|
||||
Added libircclient submodule
|
||||
Fixed some error return values being too high
|
||||
|
58
src/irc.c
58
src/irc.c
@ -4,6 +4,8 @@
|
||||
|
||||
#define IRCMSG(msg) irc_cmd_msg(session, creds.channel, msg)
|
||||
|
||||
#define MAX(a,b) (a) > (b)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * username;
|
||||
@ -83,7 +85,7 @@ ircmsg(char const * reciever, char const * fmt,
|
||||
do
|
||||
{
|
||||
swp = irc_color_convert_to_mirc(data);
|
||||
irc_cmd_msg(session, reciever, swp);
|
||||
irc_cmd_msg(session, reciever, swp);
|
||||
free(swp);
|
||||
} while((data = strtok(NULL, delim), data));
|
||||
|
||||
@ -116,7 +118,7 @@ event_connect(irc_session_t * lsession,
|
||||
if(is_no_assignment(creds.channel))
|
||||
{
|
||||
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));
|
||||
#endif /* INITIAL_ASSIGNMENT_MESSAGE */
|
||||
@ -177,7 +179,10 @@ DECL void
|
||||
parse_command(char const * cmd)
|
||||
{
|
||||
size_t i = 0;
|
||||
char* msgswp = NULL;
|
||||
static int vote_count;
|
||||
static int yes, no, undecided;
|
||||
static int vote_on = 0;
|
||||
char * msgswp = NULL;
|
||||
/* size_t len = strlen(cmd); */
|
||||
printf("Handling '%s'\n", cmd);
|
||||
if (!(i = has_arg(cmd)))
|
||||
@ -206,20 +211,26 @@ parse_command(char const * cmd)
|
||||
random_assign(current_username);
|
||||
ircmsg(creds.channel, "%s: %s", current_username, remind(current_username));
|
||||
}
|
||||
else if (strcmp(cmd, "stop") == 0)
|
||||
{
|
||||
vote_on = vote_count = 0;
|
||||
ircmsg(creds.channel, "POLL STOP");
|
||||
}
|
||||
}
|
||||
else /* HAS ARGUMENTS */
|
||||
{
|
||||
char const * const arg = cmd + i;
|
||||
printf("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
|
||||
if (strncmp(cmd, "raw", 3) == 0)
|
||||
{
|
||||
printf("RAW\n");
|
||||
/* ircmsg(creds.channel, "%s: Executing SQL `%s'.", current_username, arg); */
|
||||
ircmsg(creds.channel, "%s: Executing SQL `%s'.", current_username, arg);
|
||||
msgswp = raw(arg);
|
||||
ircmsg(creds.channel, msgswp);
|
||||
} else
|
||||
#endif /* !NO_VULN_COMMANDS */
|
||||
#if 0
|
||||
if (strncmp(cmd, "repo", 4) == 0)
|
||||
{
|
||||
/* ircmsg(creds.channel, "%s: Setting project repository...", current_username); */
|
||||
@ -227,10 +238,43 @@ parse_command(char const * cmd)
|
||||
msgswp = remind(creds.channel);
|
||||
ircmsg(creds.channel, "%s: %s", current_username, msgswp);
|
||||
}
|
||||
#endif /* 0 */
|
||||
else if (strncmp(cmd, "magic", 5) == 0)
|
||||
{ ircmsg(creds.channel, "%s: " IRC_YELLOW "%d" IRC_STOP, current_username, (rand() % atoi(arg)) + 1); }
|
||||
else if (strncmp(cmd, "say", 3) == 0)
|
||||
{ ircmsg(creds.channel, "%s", arg); }
|
||||
else if (strncmp(cmd, "poll", 4) == 0)
|
||||
{
|
||||
yes = no = undecided = 0;
|
||||
vote_on = 1;
|
||||
vote_count = atoi(arg);
|
||||
if (!vote_count)
|
||||
{ ircmsg(creds.channel, "!poll NUMBER_OF_VOTES What your voting on ..."); }
|
||||
else
|
||||
{ ircmsg(creds.channel, "poll: start"); }
|
||||
}
|
||||
else if (strncmp(cmd, "vote", 4) == 0)
|
||||
{
|
||||
/* fprintf(stderr, "y%d n%d u%d vote_count %d\n", yes, no, undecided, vote_count); */
|
||||
if (vote_on && vote_count)
|
||||
{
|
||||
switch (*arg)
|
||||
{
|
||||
case 'Y': case 'y': ERRMSG("YYY"); ++yes; break;
|
||||
case 'N': case 'n': ERRMSG("NNN"); ++no; break;
|
||||
case 'U': case 'u': ERRMSG("UUU"); ++undecided; break;
|
||||
default: ircmsg(creds.channel, "Unknown vote meaning: '%c'", *arg); goto stop;
|
||||
}
|
||||
if (--vote_count)
|
||||
{ ircmsg(creds.channel, "Votes remaining: %d", vote_count); }
|
||||
else
|
||||
{
|
||||
ircmsg(creds.channel, "poll results: %s",
|
||||
MAX(undecided,MAX(yes,no)) ? "UNDECIDED" :
|
||||
MAX(yes,no) ? "PASSED" : "REJECTED");
|
||||
vote_on = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stop:
|
||||
free(msgswp);
|
||||
}
|
||||
|
Reference in New Issue
Block a user