added modlist command

This commit is contained in:
Aaron Blakely 2024-02-17 02:21:22 -06:00
parent eec33fc573
commit 18c6732f66
8 changed files with 91 additions and 8 deletions

View File

@ -18,5 +18,6 @@ These are commands which allow the bot's admin to control it once it's connected
* LOADMOD <module> * LOADMOD <module>
* UNLOADMOD <module> * UNLOADMOD <module>
* MODLIST
* JOIN <channel> * JOIN <channel>

View File

@ -9,12 +9,12 @@
#endif #endif
struct module { struct module {
char *name; char name[25];
char *author; char author[50];
char *version; char version[10];
char *description; char description[256];
char *fname; char fname[256];
#ifdef _WIN32 #ifdef _WIN32
HMODULE handle; HMODULE handle;
@ -35,5 +35,9 @@ struct mods {
void init_mods(); void init_mods();
void load_module(struct irc_conn *bot, char *where, char *stype, char *file); void load_module(struct irc_conn *bot, char *where, char *stype, char *file);
void unload_module(struct irc_conn *bot, char *where, char *file); void unload_module(struct irc_conn *bot, char *where, char *file);
void list_modules(struct irc_conn *bot, char *where);
MY_API void register_module(char *name, char *author, char *version, char *description);
MY_API void unregister_module(char *name);
MY_API struct mods *get_mods();
#endif #endif

View File

@ -1,5 +1,6 @@
#define MY_DLL_EXPORTS 1 #define MY_DLL_EXPORTS 1
#include "module.h"
#include "irc.h" #include "irc.h"
#include "events.h" #include "events.h"
#include <stdio.h> #include <stdio.h>
@ -46,10 +47,12 @@ MY_API void aj(struct irc_conn *bot, char *text)
MY_API void mod_init() MY_API void mod_init()
{ {
register_module("autojoin", "Aaron Blakely", "v0.2", "Autojoin module");
add_handler(IRC_CONNECTED, aj); add_handler(IRC_CONNECTED, aj);
} }
MY_API void mod_unload() MY_API void mod_unload()
{ {
unregister_module("autojoin");
del_handler(IRC_CONNECTED, aj); del_handler(IRC_CONNECTED, aj);
} }

View File

@ -4,5 +4,5 @@ for %%F in ("%filename%") do (
set "basename=%%~nF" set "basename=%%~nF"
) )
cl /I..\lib /I..\include\libconfig-1.7.3\lib /LD /EHsc ..\include\xbot.lib ..\include\libconfig.lib %filename% cl /I..\lib /I..\include\libconfig-1.7.3\lib /LD /EHsc ..\Debug\xbot.lib ..\include\libconfig.lib %filename%
link /DLL /out:.\%basename%.dll %basename%.obj ..\include\xbot.lib ..\include\libconfig.lib link /DLL /out:.\%basename%.dll %basename%.obj ..\Debug\xbot.lib ..\include\libconfig.lib

View File

@ -31,12 +31,14 @@ MY_API void hello_join(struct irc_conn *bot, char *user, char *host, char *chan)
MY_API void mod_init() MY_API void mod_init()
{ {
register_module("hello", "Aaron Blakely", "v0.05", "Test module");
add_handler(PRIVMSG_CHAN, hello); add_handler(PRIVMSG_CHAN, hello);
add_handler(JOIN, hello_join); add_handler(JOIN, hello_join);
} }
MY_API void mod_unload() MY_API void mod_unload()
{ {
unregister_module("hello");
del_handler(PRIVMSG_CHAN, hello); del_handler(PRIVMSG_CHAN, hello);
del_handler(JOIN, hello_join); del_handler(JOIN, hello_join);
} }

View File

@ -25,12 +25,14 @@ MY_API void up(struct irc_conn *bot, char *user, char *host, char *chan, char *t
MY_API void mod_init() MY_API void mod_init()
{ {
register_module("uptime", "Aaron Blakely", "v0.1", "Uptime module");
printf("installing up handler\n"); printf("installing up handler\n");
add_handler(PRIVMSG_CHAN, up); add_handler(PRIVMSG_CHAN, up);
} }
MY_API void mod_unload() MY_API void mod_unload()
{ {
unregister_module("uptime");
printf("unloading up handler\n"); printf("unloading up handler\n");
del_handler(PRIVMSG_CHAN, up); del_handler(PRIVMSG_CHAN, up);
} }

View File

@ -190,6 +190,19 @@ void fire_handler(struct irc_conn *bot, char *type, ...)
irc_notice(bot, usr, "You are unauthorized to use this command."); irc_notice(bot, usr, "You are unauthorized to use this command.");
} }
} }
else if (!strcmp("MODLIST", cmd))
{
if (!strcmp(bot->admin, usr))
{
list_modules(bot, usr);
}
else
{
irc_notice(bot, usr, "You are unauthorized to use this command.");
}
}
va_end(args);
} }
for (i = 0; i < handlers_count; i++) for (i = 0; i < handlers_count; i++)

View File

@ -24,7 +24,7 @@ void init_mods()
void load_module(struct irc_conn *bot, char *where, char *stype, char *file) void load_module(struct irc_conn *bot, char *where, char *stype, char *file)
{ {
char *error = (char *)malloc(sizeof(char *)*1024); char *error = (char *)malloc(sizeof(char *)*1024);
mods->modules[mods->count].fname = file; strlcpy(mods->modules[mods->count].fname, file, 256);
#ifdef _WIN32 #ifdef _WIN32
mods->modules[mods->count].handle = LoadLibrary(file); mods->modules[mods->count].handle = LoadLibrary(file);
@ -236,7 +236,65 @@ void unload_module(struct irc_conn *bot, char *where, char *file)
printf("Module '%s' unloaded.\n", file); printf("Module '%s' unloaded.\n", file);
} }
while (i < mods->count)
{
mods->modules[i] = mods->modules[i+1];
i++;
}
return; return;
} }
} }
} }
void list_modules(struct irc_conn *bot, char *where)
{
int i;
char *msg = malloc(512);
char *tmp = malloc(512);
for (i = 0; i < mods->count; i++)
{
sprintf(tmp, "%s (%s) by %s - %s", mods->modules[i].name, mods->modules[i].version, mods->modules[i].author, mods->modules[i].description);
irc_notice(bot, where, tmp);
}
free(msg);
free(tmp);
}
MY_API void register_module(char *name, char *author, char *version, char *description)
{
if (mods->count >= 512)
{
eprint("Error: Too many modules loaded.\n");
return;
}
strlcpy(mods->modules[mods->count].name, name, 25);
strlcpy(mods->modules[mods->count].author, author, 50);
strlcpy(mods->modules[mods->count].version, version, 10);
strlcpy(mods->modules[mods->count].description, description, 256);
}
MY_API void unregister_module(char *name)
{
int i;
for (i = 0; i < mods->count; i++)
{
if (strcmp(mods->modules[i].fname, name) == 0)
{
while (i < mods->count)
{
mods->modules[i] = mods->modules[i+1];
i++;
}
return;
}
}
}
MY_API struct mods *get_mods()
{
return mods;
}