This commit is contained in:
anon 2023-08-02 21:00:21 +02:00
commit fee8e2b415
9 changed files with 173 additions and 29 deletions

47
README.md Normal file
View File

@ -0,0 +1,47 @@
* Probotic
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
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.

4
bootstrap/bootstrap.sh Normal file
View File

@ -0,0 +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'

View File

@ -14,11 +14,14 @@ LDFLAGS='-lircclient -lsqlite3'
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 CPPFLAGS="$CPPFLAGS -DNDEBUG";
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: $?"

View File

@ -0,0 +1 @@
./probotic irc.rizon.net 6667 '#/g/chad' probotic

14
install.sh Normal file
View File

@ -0,0 +1,14 @@
#!/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 install
TARGET=${TARGET-/opt/probotic}
useradd probotic -r -s /sbin/nologin -d $TARGET
mkdir -p $TARGET
install -g probotic -o probotic -m 744 \
$DIR/bootstrap/probotic_data.sqlite probotic -v $TARGET
chown probotic:probotic $TARGET -R

View File

@ -31,6 +31,8 @@
irc_session_t * session = NULL;
irc_callbacks_t callbacks;
const char * channel;
char * get_username(const char * origin)
{
const char USERNAME_TERMINATOR = '!';
@ -56,7 +58,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);
@ -69,6 +71,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);
}
@ -79,21 +85,58 @@ 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;
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(!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);
//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);
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 <random janny>", 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
init(void)
init(char const * username, char const * server, int port)
{
if(api_init())
{ ERR(DB_ERROR, "Error initializing database."); }
@ -104,6 +147,7 @@ init(void)
session = irc_create_session(&callbacks);
if (!session)
<<<<<<< HEAD
{ ERR(IRC_ERROR, "Error creating IRC session"); }
irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME);
@ -116,13 +160,54 @@ rope(int r){
api_rope();
exit(r);
=======
{ 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\nPossible issue: bad URL, no network connection, bad port, refused connection."); }
return 0;
>>>>>>> 3d4a6cf8ff85869dba21c42576777254dbf4c68c
}
/* 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)
{
<<<<<<< HEAD
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];
#ifdef NDEBUG
fprintf(stderr, "-- %s:%d %s %s --\n", server, port, channel, username);
#endif /* NDEBUG */
if (!init(username, server, port))
{
while(1)
{}
irc_destroy_session(session);
return 0;
}
else
>>>>>>> 3d4a6cf8ff85869dba21c42576777254dbf4c68c
{ return 1; }
if (irc_run(session) != 0)

View File

@ -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)
{

7
uninstall.sh Normal file
View File

@ -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