The code works very simple. (For Pokemon Diamond/Pearl)
The syntax is !addfc #### #### ####
The code will check if the friend code is 4 digits spaced out, and if not, it'll reply with an error message. If the friend code is in correct syntax (Not knowing if possible for the Nintendo database to add, just checks the normal standards of the codes), then it'll write a line in the database. Only you as the owner can access the database to ensure privacy.
on *:TEXT:!addfc *:*: {
if ($len($2) == 4) && ($2 isnum) && ($len($3) == 4) && ($3 isnum) && ($len($4) == 4) && ($4 isnum) {
write fc.txt $nick : The FC for him or her is : $2-5
notice $nick You have successfully added your friend code to the database.
}
else {
notice $nick Invalid friend code. To let my owner add your friend code, please say !addfc friendcode . Replace friendcodehere with your 12 digit friend code with spaces every 4 numbers. }
}
Two things I noticed right off, one is you use $2-5 instead of $2-4 which would allow extra data in since you never check if (!$5).
The second thing is..
if ($len($2) == 4) && ($2 isnum) && ($len($3) == 4) && ($3 isnum) && ($len($4) == 4) && ($4 isnum) {
Could be changed to
if ($len($remove($2-4,$chr(32))) == 12) && ($remove($2-4,$chr(32)) isnum) {
I know its not a lot shorter but it does give you a great example of creative thinking to bring down the amount of ifs you need.
You should also consider checking the input against the file to make sure it doesnt already exist to avoid someone adding the same number a thousand times.
The code in general is a very simple one, almost too much so.
Keep up the coding. :)