第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Java TwitchBot/PircBot 無(wú)法讀取 .txt 文件中的命令,就像它必須做的那樣

Java TwitchBot/PircBot 無(wú)法讀取 .txt 文件中的命令,就像它必須做的那樣

喵喔喔 2023-05-17 15:46:38
我開始TwitchBot在java. 機(jī)器人工作正常,所以我的想法是用變量替換硬編碼命令。命令和消息保存在文本文件中。BufferedReader班級(jí):try {            reader = new BufferedReader(new FileReader("censored//lucky.txt"));            String line = reader.readLine();            while (line != null) {                String arr[] = line.split(" ", 2);                command = arr[0];                message = arr[1];                line = reader.readLine();            }            reader.close();        } catch (IOException e) {            e.printStackTrace();        }我的片段bot/command classif(message.toLowerCase().contains(BufferedReader.command)) {            sendMessage(channel, BufferedReader.message);        }我的.txt文件:!test1 Argument1 Argument2!test2 Argument1 Argument2!test3 Argument1 Argument2!test4 Argument1 Argument2當(dāng)我的文本文檔中只有 1 行時(shí)一切正常command+message / line,但是當(dāng)有多行時(shí),我無(wú)法訪問(wèn)Twitch Chat. 我知道,命令是這樣堆疊的!test1 !test2 !test3 !test。所以我的問(wèn)題是,我該如何避免這種情況?我擔(dān)心的是,在我的實(shí)際代碼中!test3使用了來(lái)自我的命令的消息!test1。
查看完整描述

1 回答

?
胡子哥哥

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊

while (line != null) 

{

   String arr[] = line.split(" ", 2);

   command = arr[0];

   message = arr[1];

   line = reader.readLine();

}

此循環(huán)不斷讀取文件中的每一行并覆蓋commandand的內(nèi)容message,這意味著當(dāng)文件中有多個(gè)命令時(shí) - 只有最后一行占上風(fēng)。


如果要存儲(chǔ)多個(gè)命令/消息,則command/變量必須是ormessage類型。然后你可以根據(jù)內(nèi)容進(jìn)行匹配。java.util.ListHashMap


例如。,


Map<String,String> msgMap = new HashMap<>();

while (line != null) 

    {

       String arr[] = line.split(" ", 2);

       if(arr[0]!=null)

         msgMap.put(arr[0],arr[1]);

       line = reader.readLine();

    }


查看完整回答
反對(duì) 回復(fù) 2023-05-17
  • 1 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)