diff --git a/Makefile b/Makefile index 80e61b5..94314bf 100644 --- a/Makefile +++ b/Makefile @@ -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) \ No newline at end of file diff --git a/lib/events.h b/lib/events.h index 5afc4be..bc42f5f 100644 --- a/lib/events.h +++ b/lib/events.h @@ -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); diff --git a/lib/irc.h b/lib/irc.h index 9c40825..dadda5a 100644 --- a/lib/irc.h +++ b/lib/irc.h @@ -13,6 +13,8 @@ struct irc_conn { FILE *srv_fd; + + char nick[32]; char *admin; char host[256]; diff --git a/mods/hello/Makefile b/mods/hello/Makefile new file mode 100644 index 0000000..95864d1 --- /dev/null +++ b/mods/hello/Makefile @@ -0,0 +1,7 @@ +CC=gcc +CFLAGS=-fPIC -I../../lib +OBJ=../hello.so + +main: + $(CC) -shared -o $(OBJ) $(CFLAGS) ./hello.c + @echo "All Done!" \ No newline at end of file diff --git a/mods/test/test.c b/mods/hello/hello.c similarity index 82% rename from mods/test/test.c rename to mods/hello/hello.c index 617572f..b19fb83 100644 --- a/mods/test/test.c +++ b/mods/hello/hello.c @@ -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); diff --git a/mods/test.so b/mods/test.so deleted file mode 100755 index 1633a32..0000000 Binary files a/mods/test.so and /dev/null differ diff --git a/mods/test/Makefile b/mods/test/Makefile deleted file mode 100644 index 3df7c81..0000000 --- a/mods/test/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -CC=gcc -CFLAGS=-fPIC -I../../lib -OBJ=../test.so - -main: - $(CC) -shared -o $(OBJ) $(CFLAGS) ./test.c - @echo "All Done!" \ No newline at end of file diff --git a/mods/uptime/Makefile b/mods/uptime/Makefile new file mode 100644 index 0000000..3f848a6 --- /dev/null +++ b/mods/uptime/Makefile @@ -0,0 +1,7 @@ +CC=gcc +CFLAGS=-fPIC -I../../lib +OBJ=../uptime.so + +main: + $(CC) -shared -o $(OBJ) $(CFLAGS) ./uptime.c + @echo "All Done!" \ No newline at end of file diff --git a/mods/uptime/uptime.c b/mods/uptime/uptime.c new file mode 100644 index 0000000..02b9749 --- /dev/null +++ b/mods/uptime/uptime.c @@ -0,0 +1,26 @@ +#include "irc.h" +#include "events.h" +#include "module.h" +#include +#include + +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); +} \ No newline at end of file diff --git a/src/events.c b/src/events.c index 7d27747..7948287 100644 --- a/src/events.c +++ b/src/events.c @@ -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); } \ No newline at end of file diff --git a/src/main.c b/src/main.c index ee3eb47..af12ee1 100644 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/xbot.cfg b/xbot.cfg index d79f026..611764a 100644 --- a/xbot.cfg +++ b/xbot.cfg @@ -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