Advertisement
Guest User

Urban Dictionary Script by Ford_Lawnmower 11-05-14

a guest
Nov 5th, 2014
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 8.78 KB | None | 0 0
  1. ;Urban Dictionary Script by Ford_Lawnmower irc.GeekShed.net #Script-Help
  2. ;11-5-14
  3. menu Channel,Status {
  4.   .$iif($group(#Slang) == On,$style(1)) Slang Trigger
  5.   ..$iif($group(#Slang) == On,$style(2)) On: .enable #Slang
  6.   ..$iif($group(#Slang) == Off,$style(2)) Off: .disable #Slang
  7.   ..Add Badwords: {
  8.     if (!$hget(censored)) { hmake censored 5 }
  9.     $?="Enter the badword"
  10.     if ($!) {
  11.       if (!$hfind(censored,$!).data) {
  12.         hadd  censored $calc($hget(censored,0).item + 1) $!
  13.         echo -a $! added to badword list
  14.       }
  15.       else { echo -a $! is already in my database. }
  16.     }
  17.   }
  18.   ..Delete Badwords: {
  19.     $?="Enter the bad word or the item number!"
  20.     if ($!) {
  21.       if ($! isnum) && ($hget(censored,$!)) {
  22.         echo -a $hget(censored,$!) was deleted!
  23.         hdel  censored $!
  24.         halt
  25.       }
  26.       if ($! isalpha) && ($hfind(censored,$!).data) {
  27.         echo -a $! has been deleted from my database!
  28.         hdel censored $hfind(censored,$!).data
  29.       }
  30.       else { echo -a Can't find $! in my database. Try checking the list. }
  31.     }
  32.   }
  33.   ..List Badwords:censored.list
  34. }
  35. #Slang on
  36. On $*:Text:/^(\+|-|!|@)(Slang|ud).*/Si:#: {
  37.   var %action $regml(1)
  38.   if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@)/)) {
  39.     if (%action == +) {
  40.       if ($istok(%SlangChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is already running the Slang script }
  41.       else {
  42.         .enable #Slang
  43.         Set %SlangChanList $addtok(%SlangChanList,$+($network,$chan),32)
  44.         .msg $chan $nick has activated the Slang script for $chan .
  45.       }
  46.     }
  47.     else {
  48.       if (!$istok(%SlangChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is not running the Slang script }
  49.       else {
  50.         Set %SlangChanList $remtok(%SlangChanList,$+($network,$chan),1,32)
  51.         .msg $chan $nick has deactivated the Slang script for $chan .
  52.       }
  53.     }
  54.   }
  55.   elseif (!$timer($+(Slang,$network,$nick))) && ($istok(%SlangChanList,$+($network,$chan),32)) {
  56.     .timer $+ $+(Slang,$network,$nick) 1 6 noop
  57.     var %method $iif(%action == !,.msg $chan,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%|\+)/),.msg $chan,.notice $nick))
  58.     GetSlang %method $2-
  59.   }
  60. }
  61. #Slang end
  62. alias slang { GetSlang echo -a $1- }
  63. alias -l GetSlang {
  64.   var %sockname $+(SlangUD,$network,$2,$ticks)
  65.   var %SlangUD.url $iif($3,$replace($+(/define.php?page=,$iif($ceil($calc($3 / 7)),$v1,1),&term=,$iif($3 !isnum,$3-,$4-)),$chr(32),+),/random.php)
  66.   sockopen %sockname www.urbandictionary.com 80
  67.   ;sockmark %sockname $1-2 %SlangUD.url $iif($3 isnum,$iif($calc($3 % 7),$v1,7),1) 0 0
  68.   svar %sockname method $1-2
  69.   svar %sockname url %SlangUD.url
  70.   svar %sockname num $iif($3 isnum, $3, 1)
  71. }
  72. On *:sockopen:SlangUD*: {
  73.   if (!$sockerr) {
  74.     sockwrite -nt $sockname GET $svar($sockname,url) HTTP/1.1
  75.     sockwrite -n $sockname Host: www.urbandictionary.com
  76.     sockwrite -n $sockname $crlf
  77.   }
  78.   else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  79. }
  80. On *:sockread:SlangUD*: {
  81.   if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  82.   else {
  83.     var %SlangUD | sockread %SlangUD
  84.     if (Location: http://www.urbandictionary.com/define.php?term isin %SlangUD) {
  85.       GetSlang $svar($sockname,method) 1 $gettok(%SlangUD,-1,61)
  86.       sockclose $sockname
  87.       return
  88.     }
  89.     elseif (<div id='not_defined_yet'> isin %SlangUD) { $svar($sockname,method) Sorry that word has yet to be defined. }
  90.     elseif ($regex(%SlangUD,/<div\sclass=['"]ribbon)) {
  91.       svar $sockname div small
  92.     }  
  93.     elseif (($svar($sockname,div) == small) && ($regex(%SlangUD,/(^\d+)/))) {
  94.       svar $sockname itemnum $regml(1)
  95.       svar $sockname div noop
  96.     }
  97.     elseif ($regex(%SlangUD,/<title>Urban\sDictionary:\s(.*?)<\/title>/i)) {
  98.       $svar($sockname,method) 06Word -04 $censored($httpstrip($regml(1)))
  99.     }
  100.     elseif ($svar($sockname,num) == $svar($sockname,itemnum)) {
  101.       if ($regex(%SlangUD,/<div\sclass=['"]([^>]*)['"]>/i)) {
  102.         svar $sockname div $regml(1)
  103.       }
  104.       if ($svar($sockname,div) == meaning) {
  105.         var %definition $svar($sockname,definition)
  106.         svar $sockname definition $+($iif($+($svar($sockname,definition),$chr(32)),$v1),%SlangUD)
  107.         if (</div> isin %SlangUD) {
  108.           put $svar($sockname,method) 06Definition -04 $censored($replace($httpstrip($svar($sockname,definition)),$chr(13),$chr(32)))
  109.           svar $sockname div noop
  110.         }
  111.       }
  112.       if ($svar($sockname,div) == example) {
  113.         svar $sockname example $+($svar($sockname,example),$chr(32),%SlangUD)
  114.         if (</div> isin %SlangUD) {
  115.           put $svar($sockname,method) 06Example -04 $censored($replace($httpstrip($svar($sockname,example)),$chr(13),$chr(32)))
  116.           svar $sockname div noop
  117.         }
  118.       }
  119.       ;      if ($svar($sockname,div) == contributor) {
  120.       ;        svar $sockname contributor $+($svar($sockname,contributor),$chr(32),%SlangUD)
  121.       ;        if (</div> isin %SlangUD) {
  122.       ;          put $svar($sockname,method) 06Author -04 $censored($replace($httpstrip($svar($sockname,contributor)),$chr(13),$chr(32))) - $+(07,http://www.urbandictionary.com,$svar($sockname,url)))
  123.       ;          sockclose $sockname
  124.       ;          return
  125.       ;        }
  126.       ;      }
  127.     }
  128.   }
  129. }
  130. alias -l httpstrip { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x) | return $remove($replace(%x,&amp;,&,&quot;,",&gt;,>,&lt;,<),&nbsp;,&lt;) }
  131. alias -l Put {
  132.   if (!$regex($1,/(\.|^)(msg|notice|echo)$/Si)) || (!$3) { echo -st **Put error** Syntax /Put msg #channel text - or - /Put notice nickname text  | return }
  133.   tokenize 32 $fix&#($regsubex($1-,/([$\|%\[\]\}\{][^\s]*)/g,$+($chr(2),$chr(2),\t)))
  134.   var %tokens $0, %Tstart 3, %Dtimer 1500
  135.   if ($timer($+(Put,$2,$network)).secs) { %Dtimer = $calc($v1 * 1000) }  
  136.   while ($len($($+($,%Tstart,-,%tokens),2)) > 430) {
  137.     dec %tokens
  138.     if ($len($($+($,%Tstart,-,%tokens),2)) <= 430) {
  139.       .timer -m 1 %Dtimer $1-2 $+(04,$($+($,%Tstart,-,%tokens),2)))
  140.       inc %Dtimer 1500
  141.       %Tstart = $calc(%tokens + 1)
  142.       %tokens = $0
  143.     }
  144.   }
  145.   .timer -m 1 %Dtimer $1-2 $+(04,$($+($,%Tstart,-,%tokens),2)))
  146.   .timer $+ $+(Put,$2,$network) -m 1 $calc(%Dtimer + 1500) noop
  147. }
  148. alias  censored {
  149.   if (!$hget(censored)) { hmake censored 5 }
  150.   var %censored.string = $1-, %censored.words = $gettok($1-,0,32)
  151.   while %censored.words {
  152.     if ($hfind(censored,$left($gettok(%censored.string,%censored.words,32),4) $+ *,1,w).data) || ($hfind(censored,$gettok(%censored.text,%censored.word,32)).data) {
  153.       %censored.string = $replace(%censored.string,$gettok(%censored.string,%censored.words,32),!@#&)
  154.     }
  155.     dec %censored.words
  156.   }
  157.   return %censored.string
  158. }
  159. alias censored.list {
  160.   var %censored.counter = $hget(censored,0).item
  161.   while %censored.counter {
  162.     echo -a $hget(censored,%censored.counter).item $hget(censored,%censored.counter).data
  163.     dec %censored.counter
  164.   }
  165. }
  166. alias -l fix&# {
  167.   return $regsubex($regsubex($replace($regsubex($1-,/\&\#([0-9]{1,});/g,$utf8(\t)),&quot;,",&amp;,&,&gt;,>,&lt;,<,&#39;,',$chr(9),$chr(32)),$&
  168.     /([$\|%\[\]\}\{][^\s]*)/g,$+($chr(2),$chr(2),\t)),/\&\#x([0-9a-f]{1,});/gi,$H2U(\t))
  169. }
  170. alias -l UTF8 {
  171.   if ($version >= 7) return $chr($1)
  172.   elseif ($1 < 255) { return $chr($1) }
  173.   elseif ($1 >= 256) && ($1 < 2048) { return $+($chr($calc(192 + $div($1,64))),$chr($calc(128 + $mod($1,64)))) }
  174.   elseif ($1 >= 2048) && ($1 < 65536) { return $+($chr($calc(224 + $div($1,4096))),$chr($calc(128 + $mod($div($1,64),64))),$chr($calc(128 + $mod($1,64)))) }
  175.   elseif ($1 >= 65536) && ($1 < 2097152) {
  176.     return $+($chr($calc(240 + $div($1,262144))),$chr($calc(128 + $mod($div($1,4096),64))),$chr($calc(128 + $mod($div($1,64),64))),$&
  177.       $chr($calc(128 + $mod($1,64))))
  178.   }
  179. }
  180. alias -l div { return $int($calc($1 / $2)) }
  181. alias -l mod {
  182.   var %int $int($calc($1 / $2))
  183.   return $calc($1 - (%int * $2))
  184. }
  185. alias -l H2U { return $utf8($base($1,16,10)) }
  186. alias -l Svar {
  187.   var %sockname $1, %item $+($2,$1)
  188.   if ($isid) {
  189.     if ($regex(svar,$sock(%sockname).mark,/ $+ %item $+ \x01([^\x01]*)/i)) return $regml(svar,1)
  190.   }
  191.   elseif ($3)  {
  192.     var %value $3-
  193.     if (!$regex(svar,$sock(%sockname).mark,/ $+ %item $+ \x01/i)) { sockmark %sockname $+($sock(%sockname).mark,$chr(1),%item,$chr(1),%value) }
  194.     else { sockmark %sockname $regsubex(svar,$sock(%sockname).mark,/( $+ %item $+ \x01[^\x01]*)/i,$+(%item,$chr(1),%value)) }
  195.   }
  196. }
  197. On *:Unload: { hfree censored }
  198. On *:Start: {
  199.   unset %UDChanList
  200.   if (!$hget(censored)) { hmake censored 5 }
  201.   if ($isfile(censored.hsh)) { hload censored censored.hsh }
  202. }
  203. On *:Exit: { if ($hget(censored)) { hsave censored censored.hsh } }
  204. On *:Disconnect: { if ($hget(censored)) { hsave censored censored.hsh } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement