This is a tad boring to assign a nickname with a random colour. It'd be interesting to have different colours at random every time someone sends a message. This is just my two bits worth. Last but not least, though, this only works for $chan.
Incidentally, you can use an alias for the routine and have the text and action call from it. This saves you a repeated routine.