mIRC Home    About    Download    Register    News    Help

Topic Options
#246479 - 13/06/14 12:44 AM lmgtfy script
judge2020 Offline
Fjord artisan

Registered: 21/03/14
Posts: 215
Loc: USA
I am trying to make a simple script where is someone says "!lmgtfy [words]" is will make the question on lmgtfy.com (let me google that for you). The way it puts it together is fairly simple so i decided not to use their API or anything like that/ Here is the script:
Code:
on *:text:!lmgtfy*:#mark_paintball:{ msg # http://lmgtfy.com/?q= $+ $2 $+ $chr(37) $+ 20 $+ $3 $+ $chr(37) $+ 20 $+ (((etc))) }
The problem is 1. this takes long to type to 30/40 words and 2. if it's not that # of words it repeats %20 20 times or so. I know i could do it to where if Words is 3, 4, 5, etc but That is even longer.
Is there an easier way to do this and would it fix the %20 problem?
_________________________
#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball

Top
#246480 - 13/06/14 01:35 AM Re: lmgtfy script [Re: judge2020]
HadS Offline
Ameglian cow

Registered: 30/07/03
Posts: 40
Loc: Paris, France
Hi,

First of all to make this script correct, you need to convert the "[words]" in html format in order to deal with correct other langage characters like ,,, etc..
Look at this link for more precision click here

Secondly, for your repeats problem, you just need to create a loop and deal with tokens ($gettok, $numtok, etc).

$numtok(This is a test,32) <= return 4
$gettok(This is a test,1,32) <== return This

Deal with tokens in a loop is quite easy
Code:
;example
alias extoken {
  var %i = 1, %str = This is a test
  while ($gettok(%str,%i,32) != $null) {
    echo 2 -s word %i = $gettok(%str,%i,32)
   inc %i
  }
}


/extoken blah this is a test


Edited by HadS (13/06/14 01:37 AM)

Top
#246481 - 13/06/14 01:54 AM Re: lmgtfy script [Re: judge2020]
HadS Offline
Ameglian cow

Registered: 30/07/03
Posts: 40
Loc: Paris, France
I wrote this code wich works perfectly:
Code:
;url_code downloaded from http://www.mircscripts.org/showdoc.php?type=code&id=4448
alias url_encode {
  var %i = 1, %len = $len($1), %str
  while (%i <= %len) {
    var %char = $asc($mid($1,%i,1)), %i = %i + 1
    if (%char isnum 33-47) || (%char isnum 48-57) || (%char isnum 58-64) || (%char isnum 65-90) || (%char isnum 97-122) var %str = $+(%str,$chr(%char))
    elseif (%char < 128) var %str = $+(%str,%,$base(%char,10,16,2))
    elseif (%char < 2048) var %str = $+(%str,%,$base($calc(192 + $int($calc(%char / 64))),10,16,2),%,$base($calc(128 + (%char % 64)),10,16,2))
    elseif (%char < 65536) var %str = $+(%str,%,$base($calc(224 + $int($calc(%char / 4096))),10,16,2),%,$base($calc(128 + ($int($calc(%char / 64)) % 64)),10,16,2),%,$base($calc(128 + (%char % 64)),10,16,2))
    elseif (%char < 2097152) var %str = $+(%str,%,$base($calc(240 + $int($calc(%char / 262144))),10,16,2),%,$base($calc(128 + ($int($calc(%char / 4096)) % 64)),10,16,2),%,$base($calc(128 + ($int($calc(%char / 64)) % 64)),10,16,2),%,$base($calc(128 + (%char % 64)),10,16,2))
  }
  return %str
}
;example
on *:text:!lmgtfy ?*:#mark_paintball:{ 
   tokenize 32 $2-
  var %i = 1, %string = http://lmgtfy.com/?q=
  while ( [ $ $+ [ %i ] ] != $null) {
    %string = %string $+ $&
      $url_encode($replacex([ $ $+ [ %i ] ],$,% $+ 24,%,% $+ 25)) $+ $iif(%i < $0,+)
    inc %i
  }
  msg $chan %string
}


I have also changed the on *!:text:lmgtfy* for this one wich is errorless: !lmgtfy ?* in case of the user sends !lmgtfy with an empty string, or sends !lmgtfyblabla



Edited by HadS (13/06/14 02:17 AM)
Edit Reason: added $replacex for % and $ correct processing

Top