The $text argument is a string but lrange command works only with lists. So we need to split text before using lrange. But later we need to turn our text in string back, thats why we use join.
You'll actually find this kind of improper list-use all through the script. Also, in this special case, you could simply use $text directly, rather than converting it to a list, selecting the whole list, and then convert it back into a string.
You should also be aware, that the mass-(de)voice/op commands are flawed as they expect the server to accept 6 modes per line (3 is standard) without checking how many the server actually permits.
Further, this script uses a very insecure security model, which grants public access to the chanset tcl command through mere hostmask matching. This opens for the possibility of remote code vulnerability using the need-* channel settings.