nice work but you could just use
if ($nick(#,$nick,~&%)) {
to check if the nick is owner, admin, or halfop