Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. # Lilys Simple Dictionary (lily@disorg.net)
  2. # Dictionary script for eggdrop bots
  3. # Will return short dictionary definitions from dict.org
  4. # Requires TCL8.0 or greater, has only been tested on eggdrop > 1.6.15
  5. ## VERSION 1.0 6/15/04 - basic functions
  6. ## Version 2.0 10/17/07 - changed to dict.org
  7. ## Version 3.0 10/16/13 - code rewrite
  8. # You must ".chanset #channel +ldict" for each chan you wish to use this in.
  9. # USAGE !d <word>
  10.  
  11. ####################################################################
  12.  
  13. package require http
  14. setudef flag ldict
  15. set ldef(vers) 3.0
  16. set ldef(agent) "Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"
  17.  
  18. proc pub_d {nick uhand handle chan input} {
  19. if {[channel get $chan ldict]} {
  20. global ldef
  21. if {[llength $input]==0} {
  22. putserv "PRIVMSG $chan :Lilys Dictionary $ldef(vers). Definitions are from WordNet, served by http://dict.org"
  23. } else {
  24. set query "http://www.dict.org/bin/Dict?Form=Dict1&Strategy=*&Database=wn&Query="
  25. for { set index 0 } { $index<[llength $input] } { incr index } {
  26. set query "$query[lindex $input $index]"
  27. if {$index<[llength $input]-1} then {
  28. set query "$query+"
  29. }
  30. }
  31. }
  32. set http [::http::config -useragent $ldef(agent)]
  33. set http [::http::geturl $query]
  34. set html [split [::http::data $http] \n]
  35. ::http::cleanup $http
  36.  
  37. #check for valid word
  38. if {[regexp {No definitions found for} $html]} {
  39. regexp {wn:(.*?)</pre>} $html - nodef
  40. if {![info exists nodef]} {
  41. putserv "PRIVMSG $chan :$nick, $input was not found in WordNet"
  42. return 0
  43. }
  44. regsub -all {<[^>]*>} $nodef {} nodef
  45. regsub -all {[\{\}\\]} $nodef {} nodef
  46. regsub -all " +" $nodef " " nodef
  47. putserv "PRIVMSG $chan :$nick, $input was not found. Try:$nodef"
  48. return 0
  49. }
  50. #get def
  51. regexp {WordNet \(r\) 3.0 \(2006\) </a>:(.*?)Questions or comments} $html - defdata
  52. if {![info exists defdata]} {
  53. putserv "PRIVMSG $chan :$nick, data not found :("
  54. return 0
  55. }
  56. regsub -all {<[^>]*>} $defdata {} defdata
  57. regsub -all {[\{\}\\]} $defdata {} defdata
  58. regsub -all " +" $defdata " " defdata
  59.  
  60. regexp { v 1: (.*?$)} $defdata - vdef
  61. if {[info exists vdef]} {
  62. regsub { 2: (.*?$)} $vdef "" vdef
  63. set vdef [string trim $vdef]
  64. set verbd "\002\[V\]\002: $vdef "
  65. append output $verbd
  66. }
  67. regexp {n 1: (.*?$)} $defdata - ndef
  68. if {[info exists ndef]} {
  69. regsub { 2: (.*?$)} $ndef "" ndef
  70. regsub { v 1: (.*?$)} $ndef "" ndef
  71. set ndef [string trim $ndef]
  72. set nound "\002\[N\]\002: $ndef "
  73. append output $nound
  74. }
  75. regexp {adv 1: (.*?$)} $defdata - advdef
  76. if {[info exists advdef]} {
  77. regsub { 2: (.*?$)} $advdef "" advdef
  78. regsub { n 1: (.*?$)} $advdef "" advdef
  79. regsub { v 1: (.*?$)} $advdef "" advdef
  80. regsub { adj 1: (.*?$)} $advdef "" advdef
  81. set advdef [string trim $advdef]
  82. set advd "\002\[Adv\]\002: $advdef "
  83. append output $advd
  84. }
  85. regexp {adj 1: (.*?$)} $defdata - adjdef
  86. if {[info exists adjdef]} {
  87. regsub { 2: (.*?$)} $adjdef "" adjdef
  88. regsub { n 1: (.*?$)} $adjdef "" adjdef
  89. regsub { v 1: (.*?$)} $adjdef "" adjdef
  90. regsub { adv 1: (.*?$)} $adjdef "" adjdef
  91. set adjdef [string trim $adjdef]
  92. set adjd "\002\[Adj\]\002: $adjdef"
  93. append output $adjd
  94. }
  95. putserv "PRIVMSG $chan :$nick, \002$input\002: $output"
  96. }
  97. }
  98. bind pub - !d pub_d
  99.  
  100. putlog "Lilys Dictionary $ldef(vers) loaded!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement