Shoutbox

Two questions: !remotecommand and Messenger.MyContacts - 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: Two questions: !remotecommand and Messenger.MyContacts (/showthread.php?tid=79940)

Two questions: !remotecommand and Messenger.MyContacts by kaourika on 12-11-2007 at 08:05 PM

I don't know JS at all, so as a learning experience I just started throwing things together, and naturally I've run into some questions.

First question
The following code works fine when I type !whatevercommand, but I also want my contacts to be able to type !whatevercommand, have the script respond to them, and increment the nbrPoke++.

code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
... there was a lot more in here; I'm just including the relevent stuff...
code:
        if(Message.substr(0,5).toLowerCase()=="!poke"){
        nbrPoke++;
        var z = Math.floor((Math.random()*(xArray.length-1)));
        return "*" + Messenger.MyName + " pokes with a pointy stick* \n" +xArray[z];
    }

Any tips on doing what I need to do? :D

Second question
I can't understand Messenger.MyContacts. For example, here,
code:
aArray[6] = "*" + Messenger.MyName +" attacks " + Messenger.MyContacts + "*";
MyName works fine, but Contacts just produces a blank space.
I read in the documentation that this could happen due to the contact being logged out, but that wasn't the case here.

Thanks for any help :D
RE: Two questions: !remotecommand and Messenger.MyContacts by markee on 12-12-2007 at 09:01 AM

for your first question, you should use the function OnEvent_ChatWndReceivedMessage(ChatWnd,Origin,Msg,Kind){

as for the second question, Messenger.MyContacts isn't a string so it doesn't work like that.  You need to do

code:
Messenger.MyContacts.GetContact("put their email here").Name
to return their display name (which i think is what you want).
RE: Two questions: !remotecommand and Messenger.MyContacts by kaourika on 12-13-2007 at 12:31 AM

Thanks for the help, Markee. =)

I tried putting in function OnEvent_ChatWndReceivedMessage(ChatWnd,Origin,Msg,Kind){ instead, and after doing so, that part of the script completely stops working(!command will simply show up as !command, for both sides of the conversation).
I figured it must be a conflict with some other part of my script, so I systematically removed all of those other parts, and tested without each one, but it didn't fix the problem.

Here is the relevent code section:

code:
    //// Actions
function OnEvent_ChatWndReceivedMessage(ChatWnd,Origin,Msg,Kind){
        if(Message.substr(0,8).toLowerCase()=="!petrafi"){
        nbrPet++;
        var h = Math.floor((Math.random()*(dArray.length-1)));
        return "*" + Messenger.MyName + " pets Rafeal* \n" +dArray[h];
    }
    }
    //// End Actions

There were more !commands, but I temporarily removed them so they wouldn't complicate my diagnosis. Anyway, I can't seem to find the problem with it =/

The display name was indeed what I was after. :D However, with that code, won't it only work with one person, the person whose email I define? If it's possible and not too horribly complex, I was trying to make the script adapt to whoever I was talking to at the time.
RE: Two questions: !remotecommand and Messenger.MyContacts by ddunk on 12-13-2007 at 12:40 AM

There's a couple problems.

First off, the event is "onEvent_ChatWndReceiveMessage" rather than "onEvent_ChatWndReceivedMessage".

Also, you have

code:
function OnEvent_ChatWndReceivedMessage(ChatWnd,Origin,Msg,Kind){
if(Message.substr(0,8).toLowerCase()=="!petrafi"){
So "Message" is undefined. So either change "Message" to "Msg" or "Msg" to "Message" and that part of the code should be just fine. :)
RE: Two questions: !remotecommand and Messenger.MyContacts by kaourika on 12-13-2007 at 01:19 AM

Ah! Thank you!! Now the script is actually attempting a return instead of just displaying the raw !command. I'm glad I don't have to go searching other chunks of the code for the problem.
However, it seems there's still something wrong here... D:
As you suggested, I changed it to

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,Kind){

        if(Message.substr(0,8).toLowerCase()=="!petrafi"){
        nbrPet++;
        var h = Math.floor((Math.random()*(dArray.length-1)));
        return "*" + Messenger.MyName + " pets Rafeal* \n" +dArray[h];
    }
But now it attempts to shave the response to 8 characters, I guess because of "(Message.substr(0,8)"... This is the return I'm getting in the conversation window (My name right now being Kao):
quote:
Kao says:
*Kao pet

It didn't have that problem when I was using "function OnEvent_ChatWndSendMessage." The Message.substr(0,8) is just supposed to apply to the raw !command, not the return, so that's weird...

Also, for my contact, when they say !petrafi, it executes the script in my view of the conversation, but in theirs, it still just says !petrafi. I hope there's a way around that! =/

Thanks for the continuing help! :3
RE: Two questions: !remotecommand and Messenger.MyContacts by pollolibredegrasa on 12-13-2007 at 01:29 AM

I think the problem is that the message you return in the ChatWndReceiveMessage event cannot be longer than the original message, or it just gets truncated. There's no way round this to my knowledge I'm afraid, as it's a technical limitation of Plus.


RE: Two questions: !remotecommand and Messenger.MyContacts by kaourika on 12-13-2007 at 01:44 AM

...Crap. :|

So... If I just want both people in a conversation to be able to type !command, and have text return based on that... there's really no way at all to do that? Or am I just trying to go about it in the wrong way?

Argh D: *pulls hair*


RE: Two questions: !remotecommand and Messenger.MyContacts by ShawnZ on 12-13-2007 at 01:46 AM

quote:
Originally posted by kaourika
...Crap. :|

So... If I just want both people in a conversation to be able to type !command, and have text return based on that... there's really no way at all to do that? Or am I just trying to go about it in the wrong way?

Argh D: *pulls hair*

when you return from "chatwndreceivemessage", you're editing their text as it appears to you, not sending another message back to them.
RE: Two questions: !remotecommand and Messenger.MyContacts by kaourika on 12-13-2007 at 01:55 AM

Ah! Okay, I understand, thank you.

Then there should be a way to edit the text as it's being sent, so just the end edited result appears to both contacts? Like how Quick Texts work.


RE: Two questions: !remotecommand and Messenger.MyContacts by ShawnZ on 12-13-2007 at 02:31 AM

quote:
Originally posted by kaourika
Ah! Okay, I understand, thank you.

Then there should be a way to edit the text as it's being sent, so just the end edited result appears to both contacts? Like how Quick Texts work.

yes, whatever you return from "chatwndsendmessage" will change the message being sent, and whatever you return from "chatwndreceivemessage" will change the message being received.

what you want to do is send a new message altogether from within "chatwndreceivemessage", not return anything.
RE: Two questions: !remotecommand and Messenger.MyContacts by kaourika on 12-13-2007 at 03:53 AM

Alright! I figured out how to do that, and almost everything is working perfectly now! :D Thanks!

Just one little annoyance... in my variable responses, I put Messenger.Myname, which I thought would return the name of the person who invoked the !command. Instead, it always returns MY name, even when it's my friends who typed !commandwhatever.

So, is there any way to produce the name of the person who initiated the command?

Thanks! 8D


RE: Two questions: !remotecommand and Messenger.MyContacts by markee on 12-13-2007 at 11:12 PM

use the Origin variable that is a parameter of the function.


RE: Two questions: !remotecommand and Messenger.MyContacts by CookieRevised on 12-13-2007 at 11:41 PM

PS: reading the scripting documents helps a lot in such cases. Most problems you encountered here are explained very clearly in the scripting documentation.

So, major tip: each time you want to use a certain function, look up that function in the scripting documentation and read its explaination.




eg: Scripting Doc > Index > OnEvent_ChatWndSendMessage

quote:
Return Value
A string containing the message to be sent (thus not recieved) instead (thus it will be replaced) of Message. If you do not want to modify the message, simply return Message without changing it. No size restriction applies to the new message except for the maximum size allowed by Messenger. If the event handler returns an empty string, the message is ignored and not sent to the server.
Which covers your first problems you had.



eg: Scripting Doc > Index > OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
quote:
Origin
Name of the user that sent the message (which covers one of your other questions in how to get the contact's name), as it appears in the chat window.......

Return Value
A string containing the message to be displayed in the chat window instead of Message (which explains why you didn't saw what the contact had typed, but you saw your new string, at least a part of it). If you do not want to modify the message, simply return Message without changing it. The new string will be parsed for possible format codes. It is important to remember that the new message cannot be longer than the original one (use Message.length) and will be cut if necessary which explains why the string was truncated. Also, Messenger will not re-parse the message for emoticons codes.
Which covers all the other problems you had with ChatWndReceiveMessage.
Note: there are other VERY important notes about this event function. I'm not going to quote them all though, see the help files for that.



eg: Scripting Doc > Index > ChatWnd.SendMessage
quote:
The ChatWnd.SendMessage function sends a (new) message to the contacts currently present in the chat window.
Important:
quote:
The EditChangeAllowed property should be checked before this function is called.



eg: Scripting Doc > Index > ChatWnd.EditChangeAllowed
quote:
The ChatWnd.EditChangeAllowed property specifies whether or not text can be entered/send in the typing area of the chat window.



eg: Scripting Doc > Index > Messenger.MyName
quote:
A string containing the name of the current user (thus not a contact; the user is you... hence MyName).




etc...

The scripting documentation can be found on the official homepage of Messenger Plus!, here:
http://www.msgpluslive.net/scripts/view/13-Offici...ing-Documentation/

Or by selecting "Script Documentation" in the Options menu in the Script Editor.

have fun scripting...
but remember, read the docs first, then experiment with trial and error...

;)