Advertisement
illpastethat

Wikipedia v0.5

May 7th, 2016
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 5.04 KB | None | 0 0
  1. on $*:text:/^[!@]w(iki|ikipedia)(\s|$)/Si:*: {
  2.   ;$iif($istok(%youtubefetch,$chan,44),halt,noop)
  3.   ;$iif($istok(%nolinks,$nick,44),halt,noop)
  4.   if ($($+(%,botflood.,$nick),2)) {
  5.     if ($($+(%,botflood.,$nick),2) >= 50) {
  6.       ignore -u60 $address($nick,2)
  7.       msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot.
  8.       halt
  9.     }
  10.     elseif ($($+(%,botflood.,$nick),2) >= 40) {
  11.       msg $chan $+($nick,$chr(44)) Please do not flood the bot.  
  12.       inc -z $+(%,botflood.,$nick) 20
  13.       halt
  14.     }
  15.     else {
  16.       inc -z $+(%,botflood.,$nick) 10
  17.     }
  18.   }
  19.   else { inc -z $+(%,botflood.,$nick) 10 }
  20.   var %ticks $ticks
  21.   set $+(%,wiki.,%ticks,.topic) $replace($strip($2-),$chr(32),_)
  22.   if ($chan) { set $+(%,wiki.,%ticks,.msgtype) $iif($left($strip($1),1) == @,msg $chan,notice $nick) }
  23.   else { set $+(%,wiki.,%ticks,.msgtype) msg $nick }
  24.   if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
  25.     sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
  26.   }
  27.   else {
  28.     $($+(%,wiki.,%ticks,.msgtype),2) Please specify a topic to search wikipedia for.
  29.     .timerWikiVarDelete 1 1 unset $+(%,wiki.,%ticks,.*)
  30.   }
  31. }
  32.  
  33. on *:input:*:{
  34.   if (($left($strip($1),1) == @) || ($left($strip($1),1) == !)) {
  35.     if (($remove($1,$left($strip($1),1)) == wiki) || ($remove($1,$left($strip($1),1)) == wikipedia)) {
  36.       if ($2) {
  37.         var %ticks $ticks
  38.         set $+(%,wiki.,%ticks,.topic) $replace($strip($2-),$chr(32),_)
  39.         set $+(%,wiki.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $active,echo -a),msg $active)
  40.         if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
  41.           sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
  42.         }
  43.       }
  44.       elseif ($2 == $null) {
  45.         echo -a 4Incorrect Syntax - Use10 $1 <search text>
  46.       }
  47.     }
  48.   }
  49. }
  50.  
  51. alias wiki {
  52.   var %ticks $ticks
  53.   set $+(%,wiki.,%ticks,.topic) $replace($strip($1-),$chr(32),_)
  54.   set $+(%,wiki.,%ticks,.msgtype) echo -a
  55.   if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
  56.     sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
  57.   }
  58.   else {
  59.     $($+(%,wiki.,%ticks,.msgtype),2) Please specify a topic to search wikipedia for.
  60.     .timerWikiVarDelete 1 1 unset $+(%,wiki.,%ticks,.*)
  61.   }
  62.  
  63. }
  64.  
  65. on *:sockopen:wiki*: {
  66.   $iif(!$window(@Wiki- $+ $network),window -evn @Wiki- $+ $network,noop)
  67.   var %ticks $remove($sockname,wiki.)
  68.   var %x sockwrite -nt $sockname
  69.   if ($($+(%,wiki.,%ticks,.exact),2) != $null) {
  70.     ;echo @Wiki- $+ $network 4Exact match for $($+(%,wiki.,%ticks,.exact),2) from $($+(%,wiki.,%ticks,.topic),2)
  71.     %x GET $($+(%,wiki.,%ticks,.exact),2) HTTP/1.1
  72.   }
  73.   else {
  74.     %x GET /wiki/Special:Search?search= $+ $($+(%,wiki.,%ticks,.topic),2) HTTP/1.1
  75.   }
  76.   %x Host: en.wikipedia.org
  77.   %x $crlf
  78. }
  79.  
  80. alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
  81.  
  82. on *:SOCKREAD:wiki*: {
  83.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  84.   else {
  85.     var %ticks $remove($sockname,wiki.)
  86.     sockread &t
  87.     bwrite temp $+ %ticks -1 -1 &t
  88.     bread temp $+ %ticks 0 $file(temp $+ %ticks).size &binvar2
  89.     ;echo -a $bvar(&binvar2,1-).text
  90.     if (*HTTP/1.1 302 Found* iswm $bvar(&binvar2,1-).text) && ($bfind(&binvar2,1,X-Varnish) != 0) {
  91.       set $+(%,wiki.,%ticks,.exact) $remove($bvar(&binvar2,$+($bfind(&binvar2,1,Location: https://en.wikipedia.org/wiki/),-,$calc($bfind(&binvar2,1,Backend-Timing) -1))).text,Location: ,$+($crlf,X))
  92.       wikicleanup %ticks
  93.       sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
  94.       halt
  95.     }
  96.     elseif (*- Search results - Wikipedia, the free encyclopedia</title>* iswm $bvar(&binvar2,1-).text) {
  97.       ;echo @Wiki- $+ $network 4NO FOUND
  98.       $($+(%,wiki.,%ticks,.msgtype),2) 10No results found. View search page:12 https://en.wikipedia.org/wiki/Special:Search?search= $+ $($+(%,wiki.,%ticks,.topic),2)
  99.       wikicleanup %ticks
  100.       .timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
  101.       halt
  102.     }
  103.     if ($bfind(&binvar2,1,may refer to) != 0) {
  104.       ;echo @Wiki- $+ $network 4DISAMBIG
  105.       $($+(%,wiki.,%ticks,.msgtype),2) 10Reached disambiguation page, view results:12 $+ $($+(%,wiki.,%ticks,.exact),2)
  106.       .timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
  107.       wikicleanup %ticks
  108.     }
  109.     elseif ($bfind(&binvar2,1,<p>) != 0) && ($bfind(&binvar2,1,</p>) != 0) {
  110.       var %pos1 $bfind(&binvar2,1,<p>)
  111.       var %pos2 $bfind(&binvar2,%pos1,</p>)
  112.       var %out $bvar(&binvar2,$+(%pos1,-,$calc(%pos2 + 3))).text
  113.       ;echo @Wiki- $+ $network 4Raw HTML:
  114.       ;echo @Wiki- $+ $network %out
  115.       var %out $nohtml($replace(%out,<b>,,</b>,,<i>,,</i>,))
  116.       if ($numtok(%out,32) < 30) {
  117.         var %out $gettok(%out,1-,32)
  118.       }
  119.       else {
  120.         var %out $gettok(%out,1-27,32) $+ ...
  121.       }
  122.       $($+(%,wiki.,%ticks,.msgtype),2) $+(10,%out,12 ,$($+(%,wiki.,%ticks,.exact),2))
  123.       wikicleanup %ticks
  124.       .timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
  125.     }
  126.   }
  127. }
  128. alias wikicleanup {
  129.   ;echo @Wiki- $+ $network Cleaning up
  130.   .remove temp $+ $1
  131.   bunset &t
  132.   bunset &binvar2
  133.   sockclose wiki. $+ $1
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement