For starters you might wanna post this in forums as opposed to a snippet, but heres a few solutions you might try.
Instead of all "if" statements change all but one to "elseif" reason being is that you could have op, halfop, and voice at the same time, echoing it 3 times on your end instead of once. (Can refine this method to function in one alias, but that is by far more complicated than changing a few statements)