If I'm following you correctly then the script probably just keeps a list of the channels for which it's currently waiting for a /who reply from. Then, each time it receives the relevant numerics it checks whether it's for a channel in it's list and if so changes the behaviour accordingly.