Code:
on !*:JOIN:#chan: {
  var %a = $gettok($mask($fulladdress,3),2,33)
  if ($read(nicks.txt,w,$+(%a,!*))) return
  write nicks.txt $+(%a,!)
  msg $nick MOTD goes here
}