Hi, I’m developing a chatbot for my Twitch stream using PircBot, and I’m encountering some problems. Only the command !currentSong
is functioning correctly, while the rest of the commands, such as !ipAddress
and !team
, are not working as expected. I’ve reviewed my code thoroughly but can’t seem to identify the issue. The bot connects seamlessly, and its ability to execute the one working command indicates that it can send messages. Could someone assist me in troubleshooting this matter?
import org.jibble.pircbot.*;
import java.io.*;
public class MyBot extends PircBot {
// Get current song from a file
public String fetchCurrentSong() throws Exception {
FileReader fileReader = new FileReader("D:/MyStream/SongList.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
String songList = "";
String line = bufferedReader.readLine();
while (line != null) {
songList += line;
line = bufferedReader.readLine();
}
return songList;
}
public MyBot() {
this.setName("MyBot");
}
public static String address = "";
public static String teamMember = "";
public void onMessage(String channel, String sender,
String login, String hostname, String message) {
String owner = "channelOwner";
if (message.startsWith("!requestSong")) {
sendMessage(channel, "Song requests are currently unavailable, use !currentSong to check the title");
}
if (message.startsWith("!ipAddress ")) {
if (sender.equals(owner)) {
address = message.split(" ")[1];
sendMessage(channel, "IP address updated: " + address);
}
} else {
if (message.equalsIgnoreCase("!ipAddress")) {
sendMessage(channel, "Currently streaming on IP: " + address);
}
}
if (message.startsWith("!teamMember ")) {
if (sender.equals(owner)) {
teamMember = message.split(" ")[1];
}
} else {
if (message.equalsIgnoreCase("!teamMember")) {
sendMessage(channel, "Check out my team at twitch.tv/" + teamMember);
}
}
if (message.equalsIgnoreCase("!currentSong")) {
String currentTrack = "";
try {
currentTrack = fetchCurrentSong();
} catch (Exception e) { e.printStackTrace(); }
sendMessage(channel, currentTrack);
}
}
}