From 044dc4506467ea89f815a8a0eeba1b0fa74e54fb Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:52:48 +0200 Subject: [PATCH 01/11] ignore gdb history file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a0e0410..10ff1a9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ obj **/*.o probotic config.h +.gdb_history From 80e6ea3f23a3ce7401560f300b51f1fa0afffe9f Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:53:06 +0200 Subject: [PATCH 02/11] ignore dbs --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 10ff1a9..4f9cdf1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ obj probotic config.h .gdb_history +*.sqlite From f363df0e7479f61074447ebd498ff7b12ffa42ab Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:53:32 +0200 Subject: [PATCH 03/11] define api fundation --- include/api.h | 5 +++++ src/api.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/unity.c | 1 + 3 files changed, 58 insertions(+) create mode 100644 include/api.h create mode 100644 src/api.c diff --git a/include/api.h b/include/api.h new file mode 100644 index 0000000..de605c0 --- /dev/null +++ b/include/api.h @@ -0,0 +1,5 @@ +#pragma once + +int api_init(void); +void api_rope(void); +char* remind(char* who); diff --git a/src/api.c b/src/api.c new file mode 100644 index 0000000..64f14da --- /dev/null +++ b/src/api.c @@ -0,0 +1,52 @@ +#include +#include +#include "stmt.h" +#include "irccolors.h" +#include "error.h" + +void rope(int r); + +#define DBFILE "test.sqlite" + +#define DBERR(line) do {\ + const int e = line; \ + if(e != SQLITE_OK && e != SQLITE_ROW && e != SQLITE_DONE) \ + { \ + fprintf(stderr, "sqlite (%d): %s\n", sqlite3_errcode(connection), sqlite3_errmsg(connection)); \ + rope(DB_ERROR); \ + } \ + } while (0) + +static sqlite3* connection = NULL; + +int +api_init(){ + DBERR(sqlite3_open(DBFILE, &connection)); + + stmt_prepare(remind_stmt); + + return 0; +} + +void api_rope(){ + DBERR(sqlite3_finalize(remind_stmt)); + sqlite3_close(connection); +} + +char* +remind(char* who){ + char* r; + char* title; + char* desc; + + DBERR(sqlite3_bind_text(remind_stmt, 1, who, -1, SQLITE_STATIC)); + + DBERR(sqlite3_step(remind_stmt)); + title = (char*)sqlite3_column_text(remind_stmt, 0); + title = strdup(title); + desc = (char*)sqlite3_column_text(remind_stmt, 1); + desc = strdup(desc); + asprintf(&r, IRC_COLOR_RED "%s: " IRC_COLOR_YELLOW "%s", title, desc); + + return r; +} diff --git a/src/unity.c b/src/unity.c index f4f411b..2c312b6 100644 --- a/src/unity.c +++ b/src/unity.c @@ -1,3 +1,4 @@ #include "parse.c" #include "fetch.c" +#include "api.c" #include "main.c" From 941f9246088d4b7ab5421eb92a10f3f14429c29a Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:54:18 +0200 Subject: [PATCH 04/11] more robust sql scripts --- defaults.sql | 22 ++++++++++++++++++++++ init.sql | 23 ++++++++++------------- 2 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 defaults.sql diff --git a/defaults.sql b/defaults.sql new file mode 100644 index 0000000..ca02da9 --- /dev/null +++ b/defaults.sql @@ -0,0 +1,22 @@ +INSERT INTO difficulty VALUES('easy'); +INSERT INTO difficulty VALUES('medium'); +INSERT INTO difficulty VALUES('hard'); +INSERT INTO difficulty VALUES('fuck you'); + +INSERT INTO tag VALUES('math'); +INSERT INTO tag VALUES('AI'); +INSERT INTO tag VALUES('networking'); +INSERT INTO tag VALUES('games'); +INSERT INTO tag VALUES('rendering'); +INSERT INTO tag VALUES('simulation'); + +-- +INSERT INTO project (title, body) VALUES ( + 'test project', + 'desc' +); + +INSERT INTO assignment VALUES ( + '#/g/chad', + 1 +); diff --git a/init.sql b/init.sql index 6c89cc1..9e61c26 100644 --- a/init.sql +++ b/init.sql @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS project; CREATE TABLE project ( title VARCHAR(64) NOT NULL, body TEXT DEFAULT NULL, @@ -8,29 +9,25 @@ CREATE TABLE project ( span INT NOT NULL DEFAULT 7 -- time to last for in days ); +DROP TABLE IF EXISTS difficulty; CREATE TABLE difficulty ( diff VARCHAR(16) ); - -INSERT INTO difficulty VALUES('easy'); -INSERT INTO difficulty VALUES('medium'); -INSERT INTO difficulty VALUES('hard'); -INSERT INTO difficulty VALUES('fuck you'); +DROP TABLE IF EXISTS tag; CREATE TABLE tag ( t VARCHAR(16) ); --- Some default (not all) tags -INSERT INTO tag VALUES('math'); -INSERT INTO tag VALUES('AI'); -INSERT INTO tag VALUES('networking'); -INSERT INTO tag VALUES('games'); -INSERT INTO tag VALUES('rendering'); -INSERT INTO tag VALUES('simulation'); - +DROP TABLE IF EXISTS project_tag; CREATE TABLE project_tag ( project INT REFERENCES project(rowid), tag INT REFERENCES tag(rowid) ); + +DROP TABLE IF EXISTS assignment; +CREATE TABLE assignment ( + who VARCHAR(32) NOT NULL, + project INT NOT NULL REFERENCES project(rowid) +); From da87ab7415fe4d4f80b8006eb62256a084d70051 Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:54:39 +0200 Subject: [PATCH 05/11] header fix --- include/config.mk.h | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 include/config.mk.h diff --git a/include/config.mk.h b/include/config.mk.h deleted file mode 100644 index 70070ea..0000000 --- a/include/config.mk.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef CONFIG_H_ - -#define SERVER "irc.rizon.net" -#define PORT 6667 -#define CHANNEL "#/g/chad" -#define USERNAME "probotic" - -#define CONFIG_H_ -#endif From 8e766f7ca6b57d15c4376790303193035d0c94a6 Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:54:56 +0200 Subject: [PATCH 06/11] fix linking, use debug --- build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index b4c6763..dd73e9c 100755 --- a/build.sh +++ b/build.sh @@ -8,9 +8,9 @@ PROGN=${PROGN:-probotic} PREFIX=${PREFIX:-$DIR} CC=${CC-cc} -CFLAGS='-std=c99 -Wall -Wextra -Wpedantic -Wno-unused-parameter' -CPPFLAGS="-I/usr/bin/ircclient/ -Iinclude -D_GNU_SOURCE -DPROGN=\"$PROGN\"" -LDFLAGS='-lircclient' +CFLAGS='-std=c99 -Wall -Wextra -Wpedantic -Wno-unused-parameter -g' +CPPFLAGS="-I/usr/bin/ircclient/ -I/usr/include/libircclient/ -Iinclude -D_GNU_SOURCE -DPROGN=\"$PROGN\"" +LDFLAGS='-lircclient -lsqlite3' mkdir -p $PREFIX && echo "Made directory: $PREFIX" From 90432c710ad1726932cc91044b15705d4eb6ce24 Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:55:12 +0200 Subject: [PATCH 07/11] +irc color esc codes --- include/irccolors.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 include/irccolors.h diff --git a/include/irccolors.h b/include/irccolors.h new file mode 100644 index 0000000..ccc5de4 --- /dev/null +++ b/include/irccolors.h @@ -0,0 +1,16 @@ +#define IRC_COLOR_WHITE "\x0300" +#define IRC_COLOR_BLACK "\x0301" +#define IRC_COLOR_BLUE "\x0302" +#define IRC_COLOR_GREEN "\x0303" +#define IRC_COLOR_RED "\x0304" +#define IRC_COLOR_BROWN "\x0305" +#define IRC_COLOR_PURPLE "\x0306" +#define IRC_COLOR_ORANGE "\x0307" +#define IRC_COLOR_YELLOW "\x0308" +#define IRC_COLOR_LIGHT_GREEN "\x0309" +#define IRC_COLOR_TEAL "\x0310" +#define IRC_COLOR_LIGHT_CYAN "\x0311" +#define IRC_COLOR_LIGHT_BLUE "\x0312" +#define IRC_COLOR_PINK "\x0313" +#define IRC_COLOR_GREY "\x0314" +#define IRC_COLOR_LIGHT_GREY "\x0315" From c0d27e49ce1b4a8685251dc2ac4e01fa70115ec2 Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:55:21 +0200 Subject: [PATCH 08/11] define exit error codes --- include/error.h | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 include/error.h diff --git a/include/error.h b/include/error.h new file mode 100644 index 0000000..58c91e3 --- /dev/null +++ b/include/error.h @@ -0,0 +1,2 @@ +#define DB_ERROR 100 +#define IRC_ERROR 200 From e2418462bac9bddaca76dfcb3c058508f9c8455d Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:55:35 +0200 Subject: [PATCH 09/11] place sql statements in sep header --- include/stmt.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 include/stmt.h diff --git a/include/stmt.h b/include/stmt.h new file mode 100644 index 0000000..2a8d78b --- /dev/null +++ b/include/stmt.h @@ -0,0 +1,16 @@ +static sqlite3_stmt* remind_stmt; +static const char remind_stmt_template[] = + "SELECT " + "title," + "body," + "difficulty," + "repo_link," + "trigger_date," + "started DATE," + "span" + " FROM assignment INNER JOIN project on assignment.project = project.rowid " + "WHERE who = ?;" +; + +#define stmt_prepare(stmt) \ + sqlite3_prepare_v2(connection, stmt ## _template, -1, &stmt, NULL) From 2a28930a5085ba5b094a484eb6abb11be1ad2d86 Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:55:47 +0200 Subject: [PATCH 10/11] wrapper Makefile for dummies --- Makefile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..78616d1 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +main: + ./build.sh From 90b9baaa180dc4ef686cb4003a50abc2a4fb0389 Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:55:52 +0200 Subject: [PATCH 11/11] remind demo --- src/main.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/main.c b/src/main.c index 9256b96..d231adb 100644 --- a/src/main.c +++ b/src/main.c @@ -26,21 +26,22 @@ #include "utils.h" #include "config.h" +#include "api.h" -irc_session_t * session; +irc_session_t * session = NULL; irc_callbacks_t callbacks; char * get_username(const char * origin) { - const char USERNAME_TERMINATOR = '!'; - int i = 0; + const char USERNAME_TERMINATOR = '!'; + int i = 0; char * r; while (origin[i] != USERNAME_TERMINATOR) { i++; } r = (char *) malloc(i + 1); strncpy(r, origin, i); r[i] = '\00'; - return r; + return r; } void @@ -83,38 +84,50 @@ event_channel(irc_session_t * session, (void) channel; (void) message; - char * swp = get_username(origin); - msg_wrapper("%s, you are a faggot for this opinion.", swp); - free(swp); + if(!strcmp(message, "!remind")){ + msg_wrapper("%s", remind("#/g/chad")); + } + //char * swp = get_username(origin); + //msg_wrapper("%s, you are a faggot for this opinion.", swp); + //free(swp); } int init(void) { + if(api_init()) + { ERR(DB_ERROR, "Error initializing database."); } + memset(&callbacks, 0, sizeof(callbacks)); callbacks.event_connect = event_connect; callbacks.event_channel = event_channel; session = irc_create_session(&callbacks); if (!session) - { ERR(1, "Error creating IRC session"); } + { ERR(IRC_ERROR, "Error creating IRC session"); } irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME); - if (irc_run(session) != 0) - { ERR(1, "Error running IRC session\nNo net?"); } - return 0; + + return 0; +} + +void +rope(int r){ + if(session){ irc_destroy_session(session); } + api_rope(); + + exit(r); } int main(int argc, char ** argv) { - if(!init()) - { - while(1) - {} - irc_destroy_session(session); - return 0; - } - else + if(init()) { return 1; } + + if (irc_run(session) != 0) + { ERR(1, "Error running IRC session\nNo net?"); } + + rope(0); + return 0; }