remind demo

This commit is contained in:
anon 2023-08-02 20:55:52 +02:00
parent 2a28930a50
commit 90b9baaa18

View File

@ -26,21 +26,22 @@
#include "utils.h" #include "utils.h"
#include "config.h" #include "config.h"
#include "api.h"
irc_session_t * session; irc_session_t * session = NULL;
irc_callbacks_t callbacks; irc_callbacks_t callbacks;
char * get_username(const char * origin) char * get_username(const char * origin)
{ {
const char USERNAME_TERMINATOR = '!'; const char USERNAME_TERMINATOR = '!';
int i = 0; int i = 0;
char * r; char * r;
while (origin[i] != USERNAME_TERMINATOR) while (origin[i] != USERNAME_TERMINATOR)
{ i++; } { i++; }
r = (char *) malloc(i + 1); r = (char *) malloc(i + 1);
strncpy(r, origin, i); strncpy(r, origin, i);
r[i] = '\00'; r[i] = '\00';
return r; return r;
} }
void void
@ -83,38 +84,50 @@ event_channel(irc_session_t * session,
(void) channel; (void) channel;
(void) message; (void) message;
char * swp = get_username(origin); if(!strcmp(message, "!remind")){
msg_wrapper("%s, you are a faggot for this opinion.", swp); msg_wrapper("%s", remind("#/g/chad"));
free(swp); }
//char * swp = get_username(origin);
//msg_wrapper("%s, you are a faggot for this opinion.", swp);
//free(swp);
} }
int int
init(void) init(void)
{ {
if(api_init())
{ ERR(DB_ERROR, "Error initializing database."); }
memset(&callbacks, 0, sizeof(callbacks)); memset(&callbacks, 0, sizeof(callbacks));
callbacks.event_connect = event_connect; callbacks.event_connect = event_connect;
callbacks.event_channel = event_channel; callbacks.event_channel = event_channel;
session = irc_create_session(&callbacks); session = irc_create_session(&callbacks);
if (!session) if (!session)
{ ERR(1, "Error creating IRC session"); } { ERR(IRC_ERROR, "Error creating IRC session"); }
irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME); 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 int
main(int argc, main(int argc,
char ** argv) char ** argv)
{ {
if(!init()) if(init())
{
while(1)
{}
irc_destroy_session(session);
return 0;
}
else
{ return 1; } { return 1; }
if (irc_run(session) != 0)
{ ERR(1, "Error running IRC session\nNo net?"); }
rope(0);
return 0;
} }