Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- if ($($+(%,wiki.,%ticks,.exact),2) != $null) {
- ;echo @Wiki- $+ $network 4Exact match for $($+(%,wiki.,%ticks,.exact),2) from $($+(%,wiki.,%ticks,.topic),2)
- %x GET $($+(%,wiki.,%ticks,.exact),2) HTTP/1.1
- }
- else {
- %x GET /wiki/Special:Search?search= $+ $($+(%,wiki.,%ticks,.topic),2) 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
- ;echo -a $bvar(&binvar2,1-).text
- if (*HTTP/1.1 302 Found* iswm $bvar(&binvar2,1-).text) && ($bfind(&binvar2,1,X-Varnish) != 0) {
- 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))
- wikicleanup %ticks
- sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
- halt
- }
- elseif (*- Search results - Wikipedia, the free encyclopedia</title>* 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
- }
- if ($bfind(&binvar2,1,may refer to) != 0) {
- ;echo @Wiki- $+ $network 4DISAMBIG
- $($+(%,wiki.,%ticks,.msgtype),2) 10Reached disambiguation page, view results:12 $+ $($+(%,wiki.,%ticks,.exact),2)
- .timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
- wikicleanup %ticks
- }
- elseif ($bfind(&binvar2,1,<p>) != 0) && ($bfind(&binvar2,1,</p>) != 0) {
- var %pos1 $bfind(&binvar2,1,<p>)
- var %pos2 $bfind(&binvar2,%pos1,</p>)
- var %out $bvar(&binvar2,$+(%pos1,-,$calc(%pos2 + 3))).text
- ;echo @Wiki- $+ $network 4Raw HTML:
- ;echo @Wiki- $+ $network %out
- var %out $nohtml($replace(%out,<b>,,</b>,,<i>,,</i>,))
- if ($numtok(%out,32) < 30) {
- var %out $gettok(%out,1-,32)
- }
- else {
- var %out $gettok(%out,1-27,32) $+ ...
- }
- $($+(%,wiki.,%ticks,.msgtype),2) $+(10,%out,12 ,$($+(%,wiki.,%ticks,.exact),2))
- wikicleanup %ticks
- .timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
- }
- }
- }
- alias wikicleanup {
- ;echo @Wiki- $+ $network Cleaning up
- .remove temp $+ $1
- bunset &t
- bunset &binvar2
- sockclose wiki. $+ $1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement