Wikipedia

By FordLawnmower on Apr 16, 2009

I re-did this whole script. If you want the old version you can find it here -->> http://pastebin.com/f132547f7
Re-did Again - Old Version -->> http://pastebin.com/Kcb20Tck

Remade this script to be much more tolerant of typos and CASE errors.
Added google site search to assure a decent result ratio.
Added simple setup so you can change logo, colors, language, etc.
Added bread,bwrite operations to prevent data loss.
Example Output:
20:23:49 @wiki aerosmith
20:23:49 Wikipedia Searching For: aerosmith
20:23:52 Wikipedia Aerosmith is an American hard rock band sometimes referred to as "The Bad Boys from Boston" and "America's Greatest Rock and Roll Band". Their style which is rooted in blues-based hard rock has come to also incorporate elements of pop heavy metal and rhythm and blues and has inspired many subsequent rock artists. The band was formed in Boston Massachusetts in 1970. Guitarist
20:23:53 Joe Perry and bassist Tom Hamilton originally in a band together called the Jam Band met up with singer Steven Tyler drummer Joey Kramer and guitarist Ray Tabano and formed Aerosmith. In 1971 Tabano was replaced by Brad Whitford and the band began developing a following in Boston. http://en.wikipedia.org/wiki/Aerosmith

This is a wikipedia bot script with @wiki(public trigger, for ops) and !wiki(private trigger for anyone) The @trigger messages the channel and the !trigger notices the user.

Syntax !wiki search words or @wiki search words.
Added a language variable
Change %langcode if you want to try another language.

Thanks to jaytea for the cool alias. I found it here -->> http://www.hawkee.com/snippet/4198/

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Wikipedia Script by Ford_Lawnmower irc.mindforge.org #USA-Chat;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alias -l GetGwikipedia {
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;Start of Simple Setup;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;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)
  var %langcode en
  ;;;Change %wikilogo(below) to change the logo.(This must be one continious string - NO SPACES)
  var %wikilogo 14W04i14k04i14p04e14d04i14a04
  ;;;Change %textcolor(below) to change the color of the results text. (There must be at least a " " here.)
  var %textcolor 04
  ;;;Change %linkcolor(below) to change the color of the returned link.(There must be at least a " " here.)
  var %linkcolor 
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;End Setup;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  $1-2 %wikilogo $+(%textcolor,Searching For:,%linkcolor) $3-
  var %sockname $+(GWikipedia,$network,$2,$ticks)
  sockopen %sockname www.google.com 80
  sockmark %sockname $1-2 $+(/search?q=,$replace($3-,$chr(32),+),+site:,%langcode.,wikipedia.org&rls=,%langcode,&hl=,%langcode) %wikilogo %textcolor %linkcolor $3-
}
menu Channel,Status {
  .$iif($group(#Wikipedia) == On,$style(1)) Wikipedia Trigger
  ..$iif($group(#Wikipedia) == On,$style(2)) On: .enable #Wikipedia
  ..$iif($group(#Wikipedia) == Off,$style(2)) Off: .disable #Wikipedia
}
alias Wiki { GetGWikipedia echo -a $1- }
#Wikipedia on
On $*:Text:/^(\+|-|!|@)Wiki.*/Si:#: {
  var %action $regml(1)
  if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@)/)) {
    if (%action == +) {
      if ($istok(%WikipediaChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is already running the Wikipedia script }
      else { 
        .enable #Wikipedia
        Set %WikipediaChanList $addtok(%WikipediaChanList,$+($network,$chan),32)
        .msg $chan $nick has activated the Wikipedia script for $chan .
      }
    }
    else {
      if (!$istok(%WikipediaChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is not running the Wikipedia script }
      else { 
        Set %WikipediaChanList $remtok(%WikipediaChanList,$+($network,$chan),1,32)
        .msg $chan $nick has deactivated the Wikipedia script for $chan . 
      }
    }
  }
  elseif (!$timer($+(Wikipedia,$network,$nick))) && ($istok(%WikipediaChanList,$+($network,$chan),32)) {
    .timer $+ $+(Wikipedia,$network,$nick) 1 6 noop
    var %method $iif(%action == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/),.msg $chan,.notice $nick))
    GetGWikipedia %method $2-
  }
}
#Wikipedia end
On *:sockopen:GWikipedia*: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
    sockwrite -n $sockname Host: www.google.com
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:GWikipedia*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    sockread &GWikipedia
    var %GWikipedia $bintween(&GWikipedia,<cite>,</cite>,1)
    if (wikipedia.org isin %GWikipedia) {
      tokenize 32 $sock($sockname).mark
      ResultsWiki $1-2 $gettok(%GWikipedia,1,47) $remove($replace($gettok(%GWikipedia,2-,47),&amp;,&),<b>,</b>) $4-6
      sockclose $sockname
      return
    }
  }
}
On *:sockclose:GWikipedia*: {
  tokenize 32 $sock($sockname).mark
  $1-2 $+($4,$5) Sorry - Cannot find $7- 
}
alias -l ResultsWiki {
  var %sockname $+(ResultsWiki,$2,$ticks,$r(1,$ticks))
  sockopen %sockname $3 80
  sockmark %sockname $1-
}
On *:Sockopen:ResultsWiki*: {
  .timer $+ $sockname 1 5 CloseWikiError $sockname
  sockwrite -nt $sockname GET $+(/,$gettok($sock($sockname).mark,4,32)) HTTP/1.1
  sockwrite -n $sockname User-Agent: Opera 9.6
  sockwrite -n $sockname Host: $gettok($sock($sockname).mark,3,32) $+ $str($crlf,2)
}
on *:sockread:ResultsWiki*: {
  if ($sockerr > 0) { echo -at >Sock Error< Wikipedia | sockclose $sockname }
  else {
    sockread -fn &wiki
    if $bvar(&wiki, 0) {
      bwrite $+($sockname,.dat) -1 -1 &wiki
      bread $+($sockname,.dat) 1 $file($+($sockname,.dat)).size &wiki
      if ($bintween(&wiki,<b>,</p>,1)) || ($bintween(&wiki,<p>,</p>,1)) {
        .remove $+($sockname,.dat)
        tokenize 32 $sock($sockname).mark
        bset -t &result 1 $bintween(&wiki,<p>,</p>,1)
        if (may refer to: isin $bvar($binstrip(&result),1,429).text) { 
          $1-2 $+($5,$6) Nothing Found! Please refine your search and check your spelling.
          .timer $+ $sockname off
          sockclose $sockname
          return
        }
        put $1-2 $fix&#($bvar($binstrip(&result),1,$bvar(&result, 0)).text) $+($7,http://,$3,/,$4)
        .timer $+ $sockname off
        sockclose $sockname
        return
      }
      elseif ($bvar(&wiki, 0)) && ($bfind(&wiki, 1, <h2>Contents</h2>)) { CloseWikiError $sockname }                     
    }
  }
}
alias -l CloseWikiError {
  var %sockname $1
  tokenize 32 $sock($1).mark
  $1-2 $5-6 Sorry :(( Unable to Parse $+($7,http://,$3,/,$4)
  sockclose %sockname
  .remove $+(%sockname,.dat)
  return
}
alias -l fix&# { return $replace($regsubex($1-,/\&\#([0-9]{1,});/g,$UTF8(\t)),&quot;,",&amp;,&,&gt;,>,&lt;,<,&#39;,',|,,$chr(9),$chr(32)) }
alias -l UTF8 {
  var %x $base($1,10,2),%y $len(%x)
  if ($1 < 161) { return $chr($1) }
  elseif (%y < 12) { return $+($shift(11000000,$left(%x,-6)),$shift(10000000,$right(%x,6))) }
  elseif (%y < 17) { return $+($shift(11100000,$left(%x,-12)),$shift(10000000,$mid(%x,-12,6)),$shift(10000000,$right(%x,6))) }
  elseif (%y < 22) {
    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)))
  }
}
alias -l shift {
  if ($2) { return $chr($base($+($left($1,$+(-,$len($2))),$2),2,10)) }
  else { return $chr($base($1,2,10)) }
}
alias -l Put {
  if (!$regex($1,/(\.|^)(msg|notice|echo)$/Si)) || (!$3) { echo -st **Put error** Syntax /Put msg #channel text - or - /Put notice nickname text  | return }
  tokenize 32 $regsubex($1-,/([$\|%\[\]\}\{][^\s]*)/g,$+($chr(2),$chr(2),\t))
  var %tokens $0, %Tstart 3, %Dtimer 1000, %prefix $gettok($sock($sockname).mark,5-6,32)
  if ($timer($+(Put,$2,$network)).secs) { %Dtimer = $calc($v1 * 1000) }  
  while ($len($($+($,%Tstart,-,%tokens),2)) > $calc(420 - $len(%prefix))) {
    dec %tokens
    if ($len($($+($,%Tstart,-,%tokens),2)) <= $calc(420 - $len(%prefix))) {
      .timer -m 1 %Dtimer $1-2 $+(%prefix,$($+($,%Tstart,-,%tokens),2)))
      inc %Dtimer 1500
      %Tstart = $calc(%tokens + 1)
      %tokens = $0
    }
  }
  .timer -m 1 %Dtimer $1-2 $+(%prefix,$($+($,%Tstart,-,%tokens),2)))
  .timer $+ $+(Put,$2,$network) -m 1 $calc(%Dtimer + 1000) noop 
}
alias -l fixurl return $regsubex($strip($1-),/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2))
alias -l binstrip {
  while ($bfind($1, 1 ,<)) && ($bfind($1, 1, >)) {
    var %first = $bfind($1, 1, <), %last $calc($bfind($1, 1, >) - $bfind($1, 1, <) + 1)
    noop = $bremove($1, $bvar($1, %first, %last).text)
  }
  while ($bfind($1, 1 ,$chr(91))) && ($bfind($1, 1, $chr(93))) {
    %first = $bfind($1, 1, $chr(91))
    %last = $calc($bfind($1, 1, $chr(93)) - $bfind($1, 1, $chr(91)) + 1)
    noop = $bremove($1, $bvar($1, %first, %last).text)
  }
  return $1
}
;bremove by jaytea
alias bremove {
  if (!$isid) || ($0 < 2) || (!$regex($1,/^&[^ ]+$/)) {
    echo -ces i * Invalid parameters: $!bremove
    return
  }
  if ($bvar($1,0)) {
    var %x = 1
    while (%x < $0) {
      inc %x
      var %i = 1, %t = $eval($ $+ %x,2) $chr(32)
      while ($bfind($1,%i,$left(%t,-2)) [ $+ [ $iif($prop == text,.text) ] ]) {
        var %i = $v1, %p = $iif($prop != text && $regex(bremove,%t,/^ *\d+(?: +\d+)* *$/i),$numtok(%t,32),$len($mid(%t,3))) + %i
        if (%p <= $bvar($1,0)) bcopy -c $1 %i $1 %p -1
        elseif ($calc(%i - 1)) bset -c $1 $v1 $bvar($1,$v1)
        else bunset $1
      }
      inc %x 2
    }
  }
  return $1
}
alias -l bintween {
  var %count = 1, %mark = 0, %mark2 = 0
  while (%count <= $4) {
    if ($bfind($1, %mark2, $2).text) {
      %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
      if ($bfind($1, %mark, $3).text) {
        %mark2 = $bfind($1, %mark, $3).text
      }
      else { return 0 } 
    }
    else { return 0 }
    inc %count
  }
  return $bvar($1, $iif(%mark > 0,%mark,1), $iif($calc(%mark2 - %mark) < 4130,$calc(%mark2 - %mark),4130)).text
}

Comments

Sign in to comment.
Somsubhra1   -  Jan 19, 2016

Doesn't return the results to me.
[11:15:04] +wiki
[11:15:06] Somsubhra1 has activated the Wikipedia script for #Coding .
[11:15:09] !wiki football
[11:15:10] -RadishBot- Wikipedia Searching For: football
[11:15:11] -RadishBot- Wikipedia Sorry - Cannot find football

I added this... http://pastebin.com/3r3zhbCC . Nothing should be wrong. I use mirc version 7.38

Thanks.

 Respond  
DalnetRefugee   -  Mar 03, 2014

sweet! It works but load 50$ CPU from time 2 time and when i change %langcode to FR ..

 Respond  
^WeSt   -  Oct 17, 2013

mIRC stucks after the !wiki C++ command, i break the line and lines was:

  • Break: command halted (line 97, script1.ini)
  • Break: command halted (line 159, script1.ini)

  • Thanks!
ProIcons  -  Nov 17, 2013

Maybe url needs URL Encode, since ++ can be interpreted as a "Space" character in the url.

Sign in to comment

cptpan   -  Sep 28, 2013

This doesn't return anything for me.

FordLawnmower  -  Oct 04, 2013

@cptpan I just tested and this script is still working.
Did you activate it for the channel (+wiki) ?

cptpan  -  Oct 05, 2013

lol derp. Fixed. Might be worth adding that to the writeup on hawkee.

Sign in to comment

RIcko   -  Jun 27, 2012

Reloaded the script again and it worked, but i guess 2 long results are considered too much :/

 Respond  
FordLawnmower   -  Jun 26, 2012

I can find no issues with this script:

[14:06:00] <@Ford_Lawnmower> +wiki
[14:06:00] Ford_Lawnmower has activated the Wikipedia script for #FordIRC .
[14:06:07] <@Ford_Lawnmower> @wiki fire
[14:06:07] Wikipedia Searching For: fire
[14:06:12] Wikipedia Fire is the rapid oxidation of a material in the exothermic chemical process of combustion, releasing heat, light, and various reaction products. Slower oxidative processes like rusting or digestion are not included by this definition. http://en.wikipedia.org/wiki/Fire

 Respond  
RIcko   -  Jun 26, 2012

Amazing snippet and work, but the link is broken and needs an update =]

 Respond  
FordLawnmower   -  Apr 15, 2011

Np :)

 Respond  
Ruudjjuhh   -  Apr 15, 2011

@FordLawnmower

Thanks it worked \o//

Cheers

 Respond  
FordLawnmower   -  Apr 15, 2011

@Ruudjjuhh Yes, it's in the setup at the top of the script.
Just change:

var %langcode en

To:

var %langcode nl
 Respond  
Ruudjjuhh   -  Apr 15, 2011

Is there a way to change the result language?
So that it use the dutch wikipedia. nl.wikipedia.org

Thnx in advance!

 Respond  
Slyvar   -  Mar 16, 2011

yes, Remotes :D

 Respond  
SkEmO   -  Mar 16, 2011

Where do I load this script? o.O Remotes?

 Respond  
Slyvar   -  Mar 09, 2011

very easy to make on PS

 Respond  
Slyvar   -  Mar 09, 2011

yes

 Respond  
FordLawnmower   -  Mar 09, 2011

Thanks Slyvar :)
I like your mIRC icon. Did you make it ?

 Respond  
Slyvar   -  Mar 09, 2011

Awesome

 Respond  
FordLawnmower   -  Jan 25, 2011

I still have this working fine Orolo.
To activate this script you must type +wiki in each channel you want to use the script.(requires ops)
If this doesn't help, please post a more specific description of your problem.

 Respond  
Orolo   -  Jan 25, 2011

Looks like it stopped working

 Respond  
FordLawnmower   -  Jul 05, 2010

Thanks Kingc44 :) Keep at it. I'm sure you'll get there soon.

 Respond  
Kingc44   -  Jul 05, 2010

@Jethro_:
I use version 6.2 for my bot because I also use an add-on which only works with version 6.2.

@FordLawnmower:
You sure are an elite scripter, all your scripts are just awesome and very useful. I wish one day I can make scripts like the ones you make :)

 Respond  
FordLawnmower   -  Jul 05, 2010

Fixed.

 Respond  
Jethro   -  Jul 05, 2010

the code from the top of the page doesn't seem to want to work with neither version 6.2 nor version 6.35.You have to wait for Ford to take note of this issue. Why are you still using 6.20? Version 6.20 won't work correctly with the script anyway. Until Ford fixes it, you need to stick with the latest version, or else you'll get an error like the user SnoooP did.

 Respond  
Kingc44   -  Jul 05, 2010

Thanks Jethro_, the one from the pastebin link works fine with mIRC 6.35 however the code from the top of the page doesn't seem to want to work with neither version 6.2 nor version 6.35.

 Respond  
Jethro   -  Jul 05, 2010

Confirmed, the current version doesn't respond to trigger anymore for some reason under version 6.35.

Kingc44, use the original version. It works perfectly without an issue:

http://pastebin.com/f132547f7

It still requires that you have at least the version 6.32 to work. I suggest that you upgrade to the latest one available today.

 Respond  
Kingc44   -  Jul 05, 2010

On quick question FordLawnmower: does this work with mIRC 6.2? Cause its just not working for me I type @wiki aerosmith and !wiki aerosmith and nothing happens :/

 Respond  
FordLawnmower   -  May 26, 2010

Thanks WebGeeks :)

 Respond  
WebGeeks   -  May 26, 2010

Amazing Script!

 Respond  
FordLawnmower   -  Apr 03, 2010

Remade this script to be much more tolerant of typos and CASE errors.
Added google site search to assure a decent result ratio.
Added simple setup so you can change logo, colors, language, etc.
Added bread,bwrite operations to prevent data loss.
Example Output:
20:23:49 @wiki aerosmith
20:23:49 Wikipedia Searching For: aerosmith
20:23:52 Wikipedia Aerosmith is an American hard rock band sometimes referred to as "The Bad Boys from Boston" and "America's Greatest Rock and Roll Band". Their style which is rooted in blues-based hard rock has come to also incorporate elements of pop heavy metal and rhythm and blues and has inspired many subsequent rock artists. The band was formed in Boston Massachusetts in 1970. Guitarist
20:23:53 Joe Perry and bassist Tom Hamilton originally in a band together called the Jam Band met up with singer Steven Tyler drummer Joey Kramer and guitarist Ray Tabano and formed Aerosmith. In 1971 Tabano was replaced by Brad Whitford and the band began developing a following in Boston. http://en.wikipedia.org/wiki/Aerosmith

 Respond  
SnoooP   -  Mar 22, 2010

Ok, thanks i'll update soon..

That line number totally confused me lol, I was like, am I totally stupid or what haha?

 Respond  
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.