@d.s=[dict.org]

### dict, telnet, and ftp clients.

### dict
alias dict {if ([$*]) {
  @ d.w = [$*]
  @ d.f = pattern(-% $d.w)
  fe ($d.f) qq {@ d.w = remw($qq $d.w)}
  @ d.f = strip(- $d.f)
  @ d.d = d.f =~ [*d*] ? word(0 $d.w) : [*]
  @ d.w = remw($d.d $d.w)
  @ dfd = opensocket($d.s 2628)
  timer 10 unless (_dict.connected) {
    ^on ^clone_read -"$dfd 2628 $d.s *"
    ge connection to $d.s timed out.} else {
    @_dict.connected=0}
  ^on ^clone_read "$dfd 2628 $d.s *" {
    @_dict.connected=1
    switch ($3) {
    (220) {@writesocket($dfd ${d.f=~[*l*]?[show db]:[define $d.d $d.w})}
    (552) {ge no match for your query.;@writesocket($dfd quit)}
    (150) {ge $4 definition${[$4]!=1?[s]:} retrieved.}
    (151) {${d.f=~[*o*]?[say]:[ge]} from $6-;@ae=1}
    (250) {@writesocket($dfd quit)}
    (110) {${d.f=~[*o*]?[say]:[ge]} $4-;@ae=1}
    (550) {ge $d.d is an invalid database. try /dict -l for a list.;@writesocket($dfd quit)}
    (221) {@closesocket($dfd);^on ^clone_read -"$dfd 2628 $d.s *"}
    (.) {@ae=0}
    (*) {if (ae) {${d.f=~[*o*]?[say]:[ge]} $3-}}}}} else {
  ausage dict}}

alias matchftp1 {
  if (fexist(~/.ncftp/bookmarks)==1) {
    ^local ffd $open(~/.ncftp/bookmarks R)
    while (!eof($ffd)&!function_return) {
      ^local fr $read($ffd)
      if (before(, $fr)==[$0]) {@function_return=[$after(, $before(2 , $fr))]}}
    @close($ffd)}}      
alias matchftp2 {
  if (fexist(~/.ncftp/bookmarks)==1) {
    ^local ffd $open(~/.ncftp/bookmarks R)
    while (!eof($ffd)&!function_return) {
      ^local fr $read($ffd)
      if (after(, $before(2 , $fr))==[$0]) {@function_return=[\/$before(, $after(/ $fr))]}}
    @close($ffd)}}

alias ftp {
  if ([$0]) {
    if ([$0]!=[-n]) {
      @ f.s = [$0] =~ [*.*] ? [$0] : matchftp1($0)
      @ f.d = pattern(/% $*) ? pattern(/% $*) : matchftp2($f.s)
      @ f.d = f.d ? f.d : [/]
      @ f.r = [$1-]} else {
      @ f.s = after(@ $_userhost($1))
      @ f.d = [/]
      @ f.r = [$2-]}
      if (f.s) {
        addtab /m -$f.s
        wait for dcc ftp $f.s $filter(/% $f.r)
        timer 1 msg -$f.s cd $f.d} else {
        ge \"$1\" is not on irc.}} else {
    ausage ftp}}

