Jump to content

Parsing private messages and clan chat


ninjamuffinz

Recommended Posts

Hi guys. 

 

I need to listen to the clan chat and private messages that my account receives and act on them. I'm not sure how I can achieve this however. 

 

Basically I'd like my bot to join a clan chat, and when another character says a certain phrase it acts on it. Is this even possible?

 

Thanks

Link to comment
Share on other sites

Hi guys. 

 

I need to listen to the clan chat and private messages that my account receives and act on them. I'm not sure how I can achieve this however. 

 

Basically I'd like my bot to join a clan chat, and when another character says a certain phrase it acts on it. Is this even possible?

 

Thanks

@Override
public void onMessage(Message message){

    if(message.getType() == Message.MessageType.PLAYER){
            
      String text = message.getMessage();
    }
}

That should get you started

  • Like 1
Link to comment
Share on other sites

Ok so I have another issue. 

 

@Override
public void onMessage(Message message){
log("Message received.");
String messageReceived = message.getMessage();

if(message.getTypeId() == 9){
log("Clan chat message.");

if(messageReceived == "/!Test"){
log("Test received..");
getKeyboard().typeString("/Success!", true);
}

log(messageReceived);
}

 

Although it appears in my logger as !Test, the if statement doesn't resolve as true so the code wont execute? Am I missing something.

Link to comment
Share on other sites

Ok so I have another issue. 

@Override
public void onMessage(Message message){
log("Message received.");
String messageReceived = message.getMessage();

if(message.getTypeId() == 9){
log("Clan chat message.");

if(messageReceived == "/!Test"){
log("Test received..");
getKeyboard().typeString("/Success!", true);
}

log(messageReceived);
}

Although it appears in my logger as !Test, the if statement doesn't resolve as true so the code wont execute? Am I missing something.

 

String values are compared using .equals()  not ==

 

Also the message will not contain /

 

It should be:

if(messageReceived.equals("!Test")){
    log("Test received..");
    getKeyboard().typeString("/Success!", true);
}

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...