Shoutbox

[Help] Replacing Text Using Scripts (I think I'm dumb lol) - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Help] Replacing Text Using Scripts (I think I'm dumb lol) (/showthread.php?tid=63077)

[Help] Replacing Text Using Scripts (I think I'm dumb lol) by Keikonium on 07-11-2006 at 10:51 PM

Here is the code I am using:

code:
function OnEvent_ChatWndSendMessage(ChatWnd, sMessage)
{
  if(sMessage == "hye");
{
  strReplace("hye" == "hey");
}
}


This shall be my first useful script (only other one I made was a popup toast that said "hello" lol).

This however, doesn't work :(. I have the scripting documentation open, but its sort of confusing me.

I want my script to replace "hye" with "hey". It shouldn't be that hard (I think :P), but I have nooo idea what I am doing wrong @_@. Some help :S?
RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by noroom on 07-11-2006 at 10:53 PM

code:
function OnEvent_ChatWndSendMessage(ChatWnd, sMessage)
{
  if(sMessage == "hye");
{
  return "hey";
}
}

Read a few tutorials for JScript, or even Java/Javascript. They help a lot.
RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Joereynolds89 on 07-11-2006 at 11:11 PM

how can u do this with numerous letters instead of words, for example i want a simple function that can change a to A, b to B, c to C in ever line as many times as it occurs, for an example as ive shown above make the entire line from lower to upperclass :D thanks for any help


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Keikonium on 07-11-2006 at 11:16 PM

I just figured it out :). I had my code all wrong >_>.

I can now replace words, letters, symbols, anything... with anything else :).

I am creating a script for this thread: Click Here

It is almost done :). Just need to find good replacements for each letter of the english alphabet, and I will be good to go. Then I can work on a script for me :).

@Joereynolds89: This is quite simple (after you know how to do it :S. And I had no clue like 5 minutes ago lol). Use this code:

code:
function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
sMessage = sMessage.replace("a","A");
sMessage = sMessage.replace("b","B");
...
sMessage = sMessage.replace("y","Y");
sMessage = sMessage.replace("z","Z");
return sMessage;
}


Just do it for each letter of the alphabet :).
RE: RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by jmccarroll on 07-11-2006 at 11:17 PM

quote:
Originally posted by Joereynolds89
how can u do this with numerous letters instead of words, for example i want a simple function that can change a to A, b to B, c to C in ever line as many times as it occurs, for an example as ive shown above make the entire line from lower to upperclass :D thanks for any help

Caps Lock?
RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Joereynolds89 on 07-11-2006 at 11:17 PM

@ Keikonium
thankyou soo much :D

EDIT: i did it but it only works for the first a, so if i put a i get A but if i put aaa i get Aaa :( any ideas?

@ jmccarroll
Yes, i could use caps lock but that wasnt my point, that was an example to explain what i wanted, what it will actually do is completely change the letter :P


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Keikonium on 07-11-2006 at 11:33 PM

I have no idea Joereynolds89 :S. I will look into it, but can't promise a solution :S. My script just blew up lol. I am not sure what I changed, but now it doesn't work at all >.<! I wish there was an undo button >_>.


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Joereynolds89 on 07-11-2006 at 11:37 PM

lol, i ended up just using quick texts until i no how :D then i can make it so every1 else can use :D


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Nathan on 07-11-2006 at 11:41 PM

quote:
Originally posted by Keikonium
I have no idea Joereynolds89 :S. I will look into it, but can't promise a solution :S. My script just blew up lol. I am not sure what I changed, but now it doesn't work at all >.<! I wish there was an undo button >_>.


Well if you hold Ctrl then press (or keep pressing) "z" then it will go back ;)
RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Silentdragon on 07-11-2006 at 11:46 PM

Hmm you can look at this if you want. I wrote it awhile ago, but decided not to release it. Anyway if you want to use it look at the Al Bhed talker in the talkers folder otherwise you can look at the code for your own idea.


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Joereynolds89 on 07-11-2006 at 11:57 PM

its a nice script, i like the jive talker :P haha, very funny :D


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by aNILEator on 07-12-2006 at 07:26 AM

OLD SCRIPT HERE, but it works :P

autocorrector

errrm yeah does what you want, would like to update it one day to have windows/boxs etc and replace words inline rather than after you've sent them but anyway, here is autocorrector

---------------------------------------------------------------------------

To add new words to the list whilst in messenger type

/script ac_add before after - for single word errors eg cheees -> cheese

/script ac_add "before word" "after word" - enclose with "speech marks" for corrections with spaces eg cheeseyfood -> cheesey food

simple :)

---------------------------------------------------------------------------

[Image: icon_flag13.gif]EN Version

[Image: icon_flag12.gif]PT Version
---------------------------------------------------------------------------

As i say though this isn't being developped anymore at the moment, sometime later in the future, maybe, but not now


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by aNILEator on 07-12-2006 at 07:29 AM

PT version


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Joereynolds89 on 07-12-2006 at 01:05 PM

Can somebody tell me how to modify this to repeat how ever many times the first letter appears, and also how to make it so it dosnt use the replacment if it detects www or http etc!
Im only using capitals as an example, in fact they are different symbols

Joe


code:
function OnEvent_Initialize(MessengerStart)
{
}
function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
sMessage = sMessage.replace("a","A");
sMessage = sMessage.replace("b","B");
sMessage = sMessage.replace("c","C");
sMessage = sMessage.replace("d","D");
sMessage = sMessage.replace("e","E");
sMessage = sMessage.replace("f","F");
sMessage = sMessage.replace("g","G");
sMessage = sMessage.replace("h","H");
sMessage = sMessage.replace("i","I");
sMessage = sMessage.replace("j","J");
sMessage = sMessage.replace("k","K");
sMessage = sMessage.replace("l","L");
sMessage = sMessage.replace("m","M");
sMessage = sMessage.replace("n","N");
sMessage = sMessage.replace("o","O");
sMessage = sMessage.replace("p","P");
sMessage = sMessage.replace("q","Q");
sMessage = sMessage.replace("r","R");
sMessage = sMessage.replace("s","S");
sMessage = sMessage.replace("t","T");
sMessage = sMessage.replace("u","U");
sMessage = sMessage.replace("v","V");
sMessage = sMessage.replace("w","W");
sMessage = sMessage.replace("x","X");
sMessage = sMessage.replace("y","Y");
sMessage = sMessage.replace("z","Z");
return sMessage;
}
function OnEvent_Uninitialize(MessengerExit)
{
}


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by noroom on 07-12-2006 at 01:31 PM

Don't Strings have a .toUpperCase() method?


RE: RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Joereynolds89 on 07-12-2006 at 01:37 PM

quote:
Originally posted by noroom
Don't Strings have a .toUpperCase() method?


Maybe you didnt read my post, you just read the code?

Someone help please :D
RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Keikonium on 07-12-2006 at 01:47 PM

for http and www just use:

sMessage = sMessage.replace("http","http");
and
sMessage = sMessage.replace("www","www");

It will see that the message has all of those grouped together, so it will make the group not change. It should work, but I haven't tested it >_>.

As for aaa --> AAA, I still haven't figured that out ^o). I was thinking perhaps:

sMessage = sMessage.replace("a"*,"A"*);

(using * as a random character, so whatever comes after the A will be capital also). This obviously didn't work, and I am sure the solution is simple, but I have no idea lol.

Hopefully somone more experienced in scripting comes along to help you out (Y).

EDIT:

How are you gonna handle links? Even if the "www" and "http" are correct, the address will still be incorrect will it not?


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Pai on 07-12-2006 at 01:55 PM

To replace all occurrences of one letter, you must use regular expressions. They come in a form of /pattern/switch , and you must use the g switch for global search (for more information on regular expression, google it)

so, the correct code for replacing all occurrences of "a" is:

sMessage = sMessage.replace(/a/g,"A");

(notice you don't use " " in a regular expression)


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Joereynolds89 on 07-12-2006 at 02:25 PM

quote:
Originally posted by Keikonium

How are you gonna handle links? Even if the "www" and "http" are correct, the address will still be incorrect will it not?

i didnt mean the http as in http i meant ignore all changed if http is part of it :( anyone no? ive seen it i just cant remember where! maybe if theres away to say if / is put before the sentence all changes are ignored?? the / isnt sent though

@Pai dosnt seem to work
RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Pai on 07-12-2006 at 05:48 PM

Then you did something wrong, because it does work ;)

Test case:

code:
    var str = "aaaaaaaaaaaaaaaaaaa"
    var str1 = str.replace("a","A");
    Debug.Trace(str1);
    var str2 = str.replace(/a/g,"A");
    Debug.Trace(str2);

returns:
code:
Aaaaaaaaaaaaaaaaaaa
AAAAAAAAAAAAAAAAAAA


-----------------------
to ignore links do something like
code:
if (!str.match('www') && !str.match('http')) { // it's not a link }

RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by aNILEator on 07-12-2006 at 06:22 PM

why don't you just simply edit the txt file in autocorrector.....?


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Silentdragon on 07-12-2006 at 07:25 PM

My script detects links and ignores them when apply the text modifications.


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Joereynolds89 on 07-12-2006 at 07:51 PM

because theres too much unneeded code, i thought creating a personal font would be sooo much easier :P

So what would the script be to ignore any changes if / , http or www is at the start and to change every instance of one letter to another :S pai just confused me, im an amateur scripter :P

EDIT: maybe something i did wrong last time, pais thing now works, ill test the ignorance if certain values are found next, but big thanx to pia :D

EDIT2:
How would i make it so changes dont occur if www, http or / is displayed anywhere within the message?? thanks

code:
function OnEvent_Initialize(MessengerStart)
{
}
function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
sMessage = sMessage.replace(/a/g,"A");
sMessage = sMessage.replace(/b/g,"B");
sMessage = sMessage.replace(/c/g,"C");
sMessage = sMessage.replace(/d/g,"D");
sMessage = sMessage.replace(/e/g,"E");
sMessage = sMessage.replace(/f/g,"F");
sMessage = sMessage.replace(/g/g,"G");
sMessage = sMessage.replace(/h/g,"H");
sMessage = sMessage.replace(/i/g,"I");
sMessage = sMessage.replace(/j/g,"J");
sMessage = sMessage.replace(/k/g,"K");
sMessage = sMessage.replace(/l/g,"L");
sMessage = sMessage.replace(/m/g,"M");
sMessage = sMessage.replace(/n/g,"N");
sMessage = sMessage.replace(/o/g,"O");
sMessage = sMessage.replace(/p/g,"P");
sMessage = sMessage.replace(/q/g,"Q");
sMessage = sMessage.replace(/r/g,"R");
sMessage = sMessage.replace(/s/g,"S");
sMessage = sMessage.replace(/t/g,"T");
sMessage = sMessage.replace(/u/g,"U");
sMessage = sMessage.replace(/v/g,"V");
sMessage = sMessage.replace(/w/g,"W");
sMessage = sMessage.replace(/x/g,"X");
sMessage = sMessage.replace(/y/g,"Y");
sMessage = sMessage.replace(/z/g,"Z");
return sMessage;
}
function OnEvent_Uninitialize(MessengerExit)
{
}

The replacment with capitals is just for example, there will be symbols here instead so no comments about using .toUppercase please

Joe
RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by segosa on 07-12-2006 at 09:35 PM

Here's code which will replace the letters for you. Might be a bit buggy as I didn't do extensive testing, however it works.

code:
function fuck_up_string(str)
{
    var a = [ 'a','B','C','D','e','F','G','H','i','J','K','L','M','N','o','P','Q','R','S','T','u','V','W','X','Y','Z' ];
    var o = "", c;
    str = str.toLowerCase();
    for (var i = 0; i < str.length; i++)
    {
        c = str.charCodeAt( i );
        if (c >= 97 && c <= 122)
            o += a[c - 97];
        else o += str.charAt( i );
    }
    return o;
}

You see that?

code:
var a = [ 'a','B','C','D','e','F','G','H','i','J','K','L','M','N','o','P','Q','R','S','T','u','V','W','X','Y','Z' ];

It will replace the letters a to z with the contents of that. As you can see in my testing I simply made the vowels lowercase. If I sent a message like "this is a test" I got "THiS iS a TeST".

RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Pai on 07-13-2006 at 12:43 AM

quote:
Originally posted by Joereynolds89
How would i make it so changes dont occur if www, http or / is displayed anywhere within the message?? thanks
You use:
code:

function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{

if (!sMessage.match('www') && !sMessage.match('http')) { // no link found, replace stuff

// here put the code that I showed you (that you used in your reply) or use segosa's (dunno if it works, just taking his word for it)

}

}


RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by segosa on 07-13-2006 at 08:54 AM

Try this:

code:
function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
    if (!sMessage.match('www') && !sMessage.match('http') && sMessage.charAt(0) != '/')
    {
        var a = [ 'a','B','C','D','e','F','G','H','i','J','K','L','M','N','o','P','Q','R','S','T','u','V','W','X','Y','Z' ];
        var o = "", c;
        str = str.toLowerCase();
        for (var i = 0; i < str.length; i++)
        {
            c = str.charCodeAt( i );
            if (c >= 97 && c <= 122)
                o += a[c - 97];
            else o += str.charAt( i );
        }
        return o;
    }
    return sMessage;
}

RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by Joereynolds89 on 07-13-2006 at 09:57 AM

lol thankyou Pai, finally got it all working :( if anyone actually wants to use it ill upload but all it does is change your font :S but i wanted it :P Thankyou to everyone that helped!

Segosa, i did all yours, i dont understand yours as i do Pai's :P but it didnt work :(

code:
function OnEvent_Initialize(MessengerStart)
{
}

function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
    if (!sMessage.match('www') && !sMessage.match('http') && sMessage.charAt(0) != '/')
    {
        var a = [ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' ];
        var o = "", c;
        str = str.toLowerCase();
        for (var i = 0; i < str.length; i++)
        {
            c = str.charCodeAt( i );
            if (c >= 97 && c <= 122)
                o += a[c - 97];
            else o += str.charAt( i );
        }
        return o;
    }
    return sMessage;
}
function OnEvent_Uninitialize(MessengerExit)
{
}

Remember capitals are only for example :D
RE: RE: [Help] Replacing Text Using Scripts (I think I'm dumb lol) by segosa on 07-13-2006 at 10:04 AM

quote:
Originally posted by Joereynolds89
lol thankyou Pai, finally got it all working :( if anyone actually wants to use it ill upload but all it does is change your font :S but i wanted it :P Thankyou to everyone that helped!

Segosa, i did all yours, i dont understand yours as i do Pai's :P but it didnt work :(

code:
function OnEvent_Initialize(MessengerStart)
{
}

function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
    if (!sMessage.match('www') && !sMessage.match('http') && sMessage.charAt(0) != '/')
    {
        var a = [ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' ];
        var o = "", c;
        str = str.toLowerCase();
        for (var i = 0; i < str.length; i++)
        {
            c = str.charCodeAt( i );
            if (c >= 97 && c <= 122)
                o += a[c - 97];
            else o += str.charAt( i );
        }
        return o;
    }
    return sMessage;
}
function OnEvent_Uninitialize(MessengerExit)
{
}

Remember capitals are only for example :D


Crap, sorry, I forgot to change something.

Since you've already got your own working, it won't matter, but here's the working code:

code:
function OnEvent_Initialize(MessengerStart)
{
}

function OnEvent_ChatWndSendMessage(pChatWnd, sMessage)
{
    if (!sMessage.match('www') && !sMessage.match('http') && sMessage.charAt(0) != '/')
    {
        var a = [ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' ];
        var o = "", c;
        var str = sMessage.toLowerCase();
        for (var i = 0; i < str.length; i++)
        {
            c = str.charCodeAt( i );
            if (c >= 97 && c <= 122)
                o += a[c - 97];
            else o += str.charAt( i );
        }
        return o;
    }
    return sMessage;
}
function OnEvent_Uninitialize(MessengerExit)
{
}