-1

I want to write IRC Twitch bot. I have never used Pirc library before, so i wrote this simple bot to get started.

BasicBot class :

public class BasicBot extends PircBot{

public BasicBot(String name){
    super();
    this.setName(name);
}
 protected void onMessage(String channel, String sender, String login, String hostname, String message) {
     if(message == "2/10"){
         sendMessage(channel,"YAYO");

     }
     System.out.println(message + (message == "2/10"));
 }
}

but when message 2/10 appears on chat this is what i see in console :

2/10false

I don't know why "2/10" == "2/10" is false. I tried also other strings like "banana" or "apple" and result was similar. Please help.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Kentox
  • 21
  • 1
  • 2

1 Answers1

2

Strings are objects - the == operator tests if both arguments are the same instance, which, in your case, they may very well not be. Instead, you should use the equals method to check that they both have the same value:

if("2/10".equals(message)){
         sendMessage(channel,"YAYO");

     }
     System.out.println(message + ("2/10".equals(message)));
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350