xbot/mods/autojoin/autojoin.c

59 lines
1.0 KiB
C
Raw Normal View History

2024-02-13 07:22:10 +00:00
#define MY_DLL_EXPORTS 1
2024-02-17 08:21:22 +00:00
#include "module.h"
2015-04-08 18:56:32 +00:00
#include "irc.h"
#include "events.h"
#include <stdio.h>
#include <stdlib.h>
#include <libconfig.h>
2024-02-13 07:22:10 +00:00
MY_API void aj(struct irc_conn *bot, char *text)
2015-04-08 18:56:32 +00:00
{
// TODO:
// Config Parser API
int count, n;
config_t cfg, *cf;
const config_setting_t *autojoin;
const char *base;
const char *chan = NULL;
cf = &cfg;
config_init(cf);
if (!config_read_file(cf, "./xbot.cfg"))
{
printf("[xbot.cfg:%d] Configuration error: %s\n",
config_error_line(cf),
config_error_text(cf)
);
config_destroy(cf);
return;
}
autojoin = config_lookup(cf, "mods.mod_autojoin");
count = config_setting_length(autojoin);
for (n = 0; n < count; n++)
{
chan = config_setting_get_string_elem(autojoin, n);
2024-02-16 21:28:11 +00:00
irc_join(bot, chan);
2015-04-08 18:56:32 +00:00
}
config_destroy(cf);
}
2024-02-13 07:22:10 +00:00
MY_API void mod_init()
2015-04-08 18:56:32 +00:00
{
2024-02-17 08:21:22 +00:00
register_module("autojoin", "Aaron Blakely", "v0.2", "Autojoin module");
2015-04-08 18:56:32 +00:00
add_handler(IRC_CONNECTED, aj);
}
MY_API void mod_unload()
{
2024-02-17 08:21:22 +00:00
unregister_module("autojoin");
del_handler(IRC_CONNECTED, aj);
}