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 "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;
}