Skip to content
Snippets Groups Projects
Commit 2b78c14c authored by mcmlxxix's avatar mcmlxxix
Browse files

fixed help command. bot will not longer process server commands for disabled...

fixed help command. bot will not longer process server commands for disabled modules. a few minor fixes
parent 3f18ad34
No related branches found
No related tags found
No related merge requests found
......@@ -51,12 +51,14 @@ Bot_Commands["JOINCHAN"].command = function (target,onick,ouh,srv,lvl,cmd) {
srv.o(target,"Invalid channel name","NOTICE");
return;
}
var chan=cmd[0].toUpperCase();
var chan=cmd.shift().toUpperCase();
var key=cmd.shift();
if(srv.channel[chan]) {
srv.o(target,"I am already in that channel","NOTICE");
return;
}
srv.channel[chan]=new Bot_IRC_Channel(chan);
srv.channel[chan]=new Bot_IRC_Channel(chan,key);
srv.writeout("WHO " + chan);
srv.o(target,"Ok.","NOTICE");
return;
......@@ -108,7 +110,6 @@ Bot_Commands["HELP"].usage =
Bot_Commands["HELP"].help =
"Displays helpful information about bot commands.";
Bot_Commands["HELP"].command = function (target,onick,ouh,srv,lvl,cmd) {
cmd.shift();
function help_out(bot_cmd) {
if(bot_cmd) {
if(bot_cmd.usage) srv.o(onick,format("Usage: " + bot_cmd.usage,srv.curnick),"NOTICE");
......@@ -127,27 +128,48 @@ Bot_Commands["HELP"].command = function (target,onick,ouh,srv,lvl,cmd) {
srv.o(onick,"[" + name + "] " + cmdstr.substr(1).toLowerCase(),"NOTICE");
}
var hlp_main=cmd.shift();
var hlp_main=cmd[1];
/* if no module or command was specified, list all commands, and general command usage */
if(!hlp_main) {
srv.o(target,"Usage: HELP <module> <command> | HELP <command>","NOTICE");
srv.o(onick,"Usage: HELP <module> <command> | HELP <command>","NOTICE");
list_out(Bot_Commands,"main");
for(var m in Modules) {
list_out(Modules[m].Bot_Commands,m.toLowerCase());
}
/* if there is a module matching the first command parameter
display help information for that module */
} else if(Modules[hlp_main.toUpperCase()]) {
var module=Modules[hlp_main.toUpperCase()];
var hlp_cmd=cmd[0];
var hlp_cmd=cmd[2];
/* if a command was specified, list that command's help info */
if(hlp_cmd) {
if(module.Bot_Commands.HELP) {
module.Bot_Commands.HELP.command(target,onick,ouh,srv,lvl,cmd);
} else {
help_out(module.Bot_Commands[help_cmd.toUpperCase()]);
}
/* if no command was specified, list module's commands */
} else {
list_out(module.Bot_Commands,hlp_main.toLowerCase());
}
} else {
help_out(Bot_Commands[hlp_main.toUpperCase()])
/* if there is help information for the command specified show it */
if(Bot_Commands[hlp_main.toUpperCase()])
help_out(Bot_Commands[hlp_main.toUpperCase()]);
/* otherwise if this is not a private message, check the current channel's
ACTIVE modules for a command that matches */
else if(target != onick) {
var chan=srv.channel[target.toUpperCase()];
for(var m in chan.modules) {
var module=Modules[m];
if(module.Bot_Commands.HELP)
module.Bot_Commands.HELP.command(target,onick,ouh,srv,lvl,cmd);
else if(module.Bot_Commands[hlp_main.toUpperCase()])
help_out(module.Bot_Commands[hlp_main.toUpperCase()]);
}
}
}
return;
}
......@@ -550,7 +572,7 @@ Server_Commands["QUIT"]=Server_Commands["KICK"]=Server_Commands["PART"];
Server_Commands["PRIVMSG"] = function (srv,cmd,onick,ouh) {
if(srv.users[onick.toUpperCase()]) srv.users[onick.toUpperCase()].last_spoke=time();
if (cmd[0][0] == "#" || cmd[0][0] == "&") {
var chan=get_privmsg_channel(srv,cmd);
var chan=srv.channel[cmd[0].toUpperCase()];
if(!chan) return;
if (srv.pipe && srv.pipe[chan.name.toUpperCase()]) {
......@@ -560,6 +582,8 @@ Server_Commands["PRIVMSG"] = function (srv,cmd,onick,ouh) {
}
cmd=parse_cmd_prefix(cmd);
if(!cmd) return false;
/* check main bot commands */
srv.bot_command(srv,Bot_Commands,chan.name,onick,ouh,cmd.join(" "));
......
......@@ -19,11 +19,14 @@
/* Server methods */
function Server_command(srv,cmdline,onick,ouh) {
var cmd=IRC_parsecommand(cmdline);
var chan=get_command_channel(srv,cmd);
var main_cmd=cmd.shift();
if(Server_Commands[main_cmd]) Server_Commands[main_cmd](srv,cmd,onick,ouh);
for(var m in Modules) {
var module=Modules[m];
if(chan && chan.modules[m] != true) {
continue;
}
if(module
&& module.enabled
&& module.Server_Commands[main_cmd]) {
......@@ -74,7 +77,7 @@ function Server_CTCP(onick,ouh,cmd) {
break;
case "VERSION":
this.ctcp_reply(onick, "VERSION "
+ "Synchronet IRC Bot by Randy E. Sommerfeld <cyan@rrx.ca>");
+ "Synchronet IRC Bot by Randy E. Sommerfeld <cyan@rrx.ca>, Module system by Matt D. Johnson <mdj1979@gmail.com>");
break;
case "FINGER":
this.ctcp_reply(onick, "FINGER "
......@@ -232,19 +235,30 @@ function save_everything() { // save user data, and call save() method for all e
return true;
}
function get_privmsg_channel(srv,cmd) {
var chan_str = cmd[0].toUpperCase();
function get_command_channel(srv,cmd) {
switch(cmd[0]) {
case "PRIVMSG":
break;
case "PART":
case "QUIT":
case "KICK":
case "JOIN":
if (cmd[1][0] == ":")
cmd[1] = cmd[1].substr(1);
break;
default:
return false;
}
var chan_str = cmd[1].toUpperCase();
var chan = srv.channel[chan_str];
if (!chan)
return false;
if (!chan.is_joined)
return false;
return chan;
}
function parse_cmd_prefix(cmd) {
cmd[1] = cmd[1].substr(1).toUpperCase();
if ((cmd[1].toUpperCase() == truncsp(get_cmd_prefix()))
if ((cmd[1] == truncsp(get_cmd_prefix()))
&& cmd[2]) {
cmd.shift();
cmd.shift();
......@@ -253,6 +267,8 @@ function parse_cmd_prefix(cmd) {
cmd[0] = cmd[0].substr(1);
} else if(get_cmd_prefix()=="") {
cmd.shift();
} else {
return false;
}
cmd[0] = cmd[0].toUpperCase();
return cmd;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment