简体   繁体   English

我的机器人不接受我的字符串数组作为 mod。 有谁知道有什么问题吗?

[英]my bot doesn't accept my string array for mod. does anyone know whats wrong with it?

when "the_pvbro" wants to type a command in chat the bot doesn't allow him to use it.当“the_pvbro”想在聊天中输入命令时,机器人不允许他使用它。 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{公共类 TwitchBot 扩展了 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.现在您正在将String发送器与 mod 数组进行比较。 This will always return false , since a String is not an array.这将始终返回false ,因为 String 不是数组。 What you want to do is check if the mod array contains the sender string.您要做的是检查 mod 数组是否包含发件人字符串。

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:然后你就可以通过替换来使用contains方法:

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() , ie:这样,当您获得更多 mod 时,您可以将它们添加到Arrays.asList()的参数中,即:

List<String> mod = Arrays.asList(
    "the_pvbro",
    "mod2",
    "mod3");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM