Compare commits

...

5 Commits

5 changed files with 27 additions and 7 deletions

View File

@ -5,6 +5,7 @@ DECL void api_rope(void);
DECL void rope(void);
DECL char * remind(char * who);
DECL char * raw(char const * const sql);
DECL int is_no_assignment(char const * const who);
extern char const * db;

View File

@ -48,3 +48,9 @@ static const char purge_assignments_stmt_template[] =
"DELETE FROM assignment "
"WHERE who = ?;"
;
static sqlite3_stmt* is_no_assignment_stmt;
static const char is_no_assignment_stmt_template[] =
"SELECT * FROM assignment "
"WHERE who = ?;"
;

View File

@ -35,6 +35,7 @@ api_init(void)
DBERR(stmt_prepare(get_nth_id_stmt));
DBERR(stmt_prepare(new_assignment_stmt));
DBERR(stmt_prepare(purge_assignments_stmt));
DBERR(stmt_prepare(is_no_assignment_stmt));
return 0;
}
@ -46,6 +47,7 @@ api_rope(void)
DBERR(sqlite3_finalize(get_nth_id_stmt));
DBERR(sqlite3_finalize(new_assignment_stmt));
DBERR(sqlite3_finalize(purge_assignments_stmt));
DBERR(sqlite3_finalize(is_no_assignment_stmt));
sqlite3_close(connection);
}
@ -172,7 +174,7 @@ DECL int
get_nth_id(const int i)
{
int r;
DBERR(sqlite3_reset(get_nth_id_stmt));
DBERR(sqlite3_reset(get_nth_id_stmt));
DBERR(sqlite3_bind_int(get_nth_id_stmt, 1, i));
DBERR(sqlite3_step(get_nth_id_stmt));
r = sqlite3_column_int(get_nth_id_stmt, 0);
@ -182,7 +184,7 @@ get_nth_id(const int i)
DECL void
new_assignment(char const * const who, const int project)
{
DBERR(sqlite3_reset(new_assignment_stmt));
DBERR(sqlite3_reset(new_assignment_stmt));
DBERR(sqlite3_bind_text(new_assignment_stmt, 1, who, -1, SQLITE_STATIC));
DBERR(sqlite3_bind_int(new_assignment_stmt, 2, project));
DBERR(sqlite3_step(new_assignment_stmt));
@ -199,7 +201,16 @@ random_assign(char const * const who)
DECL void
purge_assignments(char const * const who)
{
DBERR(sqlite3_reset(purge_assignments_stmt));
DBERR(sqlite3_reset(purge_assignments_stmt));
DBERR(sqlite3_bind_text(purge_assignments_stmt, 1, who, -1, SQLITE_STATIC));
DBERR(sqlite3_step(purge_assignments_stmt));
}
DECL int
is_no_assignment(char const * const who){
DBERR(sqlite3_reset(is_no_assignment_stmt));
DBERR(sqlite3_bind_text(is_no_assignment_stmt, 1, who, -1, SQLITE_STATIC));
const int e = sqlite3_step(is_no_assignment_stmt);
DBERR(e);
return (e == SQLITE_DONE);
}

View File

@ -110,6 +110,11 @@ event_connect(irc_session_t * session,
(void) count;
/* msg ChanServ IDENTIFY? */
irc_cmd_join(session, creds.channel, 0);
if(is_no_assignment(creds.channel)){
ircmsg(IRC_RED "No assignment for this channel. Finding a new...");
random_assign(creds.channel);
}
ircmsg(remind(creds.channel));
}
DECL void

View File

@ -104,9 +104,6 @@ parse_command(char const * cmd)
msgswp = remind(current_username);
ircmsg("%s: %s", current_username, msgswp);
}
// XXX: maybe no?
//else if (strcmp(cmd, "next") == 0) // TODO: implement
//{ ircmsg("%s: No future assignments", current_username); }
else if (strcmp(cmd, "help") == 0)
{
ircmsg(help_msg);
@ -121,7 +118,7 @@ parse_command(char const * cmd)
msgswp = dump();
ircmsg(msgswp);
}
else if (strcmp(cmd, "reroll") == 0) // TODO: implement
else if (strcmp(cmd, "reroll") == 0)
{
ircmsg("%s: Rerolling...", current_username);
purge_assignments(current_username);