Basic command structure\n
This commit is contained in:
parent
fc31f9884b
commit
3d4a6cf8ff
3
build.sh
3
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"
|
||||
|
||||
|
1
docs/example_cli_usage.txt
Normal file
1
docs/example_cli_usage.txt
Normal file
@ -0,0 +1 @@
|
||||
./probotic irc.rizon.net 6667 '#/g/chad' probotic
|
49
src/main.c
49
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 <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
|
||||
@ -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)
|
||||
|
17
src/parse.c
17
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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user