nI-Dict — File Browser

nI-Dictv3.0.1 / nI-Dictv3.0.1 / ni-dict.mrc

ni-dict.mrc — 15.79 KB — Download this file

; nI-Dict.mrc v3.0.1 :: ZeroSyrge(zerosrg@horiz0n.com)
; http://www.horiz0n.com/ni/
;
; Installation: /load -rs ni-dict.mrc
;
; Usage: /dict WORD(s)
;             /spell WORD(s)
;             /thes WORD(s)
;
; Public Triggers: !define
;                           !spell
;                           !thes
;
; NOTE:
; This should be considered a beta version due to
; known problems in the thesaurus portion of the script.
; The script will not crash or anything, but you may
; get odd results at times using the thesaurus.
; Aside from that, everything works fine... Enjoy.
;



alias dict {
  if $1 == $null { echo $color(info) -se * Usage: /dict WORD }
  else {
    if (%dict.server == $null) { set %dict.server dict.org }
    if $sock(dict) != $null { sockclose dict }
    if $sock(thes) != $null { sockclose thes }
    set %dict.org.var d
    set %dict.org.dvar 7
    set %dict.org.word $1-
    sockopen dict %dict.server 2628
    if $dialog(d.dict) != $null { goto next }
    else {
      dialog -mv d.dict d.dict
      goto next
    }
    :next
    dialog -v d.dict
    did -v d.dict 7
    did -h d.dict 5
    did -ac d.dict 3 %dict.org.word
    did -r d.dict 7
    did -r d.dict 5
  }
}

alias dictpub {
  if $sock(dict) != $null { sockclose dict }
  if $sock(thes) != $null { sockclose thes }
  if (%dict.server == $null) { set %dict.server dict.org }
  set %dict.org.var d
  set %dict.org.word $1-
  set %dict-file $+(",$scriptdir,dictpub-,$replace($1-,$chr(32),_),.ni,")
  sockopen pubdict %dict.server 2628
  .disable #ni-dict-pub
}

alias spell {
  if $1- == $null { echo $color(info) -se * Usage: /spell WORD }
  else {
    if $sock(dict) != $null { sockclose dict }
    if $sock(thes) != $null { sockclose thes }
    if (%dict.server == $null) { set %dict.server dict.org }
    set %dict.org.var m
    set %dict.org.dvar 5
    if %dict.spellmethod != $null { set %dict.org.var m %dict.spellmethod }
    set %dict.org.word $1-
    sockopen dict %dict.server 2628
    if $dialog(d.dict) != $null { goto next }
    else {
      dialog -mv d.dict d.dict
      goto next
    }
    :next
    dialog -v d.dict
    did -v d.dict 5
    did -h d.dict 7
    did -ac d.dict 3 %dict.org.word
    did -r d.dict 5
    did -r d.dict 7
  }
}

alias spellpub {
  if $sock(dict) != $null { sockclose dict }
  if $sock(thes) != $null { sockclose thes }
  if (%dict.server == $null) { set %dict.server dict.org }
  set %dict.org.var m
  if %dict.spellmethod != $null { set %dict.org.var m %dict.spellmethod }
  set %dict.org.word $1-
  set %dict-file $+(",$scriptdir,dictpub-,$replace($1-,$chr(32),_),.ni,")
  sockopen pubdict %dict.server 2628
  .disable #ni-dict-pub
}

alias dictmenu {
  if $1 == $null { echo $color(info) -s * Usage: /dictmenu ON/OFF }
  elseif $1 == on {
    echo $color(info) -s * [nI:Dict] Popups Enabled
    .enable #ni-dict-menu
  }
  elseif $1 == off {
    echo $color(info) -s * [nI:Dict] Popups Disabled
    .disable #ni-dict-menu
  }
  else { echo $color(info) -s * Usage: /dictmenu ON/OFF }
}

alias dicttrigger {
  if $1 == $null { echo $color(info) -s * Usage: /dicttrigger ON/OFF }
  elseif $1 == on {
    echo $color(info) -s * [nI:Dict] Public Triggers Enabled
    .enable #ni-dict-pub
  }
  elseif $1 == off {
    echo $color(info) -s * [nI:Dict] Public Triggers Disabled
    .disable #ni-dict-pub
  }
  else { echo $color(info) -s * Usage: /dicttrigger ON/OFF }
}

on 1:LOAD:{
  echo $color(info) -s ** [nI] Dictionary/SpellChecker v3.0.1 [LOADED]
  echo $color(info) -s ** Usage:
  echo $color(info) -s ** /dict <WORD>
  echo $color(info) -s ** /spell <WORD>
  echo $color(info) -s ** /thes <WORD>
  echo $color(info) -s ** Popups are available in Status and Channels.
  set %dict.server dict.org
  .enable #ni-dict-pub
  .enable #ni-dict-menu
}
on 1:UNLOAD:{
  echo $color(info) -s ** [nI] Dictionary/SpellChecker v3.0.1 [UNLOADED]
}
on *:sockopen:dict:{
  sockwrite -n $sockname %dict.org.var " $+ %dict.org.word $+ "
  sockwrite -n $sockname quit
}
on *:sockread:dict:{
  if ($sockerr > 0) return
  :nextread
  sockread %dict.org.temp
  if ($sockbr == 0) return
  if (%dict.org.temp == $null) { return }
  if $gettok(%dict.org.temp,1,32) == 220 || $gettok(%dict.org.temp,1,32) == 151 || $gettok(%dict.org.temp,1,32) == 250 {
    return
  }
  if %dict.org.temp == $chr(46) {
    did -a d.dict %dict.org.dvar $replace(%dict.org.temp, $chr(46), $str($chr(45),25)) $iif(%dict.org.dvar == 7,$crlf,$null)
    return
  }
  if $gettok(%dict.org.temp,1,32) == 552 {
    if %dict.org.var == d {
      did -a d.dict %dict.org.dvar [DICT] ERROR :: no match for %dict.org.word $iif(%dict.org.dvar == 7,$crlf,$null)
      if (%dict.autospell == $null) || (%dict.autospell == on) {
        .timer 1 3 spell %dict.org.word
        did -a d.dict %dict.org.dvar Checking Spelling . . . $iif(%dict.org.dvar == 7,$crlf,$null)
      }
    }
    if $left(%dict.org.var,1) == m {
      did -a d.dict %dict.org.dvar [SPELL] ERROR :: no match for %dict.org.word $iif(%dict.org.dvar == 7,$crlf,$null)
    }
    return
  }
  if $gettok(%dict.org.temp,1,32) == 150 {
    did -a d.dict %dict.org.dvar $upper($gettok(%dict.org.temp,2-,32)) $iif(%dict.org.dvar == 7,$crlf,$null)
    did -a d.dict %dict.org.dvar $str($chr(45),50) $iif(%dict.org.dvar == 7,$crlf,$null)
    return
  }
  if $gettok(%dict.org.temp,1,32) == 221 {
    return
  }
  if $left(%dict.org.var,1) == m {
    if $gettok(%dict.org.temp,1,32) == 152 {
      did -a d.dict %dict.org.dvar $upper($gettok(%dict.org.temp,2-,32)) $iif(%dict.org.dvar == 7,$crlf,$null)
      did -a d.dict %dict.org.dvar $str($chr(45),50) $iif(%dict.org.dvar == 7,$crlf,$null)
      return
    }
    did -a d.dict %dict.org.dvar $remtok($gettok(%dict.org.temp,2-,32),1-,34) $iif(%dict.org.dvar == 7,$crlf,$null)
    goto nextread
  }
  did -a d.dict %dict.org.dvar %dict.org.temp $iif(%dict.org.dvar == 7,$crlf,$null)
  goto nextread
}

dialog d.dict {
  title "[nI] Dictionary v3.0.1"
  icon $scriptdir $+ dict.ico
  size -1 -1 260 125
  option -dbu
  box "Dictionary v3.0.1", 1, 5 1 205 120
  combo 3, 10 10 73 11, edit, drop
  list 5, 10 22 195 104, vsbar, extsel
  edit "", 7, 10 22 195 94, multi, return, vsbar
  button "CLOSE", 15, 175 10 30 11, cancel
  button "Define", 17, 85 10 30 11, default
  button "Spell" 19, 115 10 30 11
  button "Thesaurus" 47, 145 10 30 11
  box "Spell Method", 21, 215 1 40 58
  box "", 23, 215 14 40 34
  radio "Normal" 25, 220 8 30 8, group 1
  radio "Prefix" 27, 220 18 30 8
  radio "Substring" 29, 220 28 30 8
  radio "Suffix" 31, 220 38 30 8
  radio "Exact" 33, 220 48 30 8
  box "Auto-Spell" 35, 215 60 40 30
  radio "On" 37, 220 68 30 8, group 2
  radio "Off" 39, 220 78 30 8
  box "Server" 41, 215 91 40 30
  radio "Default" 43, 220 100 30 8, group 3
  radio "Alternate" 45, 220 110 30 8
  menu "&File", 100
  menu "&Config", 110, 100
  menu "&Public Triggers", 120, 110
  item "&On", 130
  item break, 140
  item "O&ff", 150
  item break, 160, 110
  menu "&Server", 170, 110
  item "&Default", 180
  item break, 190
  item "&Alternate", 200
  menu "Spell-Check &Method", 210, 110
  item "&Normal", 220
  item break, 230
  item "&Prefix", 240
  item "Substring (&Middle)", 250
  item "&Suffix", 260
  item break, 270
  item "&Exact", 280
  item break, 290, 100
  item "&E&xit", 300, ok
}
on *:DIALOG:d.dict:sclick:*: {
  if ($did == 17) { dict $did(3,text) }
  if ($did == 19) { spell $did(3,text) }
  if ($did == 25) { .unset %dict.spellmethod }
  if ($did == 27) { set %dict.spellmethod prefix }
  if ($did == 29) { set %dict.spellmethod substring }
  if ($did == 31) { set %dict.spellmethod suffix }
  if ($did == 33) { set %dict.spellmethod exact }
  if ($did == 37) { .unset %dict.autospell }
  if ($did == 39) { set %dict.autospell off }
  if ($did == 43) { set %dict.server dict.org }
  if ($did == 45) { set %dict.server dict1.us.dict.org }
  if ($did == 47) { thes $did(3,text) }
  else { halt }
}
on *:DIALOG:d.dict:dclick:*: {
  if ($did == 5) && ($str(-,10) !isin $did(5).seltext) && ($did(5).sel != 1) { dict $did(5).seltext }
  else { halt }
}
on *:DIALOG:d.dict:close:*: {
  if $sock(dict) != $null { sockclose dict }
  if $sock(thes) != $null { sockclose thes }
}
on *:DIALOG:d.dict:menu:*: {
  if ($did == 130) { dicttrigger on }
  if ($did == 150) { dicttrigger off }
  if ($did == 180) { set %dict.server dict.org }
  if ($did == 200) { set %dict.server dict1.us.dict.org }
  if ($did == 220) { .unset %dict.spellmethod }
  if ($did == 240) { set %dict.spellmethod prefix }
  if ($did == 250) { set %dict.spellmethod substring }
  if ($did == 260) { set %dict.spellmethod suffix }
  if ($did == 280) { set %dict.spellmethod exact }
}
on *:DIALOG:d.dict:init:*:{
  if (%dict.server == dict.org) { did -c d.dict 43 }
  if (%dict.server == dict1.us.dict.org) { did -c d.dict 45 }
  if (%dict.spellmethod == $null) { did -c d.dict 25 }
  if (%dict.spellmethod == prefix) { did -c d.dict 27 }
  if (%dict.spellmethod == substring) { did -c d.dict 29 }
  if (%dict.spellmethod == suffix) { did -c d.dict 31 }
  if (%dict.spellmethod == exact) { did -c d.dict 33 }
  if (%dict.autospell == $null) || (%dict.autospell == on) { did -c d.dict 37 }
  if (%dict.autospell == off) { did -c d.dict 39 }
}
on *:sockopen:pubdict:{
  write -c %dict-file
  sockwrite -n $sockname %dict.org.var " $+ %dict.org.word $+ "
  sockwrite -n $sockname quit
}
on *:sockread:pubdict:{
  if ($sockerr > 0) return
  :nextread
  sockread %dict.org.temp
  if ($sockbr == 0) return
  if (%dict.org.temp == $null) { return }
  if $gettok(%dict.org.temp,1,32) == 220 || $gettok(%dict.org.temp,1,32) == 151 || $gettok(%dict.org.temp,1,32) == 250 {
    return
  }
  if %dict.org.temp == $chr(46) {
    write %dict-file $replace(%dict.org.temp, $chr(46), $str($chr(45),25))
    return
  }
  if $gettok(%dict.org.temp,1,32) == 552 {
    if %dict.org.var == d {
      write %dict-file [DEFINE] ERROR :: No match for %dict.org.word -- Try !Spell
    }
    if $left(%dict.org.var,1) == m {
      write %dict-file [SPELL] ERROR :: No match for %dict.org.word
    }
    return
  }
  if $gettok(%dict.org.temp,1,32) == 150 {
    write %dict-file $upper($gettok(%dict.org.temp,2-,32))
    write %dict-file $str($chr(45),50)
    return
  }
  if $gettok(%dict.org.temp,1,32) == 221 {
    return
  }
  if $left(%dict.org.var,1) == m {
    if $gettok(%dict.org.temp,1,32) == 152 {
      write %dict-file $upper($gettok(%dict.org.temp,2-,32))
      write %dict-file $str($chr(45),50)
      return
    }
    write %dict-file $remtok($gettok(%dict.org.temp,2-,32),1-,34)
    goto nextread
  }
  write %dict-file %dict.org.temp
  goto nextread
}
on *:sockclose:pubdict:{
  set %dict-pub-line 1
  set %dict-pub-totlines $lines(%dict-file)
  :next
  if %dict-pub-line <= %dict-pub-totlines {
    .timerdict-pub- $+ %dict-pub-line 1 %dict-pub-line .msg %dict-pub-nick $read(%dict-file, %dict-pub-line)
    inc %dict-pub-line
    goto next
  }
  else {
    .timerdict-pub-enable 1 $calc(%dict-pub-line + 2) .enable #ni-dict-pub
    .timerdict-pub-remove $+ %dict-file 1 $calc(%dict-pub-line + 30) .remove %dict-file
    halt
  }
}

#ni-dict-pub on
on *:TEXT:!define*:*:{
  if $2 == $null { halt }
  else {
    set %dict-pub-nick $nick
    .disable #ni-dict-pub
    dictpub $2-
  }
}
on *:TEXT:!spell*:*:{
  if $2 == $null { halt }
  else {
    set %dict-pub-nick $nick
    .disable #ni-dict-pub
    spellpub $2-
  }
}
on *:TEXT:!thes*:*:{
  if $2 == $null { halt }
  else {
    set %dict-pub-nick $nick
    set %thes.format public
    .disable #ni-dict-pub
    thes $2-
  }
}
#ni-dict-pub end

#ni-dict-menu on
menu status,channel {
  -
  (Dict)
  .Define:/dict $?="Define A Word"
  .Spell:/spell $?="SpellCheck A Word"
  .Thesaurus:/thes $?="Look up a word in the Thesaurus"
  .-
  .Settings
  ..Popups
  ...On:dictmenu on
  ...-
  ...Off:dictmenu off
  ..Public Triggers
  ...On:dicttrigger on
  ...-
  ...Off:dicttrigger off
  ..-
  ..Dict Server
  ...Default:/set %dict.server dict.org
  ...-
  ...Alternate:/set %dict.server dict1.us.dict.org
  ..Spell-Check Method
  ...Normal:/.unset %dict.spellmethod
  ...-
  ...Prefix:/set %dict.spellmethod prefix
  ...Substring (Middle):/set %dict.spellmethod substring
  ...Suffix:/set %dict.spellmethod suffix
  ...-
  ...Exact:/set %dict.spellmethod exact
  ..-
  ..Unload:unload -rs ni-dict.mrc
}
#ni-dict-menu end




alias thes {
  if $1 == $null { echo $color(info) -se * Usage: /thesaurus WORD }
  else {
    if $sock(dict) != $null { sockclose dict }
    if $sock(thes) != $null { sockclose thes }
    set %dict.org.var t
    set %dict.org.dvar 5
    set %dict.org.word $1-
    set %thes.file $+(",$scriptdir,thesaurus.txt,")
    sockopen thes thesaurus.reference.com 80
    if (%thes.format == $null) {
      if $dialog(d.dict) != $null { goto next }
      else {
        dialog -mv d.dict d.dict
        goto next
      }
      :next
      dialog -v d.dict
      did -h d.dict 7
      did -v d.dict 5
      did -ac d.dict 3 %dict.org.word
      did -r d.dict 7
      did -r d.dict 5
    }
  }
}

; $striphtml by fubar
alias striphtml {
  if ($1) {
    var %strip,%parm = <> $remove($1-,> <,><,$chr(9)) <>,%n = 2
    while ($gettok($gettok(%parm,%n,62),1,60)) {
      %strip = %strip $ifmatch
      inc %n
    }
    return %strip
  }
}
alias dothes {
  unset %thes.read1
  set %thes.read2 $lines(%thes.file)
  if ($lines(%thes.file) == 0) {
    did -a d.dict 5 [THES] ERROR :: no match for %dict.org.word
    if (%dict.autospell == $null) || (%dict.autospell == on) {
      did -a d.dict 5 Checking Spelling . . .
      .timer 1 1 spell %dict.org.word
    }
  }
  if ($lines(%thes.file) >= 1) {
    did -a d.dict 5 $lines(%thes.file) MATCHES FOUND
    did -a d.dict 5 $str($chr(45),50)
    :next
    inc %thes.read1
    if (%thes.read1 <= %thes.read2) {
      did -a d.dict 5 $read(%thes.file,%thes.read1)
      goto next
    }
    did -a d.dict 5 $str($chr(45),25)
  }
}
alias thespub {
  .unset %thes.format
  .unset %thespub.line1
  set %thespub.line2 $lines(%thes.file)
  :next
  inc %thespub.line1
  if %thespub.line1 <= %thespub.line2 {
    .timer 1 %thespub.line1 .msg %dict-pub-nick $read(%thes.file,%thespub.line1)
    goto next
  }
  .timer 1 $calc(%thespub.line1 + 2) .enable #ni-dict-pub
}
on *:sockopen:thes:{
  sockwrite -n $sockname GET /search?q= $+ %dict.org.word HTTP/1.0
  sockwrite -n $sockname Accept: */*
  sockwrite -n $sockname Accept-Language: en-us
  ;sockwrite -n $sockname Accept-Encoding: gzip, deflate
  sockwrite -n $sockname User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
  sockwrite -n $sockname Host: thesaurus.reference.com
  sockwrite -n $sockname Connection: Keep-Alive
  sockwrite -n $sockname
  write -c %thes.file
  unset %thes.count
}
on *:sockread:thes:{
  set %thes.fil Synonyms:
  if ($sockerr > 0) { return }
  :nextread
  sockread -f %thes.temp
  if ($sockbr == 0) return
  if (%thes.temp == $null) || ($striphtml(%thes.temp) == $null) { goto nextread }
  if (%thes.count != $null) { goto nextread }
  ;  if (%dict.org.word isin $striphtml(%thes.temp)) {
  ;  if (%thes.fil isin $striphtml(%thes.temp)) && (Source: !isin %thes.temp) {
  if (%thes.fil isin $striphtml(%thes.temp)) || (%dict.org.word isin $striphtml(%thes.temp)) {
    write %thes.file $gettok($gettok($gettok($replace($remove($striphtml(%thes.temp),&nbsp;,&nbsp),Synonyms:,$chr(171),Source:,$Chr(172),Antonyms:,$chr(173),$chr(13),$crlf,$chr(10),$crlf,$chr(44) $+ $chr(32),$crlf),2-,171),1,173),1,172)
  }
  if (Concept: isin %thes.temp) { inc %thes.count }
  goto nextread
}
on *:sockclose:thes:{
  if %thes.format != $null { thespub }
  else { dothes }
}