Compare commits

...

13 Commits

Author SHA1 Message Date
29b96f58e4 send irc messages by line by line 2023-08-03 13:09:47 +02:00
d10cb36a4b fuck optimization 2023-08-03 13:09:22 +02:00
32d27a182f stop shitting up chad 2023-08-03 12:57:41 +02:00
1c6ded5f0a fix types regarding api prototypes 2023-08-03 12:43:43 +02:00
fd5b813644 mk parsed commands call api functions 2023-08-03 12:43:03 +02:00
4ab5e9b614 remove unused return value 2023-08-03 12:42:20 +02:00
40f014c432 implement dump 2023-08-03 12:42:20 +02:00
ebd8918966 remind to repo link too 2023-08-03 12:40:45 +02:00
39cbc21d0d break raw() output to lines 2023-08-03 12:02:26 +02:00
d56564ed63 Merge branch 'master' of https://git.lain.church/emil/probotic 2023-08-03 11:58:29 +02:00
ae9f042891 actualized PARAMS_COUNT 2023-08-03 12:33:59 +03:00
Emil
6aba8323d9 Change to -ggdb 2023-08-03 02:28:24 -06:00
Emil
3b20d84f9e Fix minor build.sh issue 2023-08-03 02:17:28 -06:00
7 changed files with 49 additions and 14 deletions

View File

@ -11,4 +11,4 @@ probotic: $(SRC) $(HDR)
$(SRC) $(HDR):
run:
./probotic -server irc.rizon.net -port 6667 -username probotic -channel '#/g/chad'
./probotic -server irc.rizon.net -port 6667 -username probotic -channel '#stop_shitting_up_chad'

View File

@ -15,9 +15,9 @@ LDFLAGS='-lircclient -lsqlite3'
mkdir -p $PREFIX && echo "Made directory: $PREFIX"
# Bourne shell is evil
if [ ${DEBUG} -eq 1 ]
if [ ${DEBUG-0} -eq 1 ]
then
CFLAGS=`echo "${CFLAGS} -Og -g3"`
CFLAGS=`echo "${CFLAGS} -O0 -ggdb"`
else
CPPFLAGS="${CPPFLAGS} -DNDEBUG"
CFLAGS=`echo "${CFLAGS} -O2 -flto=auto -fomit-frame-pointer -s"`

View File

@ -15,5 +15,10 @@ DECL void parse_command(char * cmd);
DECL int parse_creds(char const * creds_file);
DECL void clean_creds(void);
DECL char * remind(char * who);
DECL void set_repo(const char * const who, const char * const link);
DECL char * dump(void);
DECL char * raw(const char * const sql);
#define CREDS_PARSER_H
#endif

View File

@ -22,3 +22,7 @@ static const char set_repo_stmt_template[] =
"repo_link = ? "
"WHERE who = ?;"
;
static const char dump_stmt[] =
"SELECT * FROM project;"
;

View File

@ -59,6 +59,7 @@ remind(char * who)
char * r;
char * title;
char * desc;
char * repo;
DBERR(sqlite3_bind_text(remind_stmt, 1, who, -1, SQLITE_STATIC));
const int i = sqlite3_step(remind_stmt);
DBERR(i);
@ -68,7 +69,9 @@ remind(char * who)
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);
repo = (char *) sqlite3_column_text(remind_stmt, 3);
repo = strdup(repo);
asprintf(&r, IRC_COLOR_RED "%s: " IRC_COLOR_YELLOW "%s (@%s)", title, desc, repo);
}
else
{
@ -77,14 +80,12 @@ remind(char * who)
return r;
}
DECL char *
set_repo(char* who, char* link)
DECL void
set_repo(const char * const who, const char * const link)
{
char * r;
DBERR(sqlite3_bind_text(set_repo_stmt, 1, link, -1, SQLITE_STATIC));
DBERR(sqlite3_bind_text(set_repo_stmt, 2, who, -1, SQLITE_STATIC));
DBERR(sqlite3_step(set_repo_stmt));
return r;
}
DECL int
@ -106,12 +107,20 @@ rtos(void* data,
strcat(*r, "NULL");
}
}
strcat(*r, "|");
strcat(*r, "|\n");
return 0;
}
DECL char *
dump(){
char* errmsg;
char* r = (char*)calloc(sizeof(char), 10000); // TODO: allow for reallocing in rtos, start with a smaller value
DBERR(sqlite3_exec(connection, dump_stmt, rtos, &r, &errmsg));
return r;
}
DECL char *
raw(const char * const sql)
{
char* errmsg;

View File

@ -63,7 +63,11 @@ ircmsg(const char* fmt,
{ exit(1); }
puts(fmtdmsg);
IRCMSG(fmtdmsg); // TODO: make it send the message line by line
const char* delim = "\n";
char* data = strtok(fmtdmsg, delim);
do{
IRCMSG(data);
}while((data = strtok(NULL, delim), data));
free(fmtdmsg);
va_end(args);

View File

@ -24,7 +24,7 @@
#include "parse.h"
#include "error.h"
#define PARAMS_COUNT 2
#define PARAMS_COUNT 5
creds_t creds = {0};
@ -65,7 +65,11 @@ parse_command(char * cmd)
else if (strcmp(cmd, "next") == 0)
{ ircmsg("%s: No future assignments", current_username); }
else if (strcmp(cmd, "dump") == 0)
{ ircmsg("%s: All projects", current_username); }
{
ircmsg("%s: All projects:", current_username);
msgswp = dump();
ircmsg(msgswp);
}
else if (strcmp(cmd, "reroll") == 0)
{ ircmsg("%s: No more rerolls possible", current_username); }
}
@ -80,9 +84,18 @@ parse_command(char * cmd)
msgswp = raw(arg);
ircmsg(msgswp);
}
else if (strcmp(cmd, "set_repo") == 0)
{
ircmsg("%s: Setting project repository...", current_username);
set_repo(creds.channel, arg);
msgswp = remind(creds.channel);
ircmsg("%s: %s", current_username, msgswp);
}
else if (strcmp(cmd, "submit") == 0)
{ ircmsg("%s: Submitting project link '%s' to <random janny>",
current_username, arg); }
{
ircmsg("%s: Submitting project link '%s' to <random janny>",
current_username, arg);
}
}
free(msgswp);
}