From e46d3e7bddc48abcf6d2b87997c5eb5bb31b86f5 Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 2 Aug 2023 10:04:57 -0600 Subject: [PATCH 1/7] Update language and tags --- init.sql | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/init.sql b/init.sql index 39fddc6..44b30cd 100644 --- a/init.sql +++ b/init.sql @@ -11,23 +11,26 @@ 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'); - +INSERT INTO difficulty VALUES('Easy'); +INSERT INTO difficulty VALUES('Medium'); +INSERT INTO difficulty VALUES('Hard'); +INSERT INTO difficulty VALUES('Fuck You'); + 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'); +INSERT INTO tag VALUES('Algorithm'); +INSERT INTO tag VALUES('Calculators'); +INSERT INTO tag VALUES('Games'); +INSERT INTO tag VALUES('Math'); +INSERT INTO tag VALUES('Networking'); +INSERT INTO tag VALUES('Rendering'); +INSERT INTO tag VALUES('Simulation'); +INSERT INTO tag VALUES('Tools'); CREATE TABLE project_tag ( project INT REFERENCES project(rowid), From 8ae8351db1d911eddbb225c5272c8ef2eadfeaf1 Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 2 Aug 2023 10:54:01 -0600 Subject: [PATCH 2/7] simple UNTESTED installer --- .gitignore | 1 + README.md | 44 ++++++++++++++++++++++++++++++++++++++++++ bootstrap/bootstrap.sh | 1 + init.sql => bootstrap/init.sql | 0 install.sh | 15 ++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 README.md create mode 100644 bootstrap/bootstrap.sh rename init.sql => bootstrap/init.sql (100%) create mode 100644 install.sh diff --git a/.gitignore b/.gitignore index a0e0410..7afd29b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ obj **/*.o probotic config.h +*.sqlite diff --git a/README.md b/README.md new file mode 100644 index 0000000..27f8987 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +* Probotic + +Healthy for your coding ability, take once weekly, excessive doses +may result in arthritis, ass pain, and death. + +* Description + +This bot will let you be delagated with challenges at dates within +it's database, this can all be done via the IRC interface. + +See doc/api.md for detailed information about this interface. + +* Building and Installation + +First, you'll want to customize include/config.h as detailed from +include/config.mk.h, then build via running ./build.sh + +This'll require a few libraries: +libircclient-dev libsqlite3-dev build-essentials + +You may then install the successful build, this'll naturally construct +a user, a database and a installation within this user's profile. You +may enact this by running ./install.sh under root, please view this +script and it's subscript ./bootstrap/boostrap.sh before running either. + +* License + +Copyright 2023 anon, fa11_1eaf, Emil + +Probotic is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License version 3 only as +published by the Free Software Foundation. + +Probotic is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License version 3 for more details. + +The above copyright notice, this permission notice and the word +"NIGGER" shall be included in all copies or substantial portions +of the Software. + +You should have received a copy of the GNU General Public License +version 3 + NIGGER along with Probotic. diff --git a/bootstrap/bootstrap.sh b/bootstrap/bootstrap.sh new file mode 100644 index 0000000..c0a9617 --- /dev/null +++ b/bootstrap/bootstrap.sh @@ -0,0 +1 @@ +sqlite3 probotic_data.sqlite -init init.sql -line '.quit' diff --git a/init.sql b/bootstrap/init.sql similarity index 100% rename from init.sql rename to bootstrap/init.sql diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..41bf659 --- /dev/null +++ b/install.sh @@ -0,0 +1,15 @@ +#!/bin/sh +DIR=$(dirname $(readlink -f "$0")) +cd $DIR +[ ! -e $DIR/probotic ] && echo "You should run './build.sh' before this script." \ + && return +# run bootstrapper +[ ! -e $DIR/bootstrap/ ] && $DIR/bootstrap/bootstrap.sh +# generate directories and prepare for install +TARGET=${TARGET-/opt/probotic} +mkdir -p $TARGET +useradd -r -s /sbin/nologin probotic -d $TARGET +cp $DIR/bootstrap/probotic_data.sqlite $TARGET +chown probotic:probotic $TARGET -R +# install files +install -g=probotic -o=probotic -m 744 probotic -sv $TARGET From df424c4c45d4311762aa0fd3d0bb11d1bdd0a587 Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 2 Aug 2023 10:58:08 -0600 Subject: [PATCH 3/7] README note about Rizon --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 27f8987..9c2da5b 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ Healthy for your coding ability, take once weekly, excessive doses may result in arthritis, ass pain, and death. +Only for real chads, goto irc.rizon.net/#/g/chad for first-hand +enjoyment of the one and only probotic and to yell at the developers. + * Description This bot will let you be delagated with challenges at dates within From c6316ac5862198803e468b3f9d46fe455b58507b Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 2 Aug 2023 11:07:35 -0600 Subject: [PATCH 4/7] Better installer and fixed bug regarding build --- build.sh | 6 ++++-- install.sh | 9 ++++----- uninstall.sh | 7 +++++++ 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 uninstall.sh diff --git a/build.sh b/build.sh index b4c6763..e8fe3a4 100755 --- a/build.sh +++ b/build.sh @@ -14,11 +14,13 @@ LDFLAGS='-lircclient' mkdir -p $PREFIX && echo "Made directory: $PREFIX" -if [ ! -z ${DEBUG} ] ; then CFLAG="$CFLAGS -Og -g3"; - else CFLAG="$CFLAGS -O2 -flto=auto -fomit-frame-pointer"; fi +if [ ! -z ${DEBUG} ]; then CFLAG="$CFLAGS -Og -g3"; + else CFLAG="$CFLAGS -O2 -flto=auto -fomit-frame-pointer -s"; fi [ ! -z ${SAN} ] && CFLAG="$CFLAGS -fsanitize=$SAN" +[ ! -e $DIR/include/config.h ] && cp $DIR/include/config.mk.h $DIR/include/config.h + echo "$CC $CFLAGS -pipe $DIR/src/unity.c -o $PREFIX/$PROGN $CPPFLAGS $LDFLAGS" $CC $CFLAGS -pipe $DIR/src/unity.c -o $PREFIX/$PROGN $CPPFLAGS $LDFLAGS echo "\nStatus: $?" diff --git a/install.sh b/install.sh index 41bf659..543d043 100644 --- a/install.sh +++ b/install.sh @@ -5,11 +5,10 @@ cd $DIR && return # run bootstrapper [ ! -e $DIR/bootstrap/ ] && $DIR/bootstrap/bootstrap.sh -# generate directories and prepare for install +# generate directories and install TARGET=${TARGET-/opt/probotic} +useradd probotic -r -s /sbin/nologin -d $TARGET mkdir -p $TARGET -useradd -r -s /sbin/nologin probotic -d $TARGET -cp $DIR/bootstrap/probotic_data.sqlite $TARGET +install -g probotic -o probotic -m 744 \ + $DIR/bootstrap/probotic_data.sqlite probotic -v $TARGET chown probotic:probotic $TARGET -R -# install files -install -g=probotic -o=probotic -m 744 probotic -sv $TARGET diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..6a1611c --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# doubles as a cleanup script +DIR=$(dirname $(readlink -f "$0")) +cd $DIR +TARGET=${TARGET-/opt/probotic} +userdel probotic +rm -rf $TARGET $DIR/bootstrap/probotic_data.sqlite probotic From 55bdf8bd5292e4718d743f88f1820badfcaddd99 Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 2 Aug 2023 11:12:17 -0600 Subject: [PATCH 5/7] updated bootstrap.sh file --- bootstrap/bootstrap.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bootstrap/bootstrap.sh b/bootstrap/bootstrap.sh index c0a9617..5c2cb54 100644 --- a/bootstrap/bootstrap.sh +++ b/bootstrap/bootstrap.sh @@ -1 +1,4 @@ +#!/bin/sh +# Tested to work 100% of the time when that file doesn't exist +# probably sqlite3 probotic_data.sqlite -init init.sql -line '.quit' From fc31f9884bc38b416e6eaf60e8b571de01069158 Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 2 Aug 2023 11:55:17 -0600 Subject: [PATCH 6/7] Updated the main function to support options --- build.sh | 2 +- src/main.c | 42 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/build.sh b/build.sh index e8fe3a4..ff16ecc 100755 --- a/build.sh +++ b/build.sh @@ -8,7 +8,7 @@ PROGN=${PROGN:-probotic} PREFIX=${PREFIX:-$DIR} CC=${CC-cc} -CFLAGS='-std=c99 -Wall -Wextra -Wpedantic -Wno-unused-parameter' +CFLAGS='-std=c99 -Wall -Wextra -Wpedantic' CPPFLAGS="-I/usr/bin/ircclient/ -Iinclude -D_GNU_SOURCE -DPROGN=\"$PROGN\"" LDFLAGS='-lircclient' diff --git a/src/main.c b/src/main.c index 9256b96..bd438f0 100644 --- a/src/main.c +++ b/src/main.c @@ -30,6 +30,8 @@ irc_session_t * session; irc_callbacks_t callbacks; +const char * channel; + char * get_username(const char * origin) { const char USERNAME_TERMINATOR = '!'; @@ -55,7 +57,7 @@ msg_wrapper(const char* fmt, { exit(1); } puts(fmtdmsg); - irc_cmd_msg(session, CHANNEL, fmtdmsg); + irc_cmd_msg(session, channel, fmtdmsg); free(fmtdmsg); va_end(args); @@ -68,6 +70,10 @@ event_connect(irc_session_t * session, const char ** params, unsigned int count) { + (void) event; + (void) origin; + (void) params; + (void) count; irc_cmd_join(session, CHANNEL, 0); } @@ -78,18 +84,22 @@ event_channel(irc_session_t * session, const char ** params, unsigned int count) { + const char * channel = params[0]; const char * message = params[1]; + (void) session; + (void) event; + (void) origin; (void) channel; (void) message; - + (void) count; char * swp = get_username(origin); msg_wrapper("%s, you are a faggot for this opinion.", swp); free(swp); } int -init(void) +init(char const * username, char const * server, int port) { memset(&callbacks, 0, sizeof(callbacks)); callbacks.event_connect = event_connect; @@ -98,17 +108,37 @@ init(void) session = irc_create_session(&callbacks); if (!session) { ERR(1, "Error creating IRC session"); } - irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME); + irc_connect(session, server, port, 0, username, username, username); if (irc_run(session) != 0) { ERR(1, "Error running IRC session\nNo net?"); } return 0; } + +/* args: server port channel [username] - defaults to probotic */ + +/* I'd have to give up constification for server:port */ int main(int argc, - char ** argv) + char const ** argv) { - if(!init()) + char const * username; + char const * server; + int port; + if (argc > 5 || argc < 4) + { + ERRMSG("server port channel [username]"); + return 1; + } + if (argc > 4) + { username = argv[4]; } + else + { username = "probotic"; } + channel = argv[3]; + port = atoi(argv[2]); + server = argv[1]; + fprintf(stderr, "-- %s:%d %s %s --", server, port, channel, username); + if (!init(username, server, port)) { while(1) {} From 3d4a6cf8ff85869dba21c42576777254dbf4c68c Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 2 Aug 2023 12:38:51 -0600 Subject: [PATCH 7/7] Basic command structure\n --- build.sh | 3 ++- docs/example_cli_usage.txt | 1 + src/main.c | 49 ++++++++++++++++++++++++++++++++++++++-------- src/parse.c | 17 ---------------- 4 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 docs/example_cli_usage.txt diff --git a/build.sh b/build.sh index ff16ecc..884aafc 100755 --- a/build.sh +++ b/build.sh @@ -15,7 +15,8 @@ LDFLAGS='-lircclient' mkdir -p $PREFIX && echo "Made directory: $PREFIX" if [ ! -z ${DEBUG} ]; then CFLAG="$CFLAGS -Og -g3"; - else CFLAG="$CFLAGS -O2 -flto=auto -fomit-frame-pointer -s"; fi + else CPPFLAGS="$CPPFLAGS -DNDEBUG"; + CFLAG="$CFLAGS -O2 -flto=auto -fomit-frame-pointer -s"; fi [ ! -z ${SAN} ] && CFLAG="$CFLAGS -fsanitize=$SAN" diff --git a/docs/example_cli_usage.txt b/docs/example_cli_usage.txt new file mode 100644 index 0000000..ab93849 --- /dev/null +++ b/docs/example_cli_usage.txt @@ -0,0 +1 @@ +./probotic irc.rizon.net 6667 '#/g/chad' probotic diff --git a/src/main.c b/src/main.c index bd438f0..c9d4399 100644 --- a/src/main.c +++ b/src/main.c @@ -57,7 +57,7 @@ msg_wrapper(const char* fmt, { exit(1); } puts(fmtdmsg); - irc_cmd_msg(session, channel, fmtdmsg); + irc_cmd_msg(session, channel, fmtdmsg); free(fmtdmsg); va_end(args); @@ -84,18 +84,48 @@ event_channel(irc_session_t * session, const char ** params, unsigned int count) { - + size_t i = 0, len; const char * channel = params[0]; - const char * message = params[1]; + char * message = params[1]; + char * arg; + char * swp; (void) session; (void) event; (void) origin; (void) channel; (void) message; (void) count; - char * swp = get_username(origin); - msg_wrapper("%s, you are a faggot for this opinion.", swp); - free(swp); + swp = get_username(origin); + /* msg_wrapper("%s, you are a faggot for this opinion.", swp); */ + /* parses the command */ + len = strlen(message); + while (message[i] != ' ') + { ++i; } + message[i] = '\0'; + arg = message + i + 1; + + if (*message == '!') + { + ++message; + /* if (strcmp(message, "stop") == 0) { exit(1); } */ + if (strcmp(message, "remind") == 0) + { msg_wrapper("%s: No current assignment.", swp); } + else if (strcmp(message, "next") == 0) + { msg_wrapper("%s: No future assignments", swp); } + else if (strcmp(message, "raw") == 0) + { msg_wrapper("%s: executing sql %s", arg); } + else if (strcmp(message, "dump") == 0) + { msg_wrapper("%s: all projects... they don't seem to exist!"); } + else if (strcmp(message, "submit") == 0) + { msg_wrapper("%s: Submitting project link '%s' to ", swp, arg); } + else if (strcmp(message, "reroll") == 0) + { msg_wrapper("%s: No more rerolls possible.", swp); } +#ifdef NDEBUG + else + { msg_wrapper("No such command '%s'", message); } +#endif /* NDEBUG */ + } + free(swp); } int @@ -109,8 +139,9 @@ init(char const * username, char const * server, int port) if (!session) { ERR(1, "Error creating IRC session"); } irc_connect(session, server, port, 0, username, username, username); + /* We should figure out how the failure happens so we can tell the user that. */ if (irc_run(session) != 0) - { ERR(1, "Error running IRC session\nNo net?"); } + { ERR(1, "Error running IRC session\nPossible issue: bad URL, no network connection, bad port, refused connection."); } return 0; } @@ -137,7 +168,9 @@ main(int argc, channel = argv[3]; port = atoi(argv[2]); server = argv[1]; - fprintf(stderr, "-- %s:%d %s %s --", server, port, channel, username); +#ifdef NDEBUG + fprintf(stderr, "-- %s:%d %s %s --\n", server, port, channel, username); +#endif /* NDEBUG */ if (!init(username, server, port)) { while(1) diff --git a/src/parse.c b/src/parse.c index ea15297..b94a5b4 100644 --- a/src/parse.c +++ b/src/parse.c @@ -44,23 +44,6 @@ int parse_repo(char const * arg) } int -parse_command(char const * command, - const char * arg /* NULLABLE */) -{ - /* I know. */ -#define COMMAND(cmd,fn) if (strcmp(command,cmd) == 0) { return fn(arg); } else - COMMAND("remind", parse_remind) - COMMAND("set_repo", parse_repo) - /* COMMAND("raw", sql_execute?) */ - /* COMMAND("post", parse_post) */ - /* COMMAND("prune", parse_prune) */ - /* COMMAND("search", parse_search) */ - /* COMMAND("list", parse_list) */ - { ERR(1,"No such command.\n"); } -#undef COMMAND -} - -int parse_creds(creds_t * creds, char const * creds_file) {