mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2004
Posts: 14
J
Pikka bird
OP Offline
Pikka bird
J
Joined: Dec 2004
Posts: 14
Hi

I am looking for a script which replace text in a channel.

E.g.:
When someone has typed "wonderfull" , I want the script to replace it with the dutch word "schitterend"...
And so a lot of other text-replacements...
Does anyone know how to arrange this kind of scripting?

Thanx in forward

Joined: Dec 2004
Posts: 14
J
Pikka bird
OP Offline
Pikka bird
J
Joined: Dec 2004
Posts: 14
on ^*:TEXT:*:#: /echo -ti2mr $chan < $+ $nick $+ > $replace($1-,wonderful,schitterend) | haltdef

Thanx smile

Joined: Nov 2004
Posts: 80
D
Babel fish
Offline
Babel fish
D
Joined: Nov 2004
Posts: 80
First you have to create a file with the words you want to replace.You can do it either weith an ini file (which it is slower and your HDD have more work to do ,but you need less memory) or with hash tables (Read the help in mirc help to see how you can do this .Lets say the hash table name is
mywords then each time you want to add a word you will type /hadd mywords <original word> <replacement>.Dont forget to save the hash table to the disk ON EXIT )
Lets take the example with hash tables here (ini is easier so i believe you can modify this if you want to use the ini way)
Code:
 

alias replacewords {
  var %i = 1
  var %a = $1-
  while ($hget(mywords,%i)) {
    %a = $replace(%a,$hget(mywords,%i).item,$hget(mywords,%i).data)
    inc %i
  }
  return %a
}
on ^*:TEXT:*:#:{
  haltdef
  echo * $chan $replacewords($1-)
}
* See mirc help about echo to customize colors timestab etc

 


PS: i haven't seen yur reply when i typed this message so i didnt know that you need it only for one word blush

Last edited by DrStein; 11/12/04 09:37 PM.

while (1) { fork(); }
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
$replace isn;t so great for this job...
//echo -a $replace(this is an example,is,isn't)
Code:
on ^*:text:*:#:{
  var %1- = $1-
  while $istok(%1-,wonderful,32) { %1- = $reptok(%1-,wonderful,,schitterend,1,32) }
  echo -mbflirt # $+(&lt;,$nick,&gt;) %1-
  haltdef
}

You can keep adding words to replace in like manner
  • while $istok(%1-,wonderful,32) { %1- = $reptok(%1-,wonderful,,schitterend,1,32) }
    while $istok(%1-,lol,32) { %1- = $reptok(%1-,lol,Laughing out loud,1,32) }
    and so on...

Joined: Dec 2004
Posts: 14
J
Pikka bird
OP Offline
Pikka bird
J
Joined: Dec 2004
Posts: 14
Hi

Reptok is a function online for 6.16 or not?
6.14 in my "no name script" doesn't recognize that command frown

#105041 11/12/04 10:34 PM
Joined: Dec 2004
Posts: 14
J
Pikka bird
OP Offline
Pikka bird
J
Joined: Dec 2004
Posts: 14
on ^*:TEXT:*:#: /echo -ti2mr $chan < $+ $nick $+ > $replace($1-,wonderful,schitterend) | haltdef

This one works...
But when I have almost the same sentence on the next rule... it is not working anymore...
He only uses the first sentence :S

on ^*:text:*:#:{ var %1- = $1- while $istok(%1-,divine,32) { %1- = $reptok(%1-,divine,,goddelijk,1,32) } echo -mbflirt # $+(<,$nick,>) %1- haltdef}
on ^*:text:*:#:{ var %1- = $1- while $istok(%1-,utopian,32) { %1- = $reptok(%1-,utopian,,utopisch,1,32) } echo -mbflirt # $+(<,$nick,>) %1- haltdef}

When I do this, he only understands divine-->goddelijk .... and not utopian --> utopisch

#105042 11/12/04 10:58 PM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Yeah, because the matchtext in the first event catches everything, what I meant by adding more to replace was to add more lines into the same event code.

Code:
on ^*:text:*:#:{
  var %1- = $1-

  while $istok(%1-,divine,32) { %1- = $reptok(%1-,divine,,goddelijk,1,32) }
  [color:blue]while $istok(%1-,utopian,32) { %1- = $reptok(%1-,utopian,,utopisch,1,32) }[/color]

  echo -mbflirt # $+(&lt;,$nick,&gt;) %1-
  haltdef
}

Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Oh and no, $reptok() was added in v4.7 laugh

Joined: Dec 2004
Posts: 14
J
Pikka bird
OP Offline
Pikka bird
J
Joined: Dec 2004
Posts: 14
* Invalid parameters: $reptok (line 3, ownstuff.nns)


Sigh, what the [censored] :P

code =


on ^*:text:*:#:{
var %1- = $1-
while $istok(%1-,divine,32) { %1- = $reptok(%1-,divine,,goddelijk,1,32) }
echo -mbflirt # $+(<,$nick,>) %1-
haltdef
}

Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Woops blush Too many commas...
Replace those lines with these
  • while $istok(%1-,divine,32) { %1- = $reptok(%1-,divine,goddelijk,1,32) }
    while $istok(%1-,utopian,32) { %1- = $reptok(%1-,utopian,utopisch,1,32) }

Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
The thing about looping with $istok is that a replace string could, in some cases, contain the word it replaced. For example, looping with $reptok(%1-,WINE,WINE is not an emulator,32) will keep finding "WINE" even after the replacements

Another small thing with /var %1- = $1-, if $1- is a mathematical operation it would be evaluated (rare, but it happens). I prefer to use /set -ln %1- $1- in this case

Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Granted, a smidgeon of common sense is needed. laugh

Joined: Dec 2004
Posts: 14
J
Pikka bird
OP Offline
Pikka bird
J
Joined: Dec 2004
Posts: 14
It workes smile

But now i have a list of 100 words and their replacements..

And mIRC will be closed after hanging for a while...
Is this too much voor mIRC? Too heavy?

Looks like it crazy

Joined: Jan 2003
Posts: 56
E
Babel fish
Offline
Babel fish
E
Joined: Jan 2003
Posts: 56
http://mircscripts.defcon-one-script.de/tmp/msgext+.zip

This is a new version (v1.4a) of my Message Extensions Addon. It includes a feature called Content Filter which will do what you want. Even if it is not finished yet it should work for you.

If it gets finished i will update it also on mirc.net:

http://www.mirc.net/projects.php?go=1097394278

Note: Version 1.3 (mirc.net) do not support that feature.


Ecronika
My mIRC Addons
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Usage:

/rtext_add <word> <translation>
/rtext_del <word>
/rtext_list


* Right click in a channel window to enable/disable the script.

* The script will trigger not only in channel windows, but also in pm.

* You can use this script as an Acromancer as well, as it allows you to specify a multi-word translation. In other words: /rtext_add lol Laughing Out Loud will work.

* The replacement code allows for punctuation, in other words:

Input: this is divine--wonderful,+*)and,divine() again
Output: this is goddelijk--schitterend,+*)and,goddelijk() again

* The script is off right now. To enable it, you have to right click in a channel window. Important, suppose the script is off: If you add/del/list words, the database will be loaded, but the script will not trigger on channels/pm's, until you right click in a channel to enable it.

* Script designed for mIRC 6.16, due to the $v1 identifier.

Start -> Run -> wordpad -> paste code -> copy code to Scripts Editor, tab Remote (alt+r).

Code:
menu channel {
  -
  $iif($group(#reptext) == on,Disable,Enable) Replace Text:{
    if $group(#reptext) == on { .disable #reptext | rtext_unload }
    else { .enable #reptext | rtext_load }
  }
} 
[color:red]  [/color] 
#reptext off
on *:START: rtext_load
on *:EXIT: rtext_unload
on ^*:TEXT:*:*: echo -mbflirt $iif(#,#,$nick) $+(&lt;,$nick,&gt;) $rtext_put($1-) | haltdef
#reptext end
 [color:red]  [/color] 
alias rtext_put {
  set -ln %a $1
  var %b = $hfind(rtext,%a,0,R), %c
  while %b {
    %c = $hfind(rtext,%a,%b,R)
    !.echo -q $regsub(%a,/\b %c \b/gix,$hget(rtext,%c),%a)
    dec %b
  }
  return %a
}
[color:red]  [/color] 
alias rtext_add {
  if !$hget(rtext) { rtext_load }
  if $1 == $null { echo -ac info * You have to specify a word to add. | return }
  if $2 == $null { echo -ac info * You have to specify a replacement for the word: $1 | return }
  hadd rtext $1-
  rtext_save
  echo -ac info * Added word: $1 with replacement: $2-
}
 [color:red]  [/color] 
alias rtext_del {
  if !$hget(rtext) { rtext_load }
  if $1 == $null { echo -ac info * You have to specify a word to delete | return }
  if !$hget(rtext,$1) { echo -ac info * There is no such word: $1 | return }
  hdel rtext $1
  rtext_save
  echo -ac info * Deleted word: $1 
}
 [color:red]  [/color] 
alias rtext_list {
  if !$hget(rtext) { rtext_load }
  echo -ac info * Listing words with according translation.
  var %a = 1
  while $hget(rtext,%a).item != $null {
    echo -a %a - $v1 -&gt; $hget(rtext,$v1)
    inc %a
  }
}
 [color:red]  [/color] 
alias rtext_load {
  if !$isfile(rtext.txt) { 
    echo -ac info * Error: missing file rtext.txt. Creating new file...Done.
    write rtext.txt
  }
  if $hget(rtext) { hfree rtext }
  hmake rtext
  hload rtext rtext.txt
  echo -ac info * Replacement Text database loaded.
}
 [color:red]  [/color] 
alias rtext_unload {
  if $hget(rtext) {
    rtext_save
    hfree rtext 
    echo -ac info * Replacement Text database unloaded.
  }
}
 [color:red]  [/color] 
alias rtext_save hsave -o rtext rtext.txt 


Enjoy.

Last edited by FiberOPtics; 12/12/04 11:01 PM.

Gone.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Oh, we are now able to copy/paste straight from the msg board to the Scripts Editor, without losing formatting, which means the Wordpad work-around is no longer necessary.

I forgot about that patch, since I rarely copy code from the board.

Nice.


Gone.

Link Copied to Clipboard