What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » find out exact text of someone's message.. (something like that)

Pages: (2): « First [ 1 ] 2 » Last »
find out exact text of someone's message.. (something like that)
Author: Message:
ash44455666
New Member
*


Posts: 10
Joined: Aug 2007
O.P. find out exact text of someone's message.. (something like that)
I'm trying to make some code that makes me kind of like a bot in a chat room (it's more of a joke between friends :P). However I'm just starting this script and therefore don't have much knowledge of it. How would I go around to finding out all the text after a command like !say? For example,
!say pie is good
I want the bot (me) to respond with
pie is good
What, though, if I wanted to find out the second and third word instead of gathering all the info? like..
!set link1 http://shoutbox.menthix.net/
The script for that would have to find out that the user typed !set, find out what the second word is (link1) and then set a variable to equal http://shoutbox.menthix.net/
Is this kind of stuff possible? I'm hoping so 8-)
08-31-2007 09:17 PM
Profile E-Mail PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
Joined: Jul 2006
RE: find out exact text of someone's message.. (something like that)
it sure is possible...
you can use something like:
[code]
    if (sMessage.charAt(0) == '!'){
        if(sMessage.charAt(1) == '!'){
            return sMessage;
        } else {
            var parts is sMessage.split(" ");
             //this makes parts an array where parts[0] is !set parts[1] is link1 and parts[2] is the link.
}}

This post was edited on 08-31-2007 at 10:21 PM by foaly.
08-31-2007 10:20 PM
Profile E-Mail PM Find Quote Report
ash44455666
New Member
*


Posts: 10
Joined: Aug 2007
O.P. RE: find out exact text of someone's message.. (something like that)
Thanks foaly :)
So if I wanted to set variable link1, link2 or link3 to what they provided, I could use something like this?

code:
var link1 = "No link set";
var link2 = "No link set";
var link3 = "No link set;
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
    if(Origin != Messenger.MyName) {
        if (sMessage.charAt(0) == '!') {
        if(sMessage.charAt(1) == '!') {
            return sMessage; }
         else {
            var parts is sMessage.split(" "); }}
    if (parts[0] == !set) {
       if (parts[1] == link1) {
          link1 = parts[2]; }
    else if (parts[1] == link2) {
          link2 = parts[2]; }
    else if (parts[1] == link3) {
          link3 = parts[2]; }}}}

08-31-2007 10:39 PM
Profile E-Mail PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
Joined: Jul 2006
RE: find out exact text of someone's message.. (something like that)
quote:
Originally posted by ash44455666
Thanks foaly :)
So if I wanted to set variable link1, link2 or link3 to what they provided, I could use something like this?

code:
var link1 = "No link set";
var link2 = "No link set";
var link3 = "No link set;
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
    if(Origin != Messenger.MyName) {
        if (sMessage.charAt(0) == '!') {
        if(sMessage.charAt(1) == '!') {
            return sMessage; }
         else {
            var parts is sMessage.split(" "); }}
    if (parts[0] == !set) {
       if (parts[1] == link1) {
          link1 = parts[2]; }
    else if (parts[1] == link2) {
          link2 = parts[2]; }
    else if (parts[1] == link3) {
          link3 = parts[2]; }}}}


yes that should work... although the words you recieve should be in quotations like:
parts[1] == "link1"

This post was edited on 08-31-2007 at 10:45 PM by foaly.
08-31-2007 10:41 PM
Profile E-Mail PM Find Quote Report
ash44455666
New Member
*


Posts: 10
Joined: Aug 2007
O.P. RE: find out exact text of someone's message.. (something like that)
Everything looks like it should work, but Messenger Plus! live says its defective - I think that's because of the missing .xml file (I don't know anything about it so I guess I gotta learn now >.<).

Edit: just read some of the documentation thingy, and apparently I don't need a .xml file.. what's wrong with it then? Here's the code;

code:
var link1 = "No link set";
var link2 = "No link set";
var link3 = "No link set";

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
    if(Origin != Messenger.MyName) {
        if (sMessage.charAt(0) == '!') {
            if(sMessage.charAt(1) == '!') return sMessage;
            else var parts is sMessage.split(" ");
        }
        if (parts[0] == "!set") {
            if (parts[1] == "link1") {
                link1 = parts[2];
                ChatWnd.SendMessage("Link1 set to " + link1);
            }
            else if (parts[1] == "link2") {
                link2 = parts[2];
                ChatWnd.SendMessage("Link2 set to " + link2);
            }
            else if (parts[1] == "link3") {
                link3 = parts[2];
                ChatWnd.SendMessage("Link3 set to " + link3);
            }
            else if (parts[0] == "!link1") ChatWnd.SendMessage(link1);
            else if (parts[0] == "!link2") ChatWnd.SendMessage(link2);
            else if (parts[0] == "!link3") ChatWnd.SendMessage(link3);
       }
    }
}


This post was edited on 08-31-2007 at 11:27 PM by ash44455666.
08-31-2007 10:53 PM
Profile E-Mail PM Find Quote Report
ash44455666
New Member
*


Posts: 10
Joined: Aug 2007
O.P. Sad  RE: find out exact text of someone's message.. (something like that)
oops ignore this post please o.O

This post was edited on 08-31-2007 at 11:25 PM by ash44455666.
08-31-2007 11:24 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: find out exact text of someone's message.. (something like that)
Your code is wrong...

code:
var link1 = "No link set";
var link2 = "No link set";
var link3 = "No link set";

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
    if(Origin != Messenger.MyName) {
        if (sMessage.charAt(0) == '!') {
            if(sMessage.charAt(1) == '!') return sMessage;
            else var parts is sMessage.split(" ");
        }
        if (parts[0] == "!set") {
            switch (parts[1]) {
                case 'link1' :
                    link1 = parts[2];
                    return "Link1 set to "+link1;
                case 'link2':
                    link2 = parts[2];
                    return "Link2 set to "+link2;
                case 'link3':
                    link3 = parts[2];
                    return "Link3 set to "+link2;
            }
        else if (parts[0] == "!link1") ChatWnd.SendMessage(link1);
        else if (parts[0] == "!link2") ChatWnd.SendMessage(link2);
        else if (parts[0] == "!link3") ChatWnd.SendMessage(link3);
       }
    }
}

Note: this in no way has been optimized. This should not be taken as a reflection of my programming abilities... just my laziness.
08-31-2007 11:27 PM
Profile E-Mail PM Find Quote Report
ash44455666
New Member
*


Posts: 10
Joined: Aug 2007
O.P. RE: find out exact text of someone's message.. (something like that)
matty that code didn't work either... I still think I'm doing something wrong that isn't in the script...
08-31-2007 11:32 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: find out exact text of someone's message.. (something like that)
Errr...
code:
        if (sMessage.charAt(0) == '!') {
            if(sMessage.charAt(1) == '!') return sMessage;
            else var parts = sMessage.split(" ");
        }
Also, you don't want to return "Link 1 set to ..." as the replacement of the received message, you want your bot to send it! ;)
code:
            switch (parts[1]) {
                case 'link1' :
                    link1 = parts[2];
                    ChatWnd.SendMessage("Link1 set to "+link1);
                    break;
                case 'link2':
                    link2 = parts[2];
                    ChatWnd.SendMessage("Link2 set to "+link2);
                    break;
                case 'link3':
                    link3 = parts[2];
                    ChatWnd.SendMessage("Link3 set to "+link3);
                    break;
            }
;)

quote:
Originally posted by ash44455666
Edit: just read some of the documentation thingy, and apparently I don't need a .xml file..
Indeed. You only need a ScriptInfo.xml if you want to pacakage and release your script in a .PLSC file. But if you only need the script to run on your side and don't need to send it to someone else, it's perfectly fine to leave the ScriptInfo.xml out. :)

Also, it may help if you enable script debugging in Preferences > General > Scripts and show the script debugging window from the contact list's Scripts button > Script debugging. It may give you information on what line the error occured and what kind of error it is.

This post was edited on 09-01-2007 at 10:13 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-01-2007 10:05 AM
Profile E-Mail PM Web Find Quote Report
ash44455666
New Member
*


Posts: 10
Joined: Aug 2007
O.P. RE: find out exact text of someone's message.. (something like that)
I found out the problem :) and ty mattike that helped too :D
The problem was
code:
if (sMessage.charAt(0) == '!') {
     if(sMessage.charAt(1) == '!') return sMessage;
     else var parts = sMessage.split(" ");
}

needed to be
code:
if (Message.charAt(0) == '!') {
    if(Message.charAt(1) == '!') return Message;
    else var parts = Message.split(" ");
}

Thanks for the idea with the debugger it's a life saver for us beginners (and probably the more advanced programmers too).
09-01-2007 07:05 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On