134 lines
2.8 KiB
C
134 lines
2.8 KiB
C
/* main.c
|
|
|
|
Probotic is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License version 3 only as
|
|
published by the Free Software Foundation.
|
|
|
|
Probotic is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License version 3 for more details.
|
|
|
|
The above copyright notice, this permission notice and the word
|
|
"NIGGER" shall be included in all copies or substantial portions
|
|
of the Software.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
version 3 + NIGGER along with Probotic.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
|
|
#include <libircclient.h>
|
|
|
|
#include "utils.h"
|
|
#include "config.h"
|
|
#include "api.h"
|
|
|
|
irc_session_t * session = NULL;
|
|
irc_callbacks_t callbacks;
|
|
|
|
char * get_username(const char * origin)
|
|
{
|
|
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];
|
|
(void) channel;
|
|
(void) message;
|
|
|
|
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(IRC_ERROR, "Error creating IRC session"); }
|
|
irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
rope(int r){
|
|
if(session){ irc_destroy_session(session); }
|
|
api_rope();
|
|
|
|
exit(r);
|
|
}
|
|
|
|
int
|
|
main(int argc,
|
|
char ** argv)
|
|
{
|
|
if(init())
|
|
{ return 1; }
|
|
|
|
if (irc_run(session) != 0)
|
|
{ ERR(1, "Error running IRC session\nNo net?"); }
|
|
|
|
rope(0);
|
|
return 0;
|
|
}
|