Jump to content

Parsing private messages and clan chat


Recommended Posts

Posted

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
Posted (edited)

Oh I see, is there anyway I can differentiate between clan chat and private chat messages? 

 

Thanks for your help.

 

I think it might be ID 9 for clan chat:

@Override
public void onMessage(Message message){

    if(message.getTypeId() == 9){

      // do something
    }
}
Edited by Explv
  • Like 1
Posted

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.

Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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