Hello I am pretty new with Java but I have fiddled with a bit.
This time I am trying to make a bot for my Twitch channel that I can configure on my own, like making a raffle and some other independent stuff.
I am using a library to connect with the Twitch IRC called PircBotX: https://code.google.com/p/pircbotx/ and I have some understanding on how to answer back with ListenerAdapter like so:
public class Commands extends ListenerAdapter {
public void onMessage(MessageEvent event) {
if (event.getMessage().equals("!commands")) {
event.respond("Available user commands: !topic, !faq, !youtube, !twitter, !schedule, !time");
}
}
}
But in this particular listener I am trying to return a message when a person does:
!topic newtopic
In this instance you need to get the "newtopic" string.
I don't know if there is a way to save the topic in the Twitch API so I just write it in my own file.
I am thinking it might look like this:
newText = event.getMessage.?????
if (event.getMessage().equals("!topic " + newText)) {
if (event.getChannel().isOp(event.getUser())) {
try (BufferedWriter br = new BufferedWriter(new FileWriter("topic.txt"))) {
br.write(newText);
br.close();
event.getChannel().send().message("Topic: " + newText);
}
}
else {
event.respond("Only mods can change the topic");
}
}
Am I doing it wrong?
I have looked through the API and I just don't understand how it works. Can anyone help?
I might want to answer my own question for people that might get into a similar dilemma.
This is how you declare the string, really easy:
String newText = event.getMessage().substring(("!topic ").length());
I remember using substring() many times. Just a little stupid mistake.
For more info on it check here:
http://www.tutorialspoint.com/java/java_string_substring.htm