Code:
alias -l _msg {
  inc %_msg_n
  if ($me ison $2) && ($isfile($3-)) && ($lines($3-) <= %_msg_n) { msg $2 $read($3-,n,%_msg_n) }
  else { .timermsg $+ $1 $+ $2 off }
}
on *:text:!add ?*:#:{ write messages.txt $2- }
on *:text:!enable:#:{ .timermsg $+ $cid $+ $chan 0 900 _msg $cid $chan messages.txt }