Shoutbox

find out exact text of someone's message.. (something like that) - 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: find out exact text of someone's message.. (something like that) (/showthread.php?tid=77141)

find out exact text of someone's message.. (something like that) by ash44455666 on 08-31-2007 at 09:17 PM

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-)


RE: find out exact text of someone's message.. (something like that) by foaly on 08-31-2007 at 10:20 PM

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.
}}


RE: find out exact text of someone's message.. (something like that) by ash44455666 on 08-31-2007 at 10:39 PM

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]; }}}}


RE: find out exact text of someone's message.. (something like that) by foaly on 08-31-2007 at 10:41 PM

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"
RE: find out exact text of someone's message.. (something like that) by ash44455666 on 08-31-2007 at 10:53 PM

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);
       }
    }
}


RE: find out exact text of someone's message.. (something like that) by ash44455666 on 08-31-2007 at 11:24 PM

oops ignore this post please o.O


RE: find out exact text of someone's message.. (something like that) by matty on 08-31-2007 at 11:27 PM

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.
RE: find out exact text of someone's message.. (something like that) by ash44455666 on 08-31-2007 at 11:32 PM

matty that code didn't work either... I still think I'm doing something wrong that isn't in the script...


RE: find out exact text of someone's message.. (something like that) by Matti on 09-01-2007 at 10:05 AM

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.
RE: find out exact text of someone's message.. (something like that) by ash44455666 on 09-01-2007 at 07:05 PM

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).
RE: find out exact text of someone's message.. (something like that) by Matti on 09-02-2007 at 09:22 AM

quote:
Originally posted by ash44455666
I found out the problem :)
Ah, yes, the good old wrongly-named-parameter symptom. :)
quote:
Originally posted by ash44455666
Thanks for the idea with the debugger it's a life saver for us beginners (and probably the more advanced programmers too).
I can assure you: every script developer needs the debugger. If something is wrong, the debugger tells you exactly where to look. If we wouldn't have a debugger, script debugging would be much harder, since we'd have to test every line of the script and see it that caused the error. The script debugger is a bless for us! :)