create assignment for channel on join ifndef
This commit is contained in:
parent
01ca07a522
commit
9841988af1
@ -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);
|
||||
|
||||
#define API_H_
|
||||
#endif
|
||||
|
@ -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 = ?;"
|
||||
;
|
||||
|
17
src/api.c
17
src/api.c
@ -33,6 +33,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;
|
||||
}
|
||||
|
||||
@ -44,6 +45,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);
|
||||
}
|
||||
|
||||
@ -170,7 +172,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);
|
||||
@ -180,7 +182,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));
|
||||
@ -197,7 +199,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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user