Guest User

Untitled

a guest
Jan 18th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.81 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;Wikipedia Script by Ford_Lawnmower irc.mindforge.org #USA-Chat;;
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. alias -l GetGwikipedia {
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6. ;;;;;;;;;;;;;;;Start of Simple Setup;;;;;;;;;;;;;;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;;Change %langcode(below) to the language you want this script to return results in (ie - de for german fr for french it for italian, etc)
  9. var %langcode en
  10. ;;;Change %wikilogo(below) to change the logo.(This must be one continious string - NO SPACES)
  11. var %wikilogo 14W04i14k04i14p04e14d04i14a04
  12. ;;;Change %textcolor(below) to change the color of the results text. (There must be at least a " " here.)
  13. var %textcolor 04
  14. ;;;Change %linkcolor(below) to change the color of the returned link.(There must be at least a " " here.)
  15. var %linkcolor 12
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. ;;;;;;;;;;;;;;;End Setup;;;;;;;;;;;;;;;
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. $1-2 %wikilogo $+(%textcolor,Searching For:,%linkcolor) $3-
  20. var %sockname $+(GWikipedia,$network,$2,$ticks)
  21. sockopen %sockname www.google.com 80
  22. sockmark %sockname $1-2 $+(/search?q=,$replace($3-,$chr(32),+),+site:,%langcode.,wikipedia.org&rls=,%langcode,&hl=,%langcode) %wikilogo %textcolor %linkcolor $3-
  23. }
  24. menu Channel,Status {
  25. .$iif($group(#Wikipedia) == On,$style(1)) Wikipedia Trigger
  26. ..$iif($group(#Wikipedia) == On,$style(2)) On: .enable #Wikipedia
  27. ..$iif($group(#Wikipedia) == Off,$style(2)) Off: .disable #Wikipedia
  28. }
  29. alias Wiki { GetGWikipedia echo -a $1- }
  30. #Wikipedia on
  31. On $*:Text:/^(\+|-|!|@)Wiki.*/Si:#: {
  32. var %action $regml(1)
  33. if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@)/)) {
  34. if (%action == +) {
  35. if ($istok(%WikipediaChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is already running the Wikipedia script }
  36. else {
  37. .enable #Wikipedia
  38. Set %WikipediaChanList $addtok(%WikipediaChanList,$+($network,$chan),32)
  39. .msg $chan $nick has activated the Wikipedia script for $chan .
  40. }
  41. }
  42. else {
  43. if (!$istok(%WikipediaChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is not running the Wikipedia script }
  44. else {
  45. Set %WikipediaChanList $remtok(%WikipediaChanList,$+($network,$chan),1,32)
  46. .msg $chan $nick has deactivated the Wikipedia script for $chan .
  47. }
  48. }
  49. }
  50. elseif (!$timer($+(Wikipedia,$network,$nick))) && ($istok(%WikipediaChanList,$+($network,$chan),32)) {
  51. .timer $+ $+(Wikipedia,$network,$nick) 1 6 noop
  52. var %method $iif(%action == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/),.msg $chan,.notice $nick))
  53. GetGWikipedia %method $2-
  54. }
  55. }
  56. #Wikipedia end
  57. On *:sockopen:GWikipedia*: {
  58. if (!$sockerr) {
  59. sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
  60. sockwrite -n $sockname Host: www.google.com
  61. sockwrite -n $sockname $crlf
  62. }
  63. else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  64. }
  65. On *:sockread:GWikipedia*: {
  66. if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  67. else {
  68. sockread &GWikipedia
  69. var %GWikipedia $bintween(&GWikipedia,<cite>,</cite>,1)
  70. if (wikipedia.org isin %GWikipedia) {
  71. tokenize 32 $sock($sockname).mark
  72. ResultsWiki $1-2 $gettok(%GWikipedia,1,47) $remove($replace($gettok(%GWikipedia,2-,47),&amp;,&),<b>,</b>) $4-6
  73. sockclose $sockname
  74. return
  75. }
  76. }
  77. }
  78. On *:sockclose:GWikipedia*: {
  79. tokenize 32 $sock($sockname).mark
  80. $1-2 $+($4,$5) Sorry - Cannot find $7-
  81. }
  82. alias -l ResultsWiki {
  83. var %sockname $+(ResultsWiki,$2,$ticks,$r(1,$ticks))
  84. sockopen %sockname $3 80
  85. sockmark %sockname $1-
  86. }
  87. On *:Sockopen:ResultsWiki*: {
  88. .timer $+ $sockname 1 5 CloseWikiError $sockname
  89. sockwrite -nt $sockname GET $+(/,$gettok($sock($sockname).mark,4,32)) HTTP/1.1
  90. sockwrite -n $sockname User-Agent: Opera 9.6
  91. sockwrite -n $sockname Host: $gettok($sock($sockname).mark,3,32) $+ $str($crlf,2)
  92. }
  93. on *:sockread:ResultsWiki*: {
  94. if ($sockerr > 0) { echo -at >Sock Error< Wikipedia | sockclose $sockname }
  95. else {
  96. sockread -fn &wiki
  97. if $bvar(&wiki, 0) {
  98. bwrite $+($sockname,.dat) -1 -1 &wiki
  99. bread $+($sockname,.dat) 1 $file($+($sockname,.dat)).size &wiki
  100. if ($bintween(&wiki,<b>,</p>,1)) || ($bintween(&wiki,<p>,</p>,1)) {
  101. .remove $+($sockname,.dat)
  102. tokenize 32 $sock($sockname).mark
  103. bset -t &result 1 $bintween(&wiki,<p>,</p>,1)
  104. if (may refer to: isin $bvar($binstrip(&result),1,429).text) {
  105. $1-2 $+($5,$6) Nothing Found! Please refine your search and check your spelling.
  106. .timer $+ $sockname off
  107. sockclose $sockname
  108. return
  109. }
  110. put $1-2 $fix&#($bvar($binstrip(&result),1,$bvar(&result, 0)).text) $+($7,http://,$3,/,$4)
  111. .timer $+ $sockname off
  112. sockclose $sockname
  113. return
  114. }
  115. elseif ($bvar(&wiki, 0)) && ($bfind(&wiki, 1, <h2>Contents</h2>)) { CloseWikiError $sockname }
  116. }
  117. }
  118. }
  119. alias -l CloseWikiError {
  120. var %sockname $1
  121. tokenize 32 $sock($1).mark
  122. $1-2 $5-6 Sorry :(( Unable to Parse $+($7,http://,$3,/,$4)
  123. sockclose %sockname
  124. .remove $+(%sockname,.dat)
  125. return
  126. }
  127. alias -l fix&# { return $replace($regsubex($1-,/\&\#([0-9]{1,});/g,$UTF8(\t)),&quot;,",&amp;,&,&gt;,>,&lt;,<,&#39;,',|,,$chr(9),$chr(32)) }
  128. alias -l UTF8 {
  129. var %x $base($1,10,2),%y $len(%x)
  130. if ($1 < 161) { return $chr($1) }
  131. elseif (%y < 12) { return $+($shift(11000000,$left(%x,-6)),$shift(10000000,$right(%x,6))) }
  132. elseif (%y < 17) { return $+($shift(11100000,$left(%x,-12)),$shift(10000000,$mid(%x,-12,6)),$shift(10000000,$right(%x,6))) }
  133. elseif (%y < 22) {
  134. return $+($shift(11110000,$left(%x,-18)),$shift(10000000,$mid(%x,$iif(%y < 18,$+(-,%y),-18),6)),$shift(10000000,$mid(%x,-12,6)),$shift(10000000,$right(%x,6)))
  135. }
  136. }
  137. alias -l shift {
  138. if ($2) { return $chr($base($+($left($1,$+(-,$len($2))),$2),2,10)) }
  139. else { return $chr($base($1,2,10)) }
  140. }
  141. alias -l Put {
  142. if (!$regex($1,/(\.|^)(msg|notice|echo)$/Si)) || (!$3) { echo -st **Put error** Syntax /Put msg #channel text - or - /Put notice nickname text | return }
  143. tokenize 32 $regsubex($1-,/([$\|%\[\]\}\{][^\s]*)/g,$+($chr(2),$chr(2),\t))
  144. var %tokens $0, %Tstart 3, %Dtimer 1000, %prefix $gettok($sock($sockname).mark,5-6,32)
  145. if ($timer($+(Put,$2,$network)).secs) { %Dtimer = $calc($v1 * 1000) }
  146. while ($len($($+($,%Tstart,-,%tokens),2)) > $calc(420 - $len(%prefix))) {
  147. dec %tokens
  148. if ($len($($+($,%Tstart,-,%tokens),2)) <= $calc(420 - $len(%prefix))) {
  149. .timer -m 1 %Dtimer $1-2 $+(%prefix,$($+($,%Tstart,-,%tokens),2)))
  150. inc %Dtimer 1500
  151. %Tstart = $calc(%tokens + 1)
  152. %tokens = $0
  153. }
  154. }
  155. .timer -m 1 %Dtimer $1-2 $+(%prefix,$($+($,%Tstart,-,%tokens),2)))
  156. .timer $+ $+(Put,$2,$network) -m 1 $calc(%Dtimer + 1000) noop
  157. }
  158. alias -l fixurl return $regsubex($strip($1-),/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2))
  159. alias -l binstrip {
  160. while ($bfind($1, 1 ,<)) && ($bfind($1, 1, >)) {
  161. var %first = $bfind($1, 1, <), %last $calc($bfind($1, 1, >) - $bfind($1, 1, <) + 1)
  162. noop = $bremove($1, $bvar($1, %first, %last).text)
  163. }
  164. while ($bfind($1, 1 ,$chr(91))) && ($bfind($1, 1, $chr(93))) {
  165. %first = $bfind($1, 1, $chr(91))
  166. %last = $calc($bfind($1, 1, $chr(93)) - $bfind($1, 1, $chr(91)) + 1)
  167. noop = $bremove($1, $bvar($1, %first, %last).text)
  168. }
  169. return $1
  170. }
  171. ;bremove by jaytea
  172. alias bremove {
  173. if (!$isid) || ($0 < 2) || (!$regex($1,/^&[^ ]+$/)) {
  174. echo -ces i * Invalid parameters: $!bremove
  175. return
  176. }
  177. if ($bvar($1,0)) {
  178. var %x = 1
  179. while (%x < $0) {
  180. inc %x
  181. var %i = 1, %t = $eval($ $+ %x,2) $chr(32)
  182. while ($bfind($1,%i,$left(%t,-2)) [ $+ [ $iif($prop == text,.text) ] ]) {
  183. var %i = $v1, %p = $iif($prop != text && $regex(bremove,%t,/^ *\d+(?: +\d+)* *$/i),$numtok(%t,32),$len($mid(%t,3))) + %i
  184. if (%p <= $bvar($1,0)) bcopy -c $1 %i $1 %p -1
  185. elseif ($calc(%i - 1)) bset -c $1 $v1 $bvar($1,$v1)
  186. else bunset $1
  187. }
  188. inc %x 2
  189. }
  190. }
  191. return $1
  192. }
  193. alias -l bintween {
  194. var %count = 1, %mark = 0, %mark2 = 0
  195. while (%count <= $4) {
  196. if ($bfind($1, %mark2, $2).text) {
  197. %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
  198. if ($bfind($1, %mark, $3).text) {
  199. %mark2 = $bfind($1, %mark, $3).text
  200. }
  201. else { return 0 }
  202. }
  203. else { return 0 }
  204. inc %count
  205. }
  206. return $bvar($1, $iif(%mark > 0,%mark,1), $iif($calc(%mark2 - %mark) < 4130,$calc(%mark2 - %mark),4130)).text
  207. }
Add Comment
Please, Sign In to add comment