Wikipedia Script (Snippet Search) v1.0

By illhawkthat on May 07, 2016

alt text

  • Wikipedia Script (Snippet Search) v1.0
  • Made by nick1
  • Last edit May 7, 2016

USAGE:

Delivers quick info about a subject using either @wiki TOPIC or !wiki TOPIC (@commands are public to the channel and !commands are noticed to the user)
Works with !w and !wikipedia
This script will automatically notify you of script updates when you start mIRC

DIRECTIONS:

Copy entire code and paste into remote section of a new script (Hit alt+r, File New)
Sample output: @wiki mIRC
mIRC is an Internet Relay Chat (IRC) client for Windows, created in 1995 and developed by Khaled Mardam-Bey. Although it is a fully functional chat utility, its... https://en.wikipedia.org/wiki/MIRC

INFO:

Posted May 07, 2016
I can be contacted via a comment below
I can be found at irc.rizon.net:6667 name nick1

CHANGELOG:


--Let me know when its broken//what you want changed.


--Feedback greatly appreciated

--If you don't like it lick it.

;Wikipedia Script (Snippet Search) v1.0
;Made by nick1
;View online and report bugs at http://hawkee.com/snippet/17017/
;Last edit May 7, 2016
;2DO -- You tell me!

alias -l wikiVersion { return v1.0 }

on $*:text:/^[!@]w(iki|ikipedia)(\s|$)/Si:*: {
  ;$iif($istok(%youtubefetch,$chan,44),halt,noop)
  ;$iif($istok(%nolinks,$nick,44),halt,noop)
  if ($($+(%,botflood.,$nick),2)) {
    if ($($+(%,botflood.,$nick),2) >= 50) { 
      ignore -u60 $address($nick,2) 
      msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot. 
      halt 
    }
    elseif ($($+(%,botflood.,$nick),2) >= 40) {
      msg $chan $+($nick,$chr(44)) Please do not flood the bot.  
      inc -z $+(%,botflood.,$nick) 20 
      halt 
    }
    else { 
      inc -z $+(%,botflood.,$nick) 10 
    }
  }
  else { inc -z $+(%,botflood.,$nick) 10 }
  var %ticks $ticks
  set $+(%,wiki.,%ticks,.topic) $replace($strip($2-),$chr(32),_)
  if ($chan) { set $+(%,wiki.,%ticks,.msgtype) $iif($left($strip($1),1) == @,msg $chan,notice $nick) }
  else { set $+(%,wiki.,%ticks,.msgtype) msg $nick }
  if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
    sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
  }
  else { 
    $($+(%,wiki.,%ticks,.msgtype),2) Please specify a topic to search wikipedia for.
    .timerWikiVarDelete 1 1 unset $+(%,wiki.,%ticks,.*) 
  }
}

on *:input:*:{
  if (($left($strip($1),1) == @) || ($left($strip($1),1) == !)) {
    if (($remove($1,$left($strip($1),1)) == wiki) || ($remove($1,$left($strip($1),1)) == wikipedia)) {
      if ($2) {
        var %ticks $ticks
        set $+(%,wiki.,%ticks,.topic) $replace($strip($2-),$chr(32),_)
        set $+(%,wiki.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $active,echo -a),msg $active)
        if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
          sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
        }
      }
      elseif ($2 == $null) { 
        echo -a 4Incorrect Syntax - Use10 $1 <search text> 
      }
    }
  }
}

alias wiki {
  var %ticks $ticks
  set $+(%,wiki.,%ticks,.topic) $replace($strip($1-),$chr(32),_)
  set $+(%,wiki.,%ticks,.msgtype) echo -a 
  if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
    sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
  }
  else { 
    $($+(%,wiki.,%ticks,.msgtype),2) Please specify a topic to search wikipedia for.
    .timerWikiVarDelete 1 1 unset $+(%,wiki.,%ticks,.*) 
  }

}

on *:sockopen:wiki*: { 
  ;$iif(!$window(@Wiki- $+ $network),window -evn @Wiki- $+ $network,noop)
  var %ticks $remove($sockname,wiki.)
  var %x sockwrite -nt $sockname
  %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
  %x Host: en.wikipedia.org
  %x $crlf
}

alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }

on *:SOCKREAD:wiki*: { 
  if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  else {
    var %ticks $remove($sockname,wiki.)
    sockread &t
    bwrite temp $+ %ticks -1 -1 &t
    bread temp $+ %ticks 0 $file(temp $+ %ticks).size &binvar2
    var %pos1 $bfind(&binvar2,1,<extract xml:space="preserve">)
    var %pos2 $bfind(&binvar2,%pos1,</extract>)
    if (%pos1 != 0) && (%pos2 != 0) {
      var %out $bvar(&binvar2,$+($calc(%pos1 +30),-,$calc(%pos2 - 1))).text
      var %out $replace(%out,&quot;,$chr(34))
      if ($numtok(%out,32) < 30) {
        var %out $gettok(%out,1-,32)
      }
      else {
        var %out $gettok(%out,1-27,32) $+ ...
      }
      var %pos1 $bfind(&binvar2,1,title=")
      var %pos2 $bfind(&binvar2,%pos1," index)
      var %link $bvar(&binvar2,$+(%pos1,-,%pos2)).text
      var %link $replace($noqt($remove(%link,title=)),$chr(32),_)
      var %link https://en.wikipedia.org/wiki/ $+ %link
      $($+(%,wiki.,%ticks,.msgtype),2) $+(10,%out,12,$chr(32) $+ %link)
      wikicleanup %ticks
      .timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
    }
    elseif (*<?xml version="1.0"?><api batchcomplete=""><limits extracts="20" /></api>* iswm $bvar(&binvar2,1-).text) {
      ;echo @Wiki- $+ $network 4NO FOUND
      $($+(%,wiki.,%ticks,.msgtype),2) 10No results found. View search page:12 https://en.wikipedia.org/wiki/Special:Search?search= $+ $($+(%,wiki.,%ticks,.topic),2)
      wikicleanup %ticks
      .timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
      halt
    }
  }
}
alias wikicleanup { 
  ;echo @Wiki- $+ $network Cleaning up
  .remove temp $+ $1
  bunset &t
  bunset &binvar2
  sockclose wiki. $+ $1
}

on *:start: .timerWUpdate 1 60 WUpdate

alias WUpdate {
  ;echo -atc info 12[04Wiki Script12] Checking for updates...
  sockopen wUpdate hawkee.com 80
}

on *:sockopen:wupdate: {  
  sockwrite -nt $sockname GET /snippet/17017/ HTTP/1.1
  sockwrite -nt $sockname Host: hawkee.com
  sockwrite -nt $sockname $crlf
}

on *:SOCKREAD:WUpdate: { 
  if ($sockerr) { echo -a SOCKET ERROR: $sockerr $sockname $asctime | halt }
  sockread %sockreader
  if (*<title>* iswm %sockreader) {
    tokenize 32 %sockreader
    if ($WikiVersion != $5) {
      echo -atc info 12[04Wiki Script12] Current: $WikiVersion Latest: $5 Status: Please update at http://hawkee.com/snippet/17017/
    }
    unset %sockreader
    sockclose $sockname
  }
}

Comments

Sign in to comment.
bertolaz   -  Dec 01, 2022

Thanks!

 Respond  
rebel9   -  Jul 18, 2017

.

illhawkthat  -  Jul 18, 2017

Hi @Rebel9 thanks for the comment - can you provide some more information on what context this script has that would allow it to be compromised? Thanks!

rebel9  -  Jul 29, 2017

!wiki test PRIVMSG #yourchannel :SUP

rebel9  -  Jul 29, 2017

cmd injection without even involving a pipe.

Sign in to comment

Hazem   -  Aug 09, 2016

@illhawkthat I LOVE IT! Thank you so much. You're the best! It's certainly a brilliant script. I just wish it had the same option that the YouTube script has, which is choosing rooms where the script would not run on. And entering certain nicknames who cannot use the script. But I love the script, and appreciate your effort... Forgive me for being greedy :P

illhawkthat  -  Aug 28, 2016

That's a good point! I probably won't add the whole interface option but if you want to add the same exceptions that you have on the youtube script you can add these lines under the on text event:
$iif($istok(%youtubefetch,$chan,44),halt,noop)
$iif($istok(%nolinks,$nick,44),halt,noop)

Sign in to comment

NoKz   -  May 28, 2016

Awesome script! Thank you very much for it! I have a couple of questions; I'm working on this for TwitchTV and was trying to figure out a good way to enable it only for moderators and subscribers? Also, is there a way I can blacklist offensive words? Thanks!

illhawkthat  -  May 28, 2016

Glad you got it working for mods and subscribers (http://hawkee.com/snippet/8577/#c130081) for blacklist words, you can do something like.

alias badwords { return hitler,shit,fuck,bad words,example }

and insert before line 32

if ($gettok($badwords,$($+(%,wiki.,%ticks,.topic),2),44) != $null) {  $($+(%,wiki.,%ticks,.msgtype),2) Sorry that's a bad word.
wikicleanup %ticks
.timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
halt
}
Sign in to comment

illhawkthat   -  May 07, 2016

Hey @Hawkee how do I add screenshots to the page?

Hawkee  -  May 10, 2016

Just like that =D If you want it to appear in the body of the page you'll have to link to the image file directly and use markdown to reference it.

Sign in to comment

illhawkthat   -  May 07, 2016
Clark2016  -  May 07, 2016

Hi @illhawkthat , can you please do a !google script? Thanks :) and this script is good.

illhawkthat  -  May 07, 2016

@Clark2016 try http://hawkee.com/snippet/7465/ or http://hawkee.com/snippet/14/ I think people have made a bunch of google scripts on this website before. Best of luck!

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.