Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;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 12
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;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),&,&),<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)),",",&,&,>,>,<,<,',',|,,$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
- }
Add Comment
Please, Sign In to add comment