[Help] Messenger.MyContacts.GetContact - 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] Messenger.MyContacts.GetContact (/showthread.php?tid=90181)
[Help] Messenger.MyContacts.GetContact by Red Blood on 04-15-2009 at 08:45 PM
Hello, I'm new to this forum. I started scripting not to long ago and at the moment I'm at a stump. What I'm trying to do is when the user types something (EX:/Test) The user recieves a message BUT ONLY THAT USER.
my code is:
code: function OnEvent_ChatWndSendMessage(ChatWnd,Message){
if(Message =="/Test"&&Messenger.MyContacts.GetContact("emails@hotmail.com")){
var Message = "Testing";
ChatWnd.SendMessage(Message);
return '';
}
}
In my code the email address is different (Obviously) but anyways I can type /Test and it sends the messages but I can use the code on everyone not just that email. Help is appreciated.
RE: [Help] Messenger.MyContacts.GetContact by ryxdp on 04-15-2009 at 10:14 PM
I'm pretty sure it's impossible to send a message in a group chat to only one person. Just open a new chat window with them
Besides which, there are a few syntax errors here, I've fixed some stuff up for you. Not that it's going to be particularly useful if it is impossible.
jscript code: function OnEvent_ChatWndSendMessage(ChatWnd,Message){
var exp=/\/Test\s(.*)/i //Regular expression of /Test email@domain.com
if(exp.exec(Message!==null){ //If regexp matched message being sent
var email=RegExp.$1 //Store the email for future use
switch(email){ //Find out what the email is
case 'email@hotmail.com': //If it's this one
//Do stuff here
return 'Testing'; //Send message
break; //Stop the script here
case 'jsmith@tardis.com': //Otherwise if it's this one
//Do more stuff here
return 'Testing2'; //Send a different message
break; //Stop here
}
}
}
RE: [Help] Messenger.MyContacts.GetContact by Red Blood on 04-16-2009 at 01:06 AM
Hmm, ok thanks. But you see the reason for that was my "Main Plan" was to create a simple like text based Rpg and have like you could only roleplay with like that one msn account.
RE: [Help] Messenger.MyContacts.GetContact by davidpolitis on 04-16-2009 at 02:27 PM
quote: Originally posted by Red Blood
Hello, I'm new to this forum. I started scripting not to long ago and at the moment I'm at a stump. What I'm trying to do is when the user types something (EX:/Test) The user recieves a message BUT ONLY THAT USER.
Can you please try to explain in more detail what exactly you're doing... At the moment I've just written this code which probably isn't of any use.
javascript code: function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
if (match = /^\/test (.*)/i.exec(Message))
{
var Email = match[1];
if (Messenger.MyContacts.GetContact(Email))
return "Test";
else
MsgPlus.DisplayToast("Error", Email + " is not on your contact list");
return "";
}
return Message;
}
function OnGetScriptCommands()
{
var SC = "<ScriptCommands>";
SC += "<Command>";
SC += "<Name>test</Name>";
SC += "<Description>Test</Description>";
SC += "</Command>";
SC += "</ScriptCommands>";
return SC;
}
Btw, I realise the code makes no real sense. I'm confused and it is late.
RE: [Help] Messenger.MyContacts.GetContact by Red Blood on 04-16-2009 at 06:20 PM
^ "Hmm, ok thanks. But you see the reason for that was my "Main Plan" was to create a simple like text based Rpg and have like you could only roleplay with like that one msn account."
Alright like first I would make a new hotmail account Ex:Rpg1@hotmail.com (Just example) Then I want to make it so for example when you type /Test that code only works on Rpg1@hotmail.com and then it will have no effect if I try it on another email.
RE: RE: [Help] Messenger.MyContacts.GetContact by ArkaneArkade on 04-16-2009 at 08:48 PM
quote: Originally posted by Red Blood
Alright like first I would make a new hotmail account Ex:Rpg1@hotmail.com (Just example) Then I want to make it so for example when you type /Test that code only works on Rpg1@hotmail.com and then it will have no effect if I try it on another email.
So you don't actually want to send a message to another player, you want it to just be the script works only on your DM account for instance?
If you were to set a variable for the DM then you could just use an if to do it.
code: var DM = "rpg1@hotmail.com";
function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
if ((Message =="/Test") && (Messenger.MyEmailAddress == DM))
{
var Message = "Testing";
MsgPlus.DisplayToast("Alert", Message);
}
}
Apologies for the bad code. I'm a little rusty, but you get the gist and hopefully it'll help you out a bit.
RE: RE: RE: [Help] Messenger.MyContacts.GetContact by davidpolitis on 04-17-2009 at 12:24 AM
quote: Originally posted by Leroux
javascript code: var DM = "rpg1@hotmail.com";
function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
if ((Message =="/Test") && (Messenger.MyEmailAddress == DM))
{
var Message = "Testing";
MsgPlus.DisplayToast("Alert", Message);
}
}
Apologies for the bad code. I'm a little rusty, but you get the gist and hopefully it'll help you out a bit.
quote: Return Value
A string containing the message to be sent instead 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.
Problems:
1. You're setting the variable "Message", which is already set by OnEvent_ChatWndSendMessage
2. You aren't returning anything at the end of the event
3. Script commands should not start with an uppercase character (although they will still work)
4. Using OnGetScriptCommands(), along with our script command check, would be more suitable
Btw, I changed the one if to use two ifs so that "/test" isn't returned, causing a loop and script error, if the current user's email address is not the value of "DM". Also, "MyEmailAddress" is not a valid property of the Messenger object and was therefore changed to "MyEmail".
javascript code: var DM = "email@live.com"; // Change to the 'enabled' email address
function OnGetScriptCommands()
{
var SC = "<ScriptCommands>";
SC += "<Command>";
SC += "<Name>test</Name>";
SC += "<Description>Test</Description>";
SC += "</Command>";
SC += "</ScriptCommands>";
return SC;
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
if (Message === "/test")
{
if (Messenger.MyEmail == DM)
{
var Msg = "Testing";
MsgPlus.DisplayToast("Alert", Msg);
}
return "";
}
return Message;
}
P.S. hopefully what I said makes sense. Sorry if it doesn't.
|