daily pastebin goal
59%
SHARE
TWEET

Wikipedia Search Snippets v1.0

illpastethat May 7th, 2016 (edited) 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Wikipedia Script (Snippet Search) v1.0
  2. ;Made by nick1
  3. ;View online and report bugs at http://hawkee.com/snippet/17017/
  4. ;Last edit May 7, 2016
  5. ;2DO -- You tell me!
  6.  
  7. alias -l wikiVersion { return v1.0 }
  8.  
  9. on $*:text:/^[!@]w(iki|ikipedia)(\s|$)/Si:*: {
  10.   ;$iif($istok(%youtubefetch,$chan,44),halt,noop)
  11.   ;$iif($istok(%nolinks,$nick,44),halt,noop)
  12.   if ($($+(%,botflood.,$nick),2)) {
  13.     if ($($+(%,botflood.,$nick),2) >= 50) {
  14.       ignore -u60 $address($nick,2)
  15.       msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot.
  16.       halt
  17.     }
  18.     elseif ($($+(%,botflood.,$nick),2) >= 40) {
  19.       msg $chan $+($nick,$chr(44)) Please do not flood the bot.  
  20.       inc -z $+(%,botflood.,$nick) 20
  21.       halt
  22.     }
  23.     else {
  24.       inc -z $+(%,botflood.,$nick) 10
  25.     }
  26.   }
  27.   else { inc -z $+(%,botflood.,$nick) 10 }
  28.   var %ticks $ticks
  29.   set $+(%,wiki.,%ticks,.topic) $replace($strip($2-),$chr(32),_)
  30.   if ($chan) { set $+(%,wiki.,%ticks,.msgtype) $iif($left($strip($1),1) == @,msg $chan,notice $nick) }
  31.   else { set $+(%,wiki.,%ticks,.msgtype) msg $nick }
  32.   if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
  33.     sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
  34.   }
  35.   else {
  36.     $($+(%,wiki.,%ticks,.msgtype),2) Please specify a topic to search wikipedia for.
  37.     .timerWikiVarDelete 1 1 unset $+(%,wiki.,%ticks,.*)
  38.   }
  39. }
  40.  
  41. on *:input:*:{
  42.   if (($left($strip($1),1) == @) || ($left($strip($1),1) == !)) {
  43.     if (($remove($1,$left($strip($1),1)) == wiki) || ($remove($1,$left($strip($1),1)) == wikipedia)) {
  44.       if ($2) {
  45.         var %ticks $ticks
  46.         set $+(%,wiki.,%ticks,.topic) $replace($strip($2-),$chr(32),_)
  47.         set $+(%,wiki.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $active,echo -a),msg $active)
  48.         if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
  49.           sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
  50.         }
  51.       }
  52.       elseif ($2 == $null) {
  53.         echo -a 4Incorrect Syntax - Use10 $1 <search text>
  54.       }
  55.     }
  56.   }
  57. }
  58.  
  59. alias wiki {
  60.   var %ticks $ticks
  61.   set $+(%,wiki.,%ticks,.topic) $replace($strip($1-),$chr(32),_)
  62.   set $+(%,wiki.,%ticks,.msgtype) echo -a
  63.   if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
  64.     sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
  65.   }
  66.   else {
  67.     $($+(%,wiki.,%ticks,.msgtype),2) Please specify a topic to search wikipedia for.
  68.     .timerWikiVarDelete 1 1 unset $+(%,wiki.,%ticks,.*)
  69.   }
  70.  
  71. }
  72.  
  73. on *:sockopen:wiki*: {
  74.   ;$iif(!$window(@Wiki- $+ $network),window -evn @Wiki- $+ $network,noop)
  75.   var %ticks $remove($sockname,wiki.)
  76.   var %x sockwrite -nt $sockname
  77.   %x GET $+(/w/api.php?format=xml&action=query&generator=search&gsrnamespace=0&gsrsearch=,$($+(%,wiki.,%ticks,.topic),2),&gsrlimit=1&prop=extracts&exintro&explaintext&exsentences=2&exlimit=max) HTTP/1.1
  78.   %x Host: en.wikipedia.org
  79.   %x $crlf
  80. }
  81.  
  82. alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
  83.  
  84. on *:SOCKREAD:wiki*: {
  85.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  86.   else {
  87.     var %ticks $remove($sockname,wiki.)
  88.     sockread &t
  89.     bwrite temp $+ %ticks -1 -1 &t
  90.     bread temp $+ %ticks 0 $file(temp $+ %ticks).size &binvar2
  91.     var %pos1 $bfind(&binvar2,1,<extract xml:space="preserve">)
  92.     var %pos2 $bfind(&binvar2,%pos1,</extract>)
  93.     if (%pos1 != 0) && (%pos2 != 0) {
  94.       var %out $bvar(&binvar2,$+($calc(%pos1 +30),-,$calc(%pos2 - 1))).text
  95.       var %out $replace(%out,&quot;,$chr(34))
  96.       if ($numtok(%out,32) < 30) {
  97.         var %out $gettok(%out,1-,32)
  98.       }
  99.       else {
  100.         var %out $gettok(%out,1-27,32) $+ ...
  101.       }
  102.       var %pos1 $bfind(&binvar2,1,title=")
  103.       var %pos2 $bfind(&binvar2,%pos1," index)
  104.       var %link $bvar(&binvar2,$+(%pos1,-,%pos2)).text
  105.       var %link $replace($noqt($remove(%link,title=)),$chr(32),_)
  106.       var %link https://en.wikipedia.org/wiki/ $+ %link
  107.       $($+(%,wiki.,%ticks,.msgtype),2) $+(10,%out,12,$chr(32) $+ %link)
  108.       wikicleanup %ticks
  109.       .timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
  110.     }
  111.     elseif (*<?xml version="1.0"?><api batchcomplete=""><limits extracts="20" /></api>* iswm $bvar(&binvar2,1-).text) {
  112.       ;echo @Wiki- $+ $network 4NO FOUND
  113.       $($+(%,wiki.,%ticks,.msgtype),2) 10No results found. View search page:12 https://en.wikipedia.org/wiki/Special:Search?search= $+ $($+(%,wiki.,%ticks,.topic),2)
  114.       wikicleanup %ticks
  115.       .timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
  116.       halt
  117.     }
  118.   }
  119. }
  120. alias wikicleanup {
  121.   ;echo @Wiki- $+ $network Cleaning up
  122.   .remove temp $+ $1
  123.   bunset &t
  124.   bunset &binvar2
  125.   sockclose wiki. $+ $1
  126. }
  127.  
  128. on *:start: .timerWUpdate 1 60 WUpdate
  129.  
  130. alias WUpdate {
  131.   ;echo -atc info 12[04Wiki Script12] Checking for updates...
  132.   sockopen wUpdate hawkee.com 80
  133. }
  134.  
  135. on *:sockopen:wupdate: {  
  136.   sockwrite -nt $sockname GET /snippet/17017/ HTTP/1.1
  137.   sockwrite -nt $sockname Host: hawkee.com
  138.   sockwrite -nt $sockname $crlf
  139. }
  140.  
  141. on *:SOCKREAD:WUpdate: {
  142.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr $sockname $asctime | halt }
  143.   sockread %sockreader
  144.   if (*<title>* iswm %sockreader) {
  145.     tokenize 32 %sockreader
  146.     if ($WikiVersion != $5) {
  147.       echo -atc info 12[04Wiki Script12] Current: $WikiVersion Latest: $5 Status: Please update at http://hawkee.com/snippet/17017/
  148.     }
  149.     unset %sockreader
  150.     sockclose $sockname
  151.   }
  152. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top