added command line arguments

This commit is contained in:
Aaron Blakely 2024-03-08 04:14:06 -06:00
parent 48de9741d1
commit 71090d244b
3 changed files with 61 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#include "irc.h"
#include "events.h"
#include "module.h"
#include "channel.h"
#include "timers.h"
#include <stdio.h>
#include <stdlib.h>
@ -120,6 +121,9 @@ void lua_eval(struct irc_conn *bot, char *user, char *host, char *chan, const ch
{
int res;
if (!is_botadmin(user))
return;
block = 1;
printf("lua eval called with %s\n", text);
if (strstr(text, "!lua") != NULL)
@ -152,7 +156,12 @@ void lua_load_script(struct irc_conn *bot, char *user, char *host, char *chan, c
{
char *name;
char *script;
char *buf = (char *)malloc(sizeof(char *) * 500);
char *buf;
if (!is_botadmin(user))
return;
buf = (char *)malloc(sizeof(char *) * 500);
if (strstr(text, "!load") != NULL)
{
@ -267,7 +276,12 @@ void lua_unload_script(struct irc_conn *bot, char *user, char *host, char *chan,
int i;
char *name;
char *script;
char *buf = (char *)malloc(sizeof(char *) * 500);
char *buf;
if (!is_botadmin(user))
return;
buf = (char *)malloc(sizeof(char *) * 500);
if (strstr(text, "!unload") != NULL)
{

View File

@ -1,6 +1,9 @@
/*
* irc.c: IRC connection and parser
* xbot: Just another IRC bot
* xbot: an advanced IRC bot for *nix and Windows
*
* This file contains the functions for connecting to an IRC server, sending
* and receiving data, and parsing the data received from the server.
*
* Written by Aaron Blakely <aaron@ephasic.org>
**/

View File

@ -4,6 +4,8 @@
* Written by Aaron Blakely <aaron@ephasic.org>
**/
#define VERSION "0.1.0"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@ -29,14 +31,14 @@
static time_t trespond;
int main()
int main(int argc, char **argv)
{
int n;
fd_set rd;
struct irc_conn bot;
struct timeval tv;
struct timeval last_ping;
char conf[1024];
char *p;
int bytesRecv;
@ -59,8 +61,44 @@ int main()
init_events();
init_timers();
init_mods();
strlcpy(conf, "xbot.cfg", sizeof conf);
if (argc > 1)
{
if (argc == 2)
{
if (!strcmp(argv[1], "-v"))
{
printf("xbot version: %s\n", VERSION);
printf("Compiled on: %s %s\n\n", __DATE__, __TIME__);
printf("Written by Aaron Blakely <aaron@ephasic.org>\n");
printf("Licensed under the MIT License\n");
return 0;
}
else if (!strcmp(argv[1], "-h"))
{
printf("Usage: xbot [-v] [-h] [-c <config file>]\n");
return 0;
}
}
else if (argc == 3)
{
if (!strcmp(argv[1], "-c"))
{
free(bot.in);
free(bot.out);
bot.in = calloc(INBUF_SIZE, sizeof(char));
bot.out = calloc(OUTBUF_SIZE, sizeof(char));
strlcpy(conf, argv[2], sizeof conf);
}
}
}
// Read the config
bot = read_config(bot, "xbot.cfg");
bot = read_config(bot, conf);
// check if the db exists, if not, create it
#ifdef _WIN32