when "the_pvbro" wants to type a command in chat the bot doesn't allow him to use it. and i'm too lazy to make a new class for every new mod i add. so does anyone have an idea maybe how to do it differntly?
import org.jibble.pircbot.*;
public class TwitchBot extends PircBot{
public TwitchBot(){
this.setName("rayibot");
this.isConnected();
}
String owner = "skalrayi";
String mod [] = new String[3];{
mod[0] = "the_pvbro";
}
public void onMessage(String channel, String sender, String login, String hostname, String message){
if(message.equalsIgnoreCase("!spiel")){
sendMessage(channel, "Aktuell wird " + Config.currentGame + " gespielt.");
}
else
if(message.equalsIgnoreCase("!song")){
sendMessage(channel, "Aktueller Song:" );
}
else
if(message.equalsIgnoreCase("!hallo")){
sendMessage(channel, "Hallo wie geht es dir denn heute so " +sender);
}
else
if(message.startsWith("!kick")){
if(sender.equals(owner) || sender.equals(mod))
{
String userToKick = message.split(" ")[1];
kick(channel, userToKick );
sendMessage(channel, ".timeout " +userToKick + " 60");
sendMessage(channel, userToKick +" wurde aus dem Channel gekickt!");
}
else{
sendMessage(channel, "Deine Rechte reichen nicht aus, um diesen Befehl zu benutzen! " + sender);
}
}
if (message.startsWith("!ban")) {
if(sender.equals(owner)|| sender.equals(mod))
{
String userToBan = message.split(" ")[1];
ban(channel, userToBan);
sendMessage(channel, ".ban " + userToBan);
sendMessage(channel, userToBan + " wurde aus dem Channel verbannt!");
}
else{
sendMessage(channel, "Deine Rechte reichen nicht aus, um diesen Befehl zu benutzen! " + sender );
}
}
}
}
Right now you are comparing the String
sender against the mod array. This will always return false
, since a String is not an array. What you want to do is check if the mod array contains the sender string.
What I would do is use a list instead of an array by replacing:
String mod [] = new String[3];{
mod[0] = "the_pvbro";
}
with
List<String> mod = Arrays.asList("the_pvbro");
Then you'll be able to use the contains
method by replacing:
sender.equals(mod)
with
mod.contains(sender);
This way, when you get more mods, you can just add them to the arguments to Arrays.asList()
, i.e.:
List<String> mod = Arrays.asList(
"the_pvbro",
"mod2",
"mod3");