mIRC Home    About    Download    Register    News    Help

Print Thread
Help with (simple) text substitution please! #260104 01/03/17 05:35 PM
Joined: Jul 2007
Posts: 45
B
beer Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2007
Posts: 45
Hi. I've tried looking up examples but haven't managed to figure this out:

I like incoming channel text that looks like this:
[12:57:00] <converter> ( USD ) ( CAD ) +0.31%

to instead look like this:
[12:57:00] <converter> [USD] [CAD] +0.31%

So basically I want to replace "( " with "[" and " )" with "]" on all text in that channel and nothing else. I assume it's done using `on ^*:text:*:#currency:{ ...something here... }`, but I can't figure out how/what.

Many thanks for your help!

Re: Help with (simple) text substitution please! [Re: beer] #260106 01/03/17 10:31 PM
Joined: Feb 2003
Posts: 2,661
Raccoon Online
Hoopy frood
Online
Hoopy frood
Joined: Feb 2003
Posts: 2,661
$replace($1-2,$chr(40) $+ $chr(32),[,$chr(32) $+ $chr(41),])

Sorry it's a visually ugly/confusing solution. Characters ( and ) and space sometimes need to be escaped with the $chr() command in order to be used in scripts. Indeed, [ and ] sometimes need to be escaped as [[ and ]], but not in this specific case.

I will leave the rest of the script up to you, as you're dealing with Halting Default Text to replace with your own text, which quickly spirals out of control. See the help file for suggestions. If you're going to "prettyify" or alter what somebody else says, there are a million things you'll need to account for when substituting their text: Nickname prefix, Nick Colors, Highlight Colors, all the /echo flags for message/flashing/timestamp, $strip, etc, and any other preferences that affect message output appearances.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: Help with (simple) text substitution please! [Re: Raccoon] #260108 02/03/17 12:48 AM
Joined: Jul 2007
Posts: 45
B
beer Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2007
Posts: 45
Thank you for your help Raccoon! The script I tried is:

Code:
on ^*:text:*:#zzzz:{
  if ($nick == mrc-test) {
    echo -t $chan $+(<,$nick,>) $replace($1-,$chr(40) $+ $chr(32),[,$chr(32) $+ $chr(41),])
    haltdef
  }
}


I created 2 connections to a server and joined test channel #zzzz with "mrc-test" and "beer". From mrc-test I wrote:
"abc ( TEST ) def"

In beer's window I saw:
"[16:28:45] <mrc-test> abc [TEST] def"

And in beer's server window I saw:
"[16:28:46] #ZZZZ Unknown command"

Using "$replace($1-2," wasn't working so I tried changing it to "$replace($1-," and that fixed it. But, I have no clue why the "#ZZZZ Unknown command" is happening. Any ideas?

Last edited by beer; 02/03/17 12:57 AM.
Re: Help with (simple) text substitution please! [Re: beer] #260109 02/03/17 01:18 AM
Joined: Feb 2003
Posts: 2,661
Raccoon Online
Hoopy frood
Online
Hoopy frood
Joined: Feb 2003
Posts: 2,661
I can't imagine where the error came from. It might be another script that's responsible. Sorry I gave you the wrong information with $1-2, that was silly of me.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: Help with (simple) text substitution please! [Re: Raccoon] #260110 02/03/17 01:28 AM
Joined: Jul 2007
Posts: 45
B
beer Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jul 2007
Posts: 45
I copy&paste'ed the code block, then deleted the original and now that `Unknown command` message is gone. Maybe some typo that got lost in the c&p? Weird but I'll take it! smile

Thanks again for your help Raccoon!