Shoutbox

[Request] Alert on specific message - 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: [Request] Alert on specific message (/showthread.php?tid=76172)

[Request] Alert on specific message by glargle on 07-17-2007 at 11:51 PM

I have no knowledge  of scripting, so all my attempts have failed.

I'm looking for a script, that when a specific word is received in a message, a sound will play. I have all sounds turned off in WLM so I want a sound to be played on certain occasions.

I'm sure this is a fairly simple script so can anybody help?


RE: [Request] Alert on specific message by roflmao456 on 07-18-2007 at 12:25 AM

:banana:Welcome to the forum!:banana:

code:
var word = new Array(
"your",
"words",
"here"
);

function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){
if(Origin != Messenger.MyName){
for(i=0;i<word.length;i++){
if(Message.search(word[i]) != -1){
MsgPlus.PlaySound("path\\to\\sound\\file");
}
}
}
}

i'm not sure if that will work but you can try.

btw, for a single backslash ( \ ) you have to put two. so

\\

will result in a single backslash ;)
RE: [Request] Alert on specific message by glargle on 07-18-2007 at 12:44 AM

Thanks alot man, but it doesn't work :(

All I need to edit is the path to the audio file, right? I've tried .wav and .mp3 with the double \


RE: [Request] Alert on specific message by roflmao456 on 07-18-2007 at 01:32 AM

could you get the text from the debug window?

(make sure the checkbox (debugging options) is checked in the scripts preferences)


RE: [Request] Alert on specific message by glargle on 07-18-2007 at 01:45 AM

Script has been stopped
Script is starting
Script is now loaded and ready

:\


RE: [Request] Alert on specific message by roflmao456 on 07-18-2007 at 02:30 AM

quote:
Originally posted by glargle
Script has been stopped
Script is starting
Script is now loaded and ready

:\

when you receive a message lol :P
RE: [Request] Alert on specific message by glargle on 07-18-2007 at 03:10 AM

Function called: OnEvent_ChatWndReceiveMessage


RE: [Request] Alert on specific message by roflmao456 on 07-18-2007 at 03:42 AM

quote:
Originally posted by glargle
Function called: OnEvent_ChatWndReceiveMessage
nothing after?
RE: [Request] Alert on specific message by glargle on 07-18-2007 at 04:33 AM

Nope. I get that message everytime I send or receive a message.


RE: [Request] Alert on specific message by markee on 07-18-2007 at 04:45 AM

quote:
Originally posted by roflmao456
:banana:Welcome to the forum!:banana:
code:
var word = new Array(
"your",
"words",
"here"
);

function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){
if(Origin != Messenger.MyName){
for(i=0;i<word.length;i++){
if(Message.search(word[i]) != -1){
MsgPlus.PlaySound("path\\to\\sound\\file");
}
}
}
}

i'm not sure if that will work but you can try.

btw, for a single backslash ( \ ) you have to put two. so

\\

will result in a single backslash ;)
Your code can be made a little better, the use of a regular expression means that you only have to make the one if statement rather than 2 and the for statement.  Also you might want to look at using things other than a search method because it doesn't give much that you can work with after (I know there was nothing in this case but it can be useful later and a good habit to get into).
code:
var word = new Array(
"your",
"words",
"here"
);
var re = RegExp("\b"+word.join("\b|\b")+"\b","i");

function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){
if(Origin != Messenger.MyName && re.test(Message)){
MsgPlus.PlaySound("path\\to\\sound\\file");
}
}

This code does exactly the same as roflmao456's code anyway, I think the problem might be in the path that you are making.  Please make sure that you use the \\ and that you start from the drive letter and double check that the file exists where you are looking.

If that doesn't work then please try this code:
code:
MsgPlus.PlaySound("path\\to\\sound\\file");
This is just to make sure that the sound file is work and that you have the right path to it.  It should make the sound when you save the script.  I advise you to get rid of this once it has worked or else every time you start messenger then you will hear the sound.

If you keep having troubles can you please copy and paste the path that you are using to the file so that we can just double check you are doing it correctly and also make sure that you have your sound on (you'd be amazed at how many people don't think of the little things).
RE: [Request] Alert on specific message by glargle on 07-18-2007 at 04:58 AM

Thanks, but I'm still not getting any sound. I'm using:

code:
MsgPlus.PlaySound("C:\\Program Files\\Messenger Plus! Live\\Scripts\\Wakealert\\wakeupfaggot.mp3");

RE: RE: [Request] Alert on specific message by davidpolitis on 07-18-2007 at 06:39 AM

quote:
Originally posted by glargle
Thanks, but I'm still not getting any sound. I'm using:

code:
MsgPlus.PlaySound("C:\\Program Files\\Messenger Plus! Live\\Scripts\\Wakealert\\wakeupfaggot.mp3");

Try the following :P

code:
MsgPlus.PlaySound("\C:\\Program Files\\Messenger Plus! Live\\Scripts\\Wakealert\\wakeupfaggot.mp3");

You could also use a toast to play the sound and say what word from the array the received message contained if you really want to :P
RE: [Request] Alert on specific message by Spunky on 07-18-2007 at 12:25 PM

Just to explain... a relative path is relative to the scripts folder so it would be easier to copy the sound file there and just use the filename in the script.

An absoloubte path is from the drive letter, but to show the script that it's an absoloubte path, you need to put a single slash at the beginning of the path.


RE: RE: [Request] Alert on specific message by davidpolitis on 07-18-2007 at 01:36 PM

quote:
Originally posted by SpunkyLoveMuff
Just to explain... a relative path is relative to the scripts folder so it would be easier to copy the sound file there and just use the filename in the script.

An absoloubte path is from the drive letter, but to show the script that it's an absoloubte path, you need to put a single slash at the beginning of the path.

:$ sorry, knew you could do that with toasts, but not with this, not really good at JS.
RE: [Request] Alert on specific message by glargle on 07-18-2007 at 02:50 PM

I'm messing up something because it's still not working. I've tried the relative and absoloute things but still fails :\

Here's the whole thing, I must be doing something wrong.

code:
var word = new Array(
"!wake",
"!wakeup",
"!wakewake"
);
var re = RegExp("\b"+word.join("\b|\b")+"\b","i");

function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){
if(Origin != Messenger.MyName && re.test(Message)){
MsgPlus.PlaySound("\C:\\Program Files\\Messenger Plus! Live\\Scripts\\Wakealert\\wakeupfaggot.mp3");
}
}

RE: [Request] Alert on specific message by Spunky on 07-18-2007 at 03:47 PM

use

code:
MsgPlus.ScriptFilesPath+"\\wakeupfaggot.mp3"

and place the mp3 in the script folder (Wakealert folder)
RE: [Request] Alert on specific message by glargle on 07-18-2007 at 04:00 PM

Still nothing. Does it work for you guys or is it a problem on my end?


RE: [Request] Alert on specific message by Spunky on 07-18-2007 at 04:20 PM

try seeing what the function returns...

code:
Debug.Trace(MsgPlus.PlaySound("wakeupfaggot.mp3));
If it's false, then it won't play... I just tried it a few times with a test script and it works when it wants tbh

RE: [Request] Alert on specific message by glargle on 07-18-2007 at 04:28 PM

When I change that, the debugger says

code:
Error: Expected ')' (code: -2146827282)
       File: Wakealert.js. Line: 11.

I don't know what I'm messing up.

RE: [Request] Alert on specific message by Spunky on 07-18-2007 at 05:14 PM

my mistake...

forgot the end quote around the file name :$


RE: [Request] Alert on specific message by glargle on 07-18-2007 at 05:35 PM

Yeah, it says false.


RE: RE: RE: [Request] Alert on specific message by CookieRevised on 07-18-2007 at 10:46 PM

quote:
As you can read in the Official Scripting Documentation

Syntax
[boolean] PlaySound(
    [string] SoundFile
    [number,optional] MaxPlayTime
);

Parameters: SoundFile
[string] Path to the sound file to play. The path is relative to the script's directory by default, to override this behavior, prefix the path with "\". Example: "\C:\directory\sound.mp3". If this string is empty, the current sound playing is stopped and the function returns.

+

quote:
Originally posted by roflmao456
btw, for a single backslash ( \ ) you have to put two. so

\\

=

MsgPlus.PlaySound("\\C:\\Program Files\\Messenger Plus! Live\\Scripts\\Wakealert\\wakeupfaggot.mp3");

or if you put the mp3 in the same directory as your script:
MsgPlus.PlaySound("wakeupfaggot.mp3");


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

PS: glargle, make also sure the MP3 is an actual proper MP3. Also, Plus! can play many formats, but it is quite possible that some subformats can't be played.
RE: [Request] Alert on specific message by Spunky on 07-19-2007 at 12:27 AM

quote:
Originally posted by CookieRevised
PS: glargle, make also sure the MP3 is an actual proper MP3. Also, Plus! can play many formats, but it is quite possible that some subformats can't be played.

I thought about the file format, but wasn't sure. I tried PlaySound with the ScriptFilesPath and it worked occasionally... Does that still have to have the \\ at the start or not?

RE: [Request] Alert on specific message by glargle on 07-19-2007 at 01:14 AM

OK I'm confused now, it turns out it was the .mp3 that wouldn't play, because I tried using a .wav and it plays fine.

The problem is, the .wav plays when I put it in a script to just play that file, but when I put it in the Wakealert script, it won't play.

Edit: I got it to work with roflmao456's script. Thanks alot everyone!


RE: [Request] Alert on specific message by CookieRevised on 07-19-2007 at 09:47 AM

quote:
Originally posted by SpunkyLoveMuff
I thought about the file format, but wasn't sure. I tried PlaySound with the ScriptFilesPath and it worked occasionally... Does that still have to have the \\ at the start or not?
If you want the path to be absolute then yes, you need the have the \ character at the start of the path string. And to have a \ character in JScript you need to enter either the string "\\" or enter the character as a ascii code like "\x5C".

RE: [Request] Alert on specific message by markee on 07-19-2007 at 01:08 PM

quote:
Originally posted by CookieRevised
quote:
Originally posted by SpunkyLoveMuff
I thought about the file format, but wasn't sure. I tried PlaySound with the ScriptFilesPath and it worked occasionally... Does that still have to have the \\ at the start or not?
If you want the path to be absolute then yes, you need the have the \ character at the start of the path string. And to have a \ character in JScript you need to enter either the string "\\" or enter the character as a ascii code like "\x5C".
And this is why I think Patchou needs to amend the documentation to make it easier for new people to understand for this stuff to do with files.  He should at least put it in the remarks section, isn't that why it is there after all?
RE: [Request] Alert on specific message by CookieRevised on 07-19-2007 at 03:20 PM

In one way I totally agree.

Although knowing that the \ character is an 'escape' character used for entering literal characters or characters by their ascii code, etc is actually basic knowledge when you work with JScript (and many many other languages for that matter).

An example (where the double backslash is used) wouldn't hurt though.
But I think a "more in depth explaination" of the use of characters and stuff and especially the backslash in JScript is not on its place there; that belongs in the 'string' section in the Jscript documentation...



EDIT: Spelling mistake fixed. Thx markee, keep them coming ;)