Or just use a timer.

join #chan | .timermodeme 1 1 mode #chan -o $me


We don't just write the scripts, we put them to the test! (ScriptBusters)