Indeed there are shorter ways of doing that code, here's one.
Code:
on @*:text:!voice*:#: mode $chan +v $iif($$2 ison $chan,$v1,$nick)