changes and uptime module

This commit is contained in:
Aaron Blakely 2015-04-18 10:51:15 -05:00
parent a484282df3
commit e7f3aba195
12 changed files with 64 additions and 13 deletions

View File

@ -21,8 +21,9 @@ main:
@echo "All Done!"
mods:
$(MAKE) -C mods/test
$(MAKE) -C mods/hello
$(MAKE) -C mods/autojoin
$(MAKE) -C mods/uptime
clean:
@rm -rf build $(EXEC)

View File

@ -15,6 +15,14 @@ struct handler
void **handlers;
};
struct event
{
char *type;
char *user;
char *chan;
char *text;
};
void init_events();
int add_handler(char *type, void *handler);
void del_handler(int num, char *type);

View File

@ -13,6 +13,8 @@ struct irc_conn
{
FILE *srv_fd;
char nick[32];
char *admin;
char host[256];

7
mods/hello/Makefile Normal file
View File

@ -0,0 +1,7 @@
CC=gcc
CFLAGS=-fPIC -I../../lib
OBJ=../hello.so
main:
$(CC) -shared -o $(OBJ) $(CFLAGS) ./hello.c
@echo "All Done!"

View File

@ -13,8 +13,7 @@ void hello(struct irc_conn *bot, char *user, char *chan, char *text)
if (!strcmp(text, buf))
{
irc_privmsg(bot, chan, "%i", HANDLER);
del_handler(HANDLER, PRIVMSG_CHAN);
irc_privmsg(bot, chan, "hi %s", user);
}
free(buf);

Binary file not shown.

View File

@ -1,7 +0,0 @@
CC=gcc
CFLAGS=-fPIC -I../../lib
OBJ=../test.so
main:
$(CC) -shared -o $(OBJ) $(CFLAGS) ./test.c
@echo "All Done!"

7
mods/uptime/Makefile Normal file
View File

@ -0,0 +1,7 @@
CC=gcc
CFLAGS=-fPIC -I../../lib
OBJ=../uptime.so
main:
$(CC) -shared -o $(OBJ) $(CFLAGS) ./uptime.c
@echo "All Done!"

26
mods/uptime/uptime.c Normal file
View File

@ -0,0 +1,26 @@
#include "irc.h"
#include "events.h"
#include "module.h"
#include <stdio.h>
#include <stdlib.h>
void up(struct irc_conn *bot, char *user, char *chan, char *text)
{
char buf[100];
FILE* file;
if (!strcmp(text, "!uptime"))
{
file = popen("uptime", "r");
fgets(buf, 100, file);
pclose(file);
irc_privmsg(bot, chan, "%s", buf);
}
}
void mod_init()
{
add_handler(PRIVMSG_CHAN, up);
}

View File

@ -135,12 +135,17 @@ void handle_self_privmsg(struct irc_conn *bot, char *user, char *text)
{
for (i = 0; i < privmsg_chan.count; i++)
{
irc_notice(bot, user, "handler[%i:%i]: %p", i, privmsg_chan.type, privmsg_chan.handlers[i]);
irc_notice(bot, user, "handler[%i:%s]: %p", i, privmsg_chan.type, privmsg_chan.handlers[i]);
}
for (i = 0; i < privmsg_self.count; i++)
{
irc_notice(bot, user, "handler[%i:%i]: %p", i, privmsg_self.type, privmsg_self.handlers[i]);
irc_notice(bot, user, "handler[%i:%s]: %p", i, privmsg_self.type, privmsg_self.handlers[i]);
}
for (i = 0; i < irc_connected.count; i++)
{
irc_notice(bot, user, "handler[%i:%s]: %p", i , irc_connected.type, irc_connected.handlers[i]);
}
}
}
@ -178,4 +183,5 @@ void free_events()
free(privmsg_self.handlers);
free(privmsg_chan.handlers);
free(chan_join.handlers);
free(irc_connected.handlers);
}

View File

@ -38,6 +38,7 @@ int main()
if (fgets(bot.in, sizeof bot.in, bot.srv_fd) == NULL)
{
eprint("xbot: remote host closed connection\n");
return 0;
}
irc_parse_raw(&bot, bot.in);

View File

@ -2,6 +2,7 @@
bot:
{
verbose = 1;
nick = "xbot";
user = "xbot";
admin = "Dark_Aaron";
@ -15,7 +16,7 @@ server:
mods:
{
autoload = ("autojoin");
autoload = ("autojoin", "hello", "uptime");
blacklist = ();
# config option for mods/autojoin.so