From e7f3aba195af01ca62d4a3d1cc7797f2dfa91102 Mon Sep 17 00:00:00 2001 From: Aaron Blakely Date: Sat, 18 Apr 2015 10:51:15 -0500 Subject: [PATCH] changes and uptime module --- Makefile | 3 ++- lib/events.h | 8 ++++++++ lib/irc.h | 2 ++ mods/hello/Makefile | 7 +++++++ mods/{test/test.c => hello/hello.c} | 3 +-- mods/test.so | Bin 8222 -> 0 bytes mods/test/Makefile | 7 ------- mods/uptime/Makefile | 7 +++++++ mods/uptime/uptime.c | 26 ++++++++++++++++++++++++++ src/events.c | 10 ++++++++-- src/main.c | 1 + xbot.cfg | 3 ++- 12 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 mods/hello/Makefile rename mods/{test/test.c => hello/hello.c} (82%) delete mode 100755 mods/test.so delete mode 100644 mods/test/Makefile create mode 100644 mods/uptime/Makefile create mode 100644 mods/uptime/uptime.c 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 1633a329fb98c982cf3a8dd5ccef9051a99598fa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8222 zcmeHMTWnOv8J_iGdnw>Glv{w7BZO54HCqP)bwZu2?+0WIF*u?n=&;^h<3)RMcF$6S zk`~D%%GR;!^3W#ALwIQ-K`R9*t*Fw=A|gW7sB$kLw=c08QLPI~!$TvYs&T)6&iuRQ zjMr^dseNKrv;X|x{I{7iGw1Suv%9aS#^)1U{NiyzoKf!}VbyVLrD}kLMXRXC|0eN( zl&!6FEol98sRJ>EWeJdvI@I+Ik_9zngK0~RgPV%79RE2$iFOpu~dv|gCB3`F=)&OpQLD)x1zs(lwZONa>g5#xjpFXS*=TsWexUGU z8h&2ky8Ls%S5=wMM}e;t>%?JYhu0m&xC&SJ9xo{HRN7HjiDlxB+Se2ZmD8w%zpUhG zUSzSX$l2LwYE&e$Q47e)RPMNl#go=ZBppk}vtl?KkBd|$ zX2F*&BC%MxCz%+EhH{zEE@8!E5j%oNhH^P4IzZ`|=cA;*v5FR`bi#$$T+rNC{fztV_Uk7w%q1(=Ob-HD+8m`ye~B zE_@jQTvR-C8EI@>0xq2PIG08j&TEAF*1K@``E9sxwN#|3W*4rGLW#Gy@XtuZ`D=CI z?)c5|JAu+0kSTRw%a+rzx0wQ}T}yPeY$OFZu1n(~#$;B)^S#x+HUFB)^4t8v5KQc#7AY zsQrGx5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_N;cGw^D8k1t3&3-c`@ zX=ma7dPK^z)d~$u`Gt9s9);_9lKm2|=yNLy++fBf3Yh z5M_+4E)Tc2)72HrSjUr@p-9q_FIQG1KPK?vG@6Xt@mOfr&K(a6>aY^AG2(V0HAL@c zv3x3Ziv4u=cS$!r1MT~|E#}A#w<})co1FAw$8)xfRYq5q%w<%rNmyN9?Qh?=r&CzH zefvAw`>g#vJqNoFS%=y?`noMoR*Ldf;jlaN#Mv*-QpxvBcZy4;#W=_1B*eTnw9K26 eLeoSj +#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