Compare commits
2 Commits
14baa2e696
...
edfed94214
Author | SHA1 | Date | |
---|---|---|---|
edfed94214 | |||
d4eb81d46d |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
**/*.out
|
||||
**/*.o
|
110
src/bot/main.c
Normal file
110
src/bot/main.c
Normal file
@ -0,0 +1,110 @@
|
||||
// @COMPILECMD gcc main.c -lircclient
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <libircclient/libircclient.h>
|
||||
|
||||
#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){
|
||||
const char USERNAME_TERMINATOR = '!';
|
||||
|
||||
int i = 0;
|
||||
while (origin[i] != USERNAME_TERMINATOR)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
char* 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()
|
||||
{
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
callbacks.event_connect = event_connect;
|
||||
callbacks.event_channel = event_channel;
|
||||
|
||||
session = irc_create_session(&callbacks);
|
||||
if (!session) {
|
||||
printf("Error creating IRC session\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
irc_connect(session, SERVER, PORT, 0, USERNAME, USERNAME, USERNAME);
|
||||
|
||||
if (irc_run(session) != 0) {
|
||||
printf("Error running IRC session\nNo net?");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc,
|
||||
char *argv[])
|
||||
{
|
||||
if(init()){ return 1; }
|
||||
|
||||
while(1){}
|
||||
|
||||
irc_destroy_session(session);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user