Note: This code probably won't be able to cover and correctly recognize all possible input data variants, so I would recommend splitting the functionality into several aliases, creating several commands: /addnick and /addhost. In the first case, the mask check will be performed based on the nick, and in the second case, based on the host/IP address.
I can't split it because this small piece of code will be implemented in another dialog box, so I can't differentiate one command from another in the dialog box's edit box.