This should work fine, note that some of the raws below are only sent to irc operators. Also, some ircd's may send results in a slightly different format, and may have some extended raws sent on whois.
Code:
on *:TEXT:.whois *:#: {
  if ($2) {
    set $+(%,whois.,$2) $chan
    msg $chan 'Processing whois'
    .whois $2 $2
  }
}
raw 311:*: if ($+(%,whois.,$2)) msg $($+(%,whois.,$2),2) $2- | halt
raw 307:*: if ($+(%,whois.,$2)) msg $($+(%,whois.,$2),2) $2- | halt
raw 615:*: if ($+(%,whois.,$2)) msg $($+(%,whois.,$2),2) $2- | halt
raw 616:*: if ($+(%,whois.,$2)) msg $($+(%,whois.,$2),2) $2- | halt
raw 319:*: if ($+(%,whois.,$2)) msg $($+(%,whois.,$2),2) $2- | halt
raw 312:*: if ($+(%,whois.,$2)) msg $($+(%,whois.,$2),2) $2- | halt
raw 313:*: if ($+(%,whois.,$2)) msg $($+(%,whois.,$2),2) $2- | halt
raw 317:*: if ($+(%,whois.,$2)) msg $($+(%,whois.,$2),2) $2 has been idle $duration($3,1) $+ , signed on $asctime($3,ddd mmm dd hh:nn:ss) | halt
raw 318:*: if ($+(%,whois.,$2)) msg $($+(%,whois.,$2),2) 'End of WHOIS' | unset $+(%whois.,$2) | halt