From 90b9baaa180dc4ef686cb4003a50abc2a4fb0389 Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 2 Aug 2023 20:55:52 +0200 Subject: [PATCH] remind demo --- src/main.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/main.c b/src/main.c index 9256b96..d231adb 100644 --- a/src/main.c +++ b/src/main.c @@ -26,21 +26,22 @@ #include "utils.h" #include "config.h" +#include "api.h" -irc_session_t * session; +irc_session_t * session = NULL; irc_callbacks_t callbacks; char * get_username(const char * origin) { - const char USERNAME_TERMINATOR = '!'; - int i = 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; + return r; } void @@ -83,38 +84,50 @@ event_channel(irc_session_t * session, (void) channel; (void) message; - 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); } int init(void) { + if(api_init()) + { ERR(DB_ERROR, "Error initializing database."); } + memset(&callbacks, 0, sizeof(callbacks)); callbacks.event_connect = event_connect; callbacks.event_channel = event_channel; session = irc_create_session(&callbacks); if (!session) - { ERR(1, "Error creating IRC session"); } + { ERR(IRC_ERROR, "Error creating IRC session"); } irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME); - if (irc_run(session) != 0) - { ERR(1, "Error running IRC session\nNo net?"); } - return 0; + + return 0; +} + +void +rope(int r){ + if(session){ irc_destroy_session(session); } + api_rope(); + + exit(r); } int main(int argc, char ** argv) { - if(!init()) - { - while(1) - {} - irc_destroy_session(session); - return 0; - } - else + if(init()) { return 1; } + + if (irc_run(session) != 0) + { ERR(1, "Error running IRC session\nNo net?"); } + + rope(0); + return 0; }