super3 / IRC-Bot

A very little basic IRCBot that will get improved over the next time.
http://www.wildphp.com
102 stars 47 forks source link

Now allow an array to be set for $numberOfArguments #54

Closed NanoSector closed 9 years ago

NanoSector commented 9 years ago

[ETA: Sorry, my title got cut off by my shell; it interpreted $numberOfArguments as a variable] On the built-in commands this isn't applicable. But consider this: My bot has an !issue command. If !issue is passed without parameters, it will return the last 5 issues posted on GitHub. If !issue has 1 parameter, it will return info about a specific issue.

Now, before this patch, $numberOfArguments was required to be set to -1. This allows multiple arguments to be passed, while it will only process one.

With this patch, I can simply set it to array(0, 1) and it'll take either 0 or 1 argument(s), and errors out on anything else. -1 can still be passed in the array and it behaves differently after this patch. Before: -1 would include 0 arguments as correct. After: -1 will now work if amount of arguments > 0 This is done to avoid possible issues that could arise from passing no arguments to a command that won't work without arguments. To allow both 0 and any amount of arguments, pass array(0, -1).

This patch also includes a safeguard that will block commands that do not have the $numberOfArguments set from running, again to prevent issues which can arise by an incorrect amount of arguments.

Do note that I left the "For help, use !help [command name]" in here. If you want to remove it, go ahead. Signed-off-by: Yoshi2889 rick.2889@gmail.com

NanoSector commented 9 years ago

Closing and recreating.