From 943fa8ad1602da4b84eed07672b683f3009d5af8 Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 15:08:24 +0200 Subject: [PATCH 1/2] use stderr for errors --- src/bot/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bot/main.c b/src/bot/main.c index 9b4b8d8..5efd3a0 100644 --- a/src/bot/main.c +++ b/src/bot/main.c @@ -83,14 +83,14 @@ init() session = irc_create_session(&callbacks); if (!session) { - printf("Error creating IRC session\n"); + fputs("Error creating IRC session\n", stderr); return 1; } irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME); if (irc_run(session) != 0) { - printf("Error running IRC session\nNo net?"); + fputs("Error running IRC session\nNo net?", stderr); return 1; } From a1f87eaccac3669671c892dbe485e69c721a81d3 Mon Sep 17 00:00:00 2001 From: Emil Date: Wed, 2 Aug 2023 07:08:22 -0600 Subject: [PATCH 2/2] MY EYES --- src/bot/main.c | 6 ++-- src/fetch.c | 21 +++++------ src/main.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 120 insertions(+), 17 deletions(-) diff --git a/src/bot/main.c b/src/bot/main.c index 5efd3a0..200f0ee 100644 --- a/src/bot/main.c +++ b/src/bot/main.c @@ -1,5 +1,7 @@ -// @COMPILECMD gcc main.c -lircclient +/* @COMPILECMD gcc main.c -lircclient */ + #define _GNU_SOURCE + #include #include #include @@ -17,7 +19,7 @@ char* get_username(const char* origin){ const char USERNAME_TERMINATOR = '!'; int i = 0; - while (origin[i] != USERNAME_TERMINATOR) + while (origin[i] !=USERNAME_TERMINATOR) { i++; } diff --git a/src/fetch.c b/src/fetch.c index e3c3384..408a192 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -1,27 +1,24 @@ /* fetch.c - fetch from file */ #include +#include + +#include #ifdef LOCAL_PROBOTIC_MAIN int -main (int argc, - char ** argv) +main (int const argc, + char const * const * const argv) /* yeah. */ { - if (argc > 1) + if (argc == 2) { - char * b; - /* get week number via stoi */ - ++argv; --argc; - /* no options, yet */ - while (++argv, --argc) - { - printf("%s\n", *argv); - } + sqlite3 * db; + int exit = sqlite3_open("test.db", &db); + char const * const query = "SELECT * FROM PERSON"; } else { - /* no stdin yet */ /* usage(); */ return 1; } diff --git a/src/main.c b/src/main.c index 7114a90..2cfdbad 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,110 @@ -/* main.c - this file would handle the bot? */ +/* @COMPILECMD ../unity.sh */ -int main(void) +#define _GNU_SOURCE + +#include +#include +#include + +#include + +#define SERVER "irc.rizon.net" +#define PORT 6667 +#define CHANNEL "#/g/chad" +#define USERNAME "probotic" + +irc_session_t * session; +irc_callbacks_t callbacks; + +char * get_username(const char * origin) { - return 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; +} + +void +msg_wrapper(const char* fmt, + ...) +{ + va_list args; + char * fmtdmsg; + + va_start(args, fmt); + if(vasprintf(&fmtdmsg, fmt, args) == -1) + { exit(1); } + + puts(fmtdmsg); + irc_cmd_msg(session, CHANNEL, fmtdmsg); + + free(fmtdmsg); + va_end(args); +} + +void +event_connect(irc_session_t *session, + const char *event, + const char *origin, + const char **params, + unsigned int count) +{ + irc_cmd_join(session, CHANNEL, 0); +} + +void +event_channel(irc_session_t *session, + const char *event, + const char *origin, + const char **params, + unsigned int count) +{ + const char *channel = params[0]; + const char *message = params[1]; + + char* swp = get_username(origin); + msg_wrapper("%s, you are a faggot for this opinion.", swp); + free(swp); +} + +int +init(void) +{ + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.event_connect = event_connect; + callbacks.event_channel = event_channel; + + session = irc_create_session(&callbacks); + if (!session) { + fprintf(stderr, "Error creating IRC session\n"); + return 1; + } + irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME); + if (irc_run(session) != 0) { + fprintf(stderr, "Error running IRC session\nNo net?"); + return 1; + } + return 0; +} + +int +main(int argc, + char ** argv) +{ + if(!init()) + { + while(1) + {} + irc_destroy_session(session); + return 0; + } + else + { return 1; } }