$iif(($2 isnum 1- $+ $lines(yodawg.txt)),$read(yodawg.txt,$2),$read(yodawg.txt))
can be
$iif($read(yodawg.txt,$2),$v1,$read(yodawg.txt))
- Never use $chan try to use # as it is faster and simpler.there are multiple situations where $chan should be used, like $chan(#).mode/topic/key/limit/ial, $chan(0), $chan(1) etc