changes and uptime module
This commit is contained in:
parent
a484282df3
commit
e7f3aba195
3
Makefile
3
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)
|
@ -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);
|
||||
|
@ -13,6 +13,8 @@ struct irc_conn
|
||||
{
|
||||
FILE *srv_fd;
|
||||
|
||||
|
||||
|
||||
char nick[32];
|
||||
char *admin;
|
||||
char host[256];
|
||||
|
7
mods/hello/Makefile
Normal file
7
mods/hello/Makefile
Normal 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!"
|
@ -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);
|
BIN
mods/test.so
BIN
mods/test.so
Binary file not shown.
@ -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
7
mods/uptime/Makefile
Normal 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
26
mods/uptime/uptime.c
Normal 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);
|
||||
}
|
10
src/events.c
10
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);
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user