Well, the idea you have comes with a variety of possible problems.
First of all, you'll need to find a way not to respond to your own messages. That means, if you respond on "hi" with "hi there!", you have to avoid responding on "hi there!" too.
Secondly, you'll need a proper way to find the messages you're looking for. You could go the easy way and simply use:
code:
if(Message.indexOf("hi") !== -1) {
but that won't match "Hi" or "HI". Also, you might want to avoid matching "hitch" as well. That's where regular expressions can come in handy, such as:
code:
if(/\bhi\b/\b.test(Message)) {
However, that may already be quite advanced, so maybe you should
first learn about those when you plan to do it really good.
But your basic concept may look like:
code:
var Match = {
"hi" => "Hello there! ",
"how are you" => "I'm fine, thanks! "
};
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, Kind) {
//1. Check if the message was sent by a contact and not yourself.
//2. Loop through the Matches with for(var Key in Matches) {}.
//3. Match the key against the Message.
//4. If a match was found, send the respond message (Matches[Key]) and return to prevent multiple responses for one message.
}
A good trick to get around the first problem is by using a timer of 1 second when a message is sent by you. That will set a global variable (such as bDoNotRespond) to true. Then, when the timer runs out, you set it back to false. You can now check in the receive message event first if bDoNotRespond is true, and then cancel the timer and return immediately to prevent responding to your own messages. That way, you don't need to use all kinds of workarounds to match Origin against the right contact name.
(Think about custom nicknames, StuffPlug's timestamps,...)
Anyway, I'm sure there are a lot of threads here which may help you with this. Good luck!