mIRC Home    About    Download    Register    News    Help

Print Thread
#246479 12/06/14 11:44 PM
Joined: Mar 2014
Posts: 215
J
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
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
judge2020 #246480 13/06/14 12:35 AM
Joined: Jul 2003
Posts: 40
H
Ameglian cow
Offline
Ameglian cow
H
Joined: Jul 2003
Posts: 40
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

Last edited by HadS; 13/06/14 12:37 AM.
judge2020 #246481 13/06/14 12:54 AM
Joined: Jul 2003
Posts: 40
H
Ameglian cow
Offline
Ameglian cow
H
Joined: Jul 2003
Posts: 40
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


Last edited by HadS; 13/06/14 01:17 AM. Reason: added $replacex for % and $ correct processing

Link Copied to Clipboard