2011-11-20 26 views
0
write("NAMES " + channel, writer);//build list of people in channel 
String[] Users = reader.ReadLine().Split(' ');//read the line from NAMES, and split into Users array 
String[] sender = nick.Split('!');//Person calling the bot 
string[] args = data.Split('-');//Arguments to command (Not listed) 
nick = sender[0].Substring(1);//Person callin the bot as above 
foreach (string i in Users) 
{ 
    if (i.StartsWith("+") && i.EndsWith(nick) || i.StartsWith("%") && i.EndsWith(nick) || i.StartsWith("@") && i.EndsWith(nick) || i.StartsWith("&") && i.EndsWith(nick) || i.StartsWith("~") && i.EndsWith(nick)) 
    { 
     Roll_Args(nick, args[1], args[2]);//If above is correct, roll the the command 
    } 
} 

由於某種原因,它不適用於@,但適用於+的等級。我不知道如何檢查IRC中的排名。檢查IRC中的排名

是否有更可靠/有效的方法來檢查IRC中的排名?

感謝您的閱讀。

編輯:它有時並不總是適用於某些人的用戶名/暱稱。例如:@Oh_Herro_Der不適用於該命令。

回答

2

您需要將每個&&條件括在括號內。

if (i.StartsWith("+") && i.EndsWith(nick)) 
|| (i.StartsWith("%") && i.EndsWith(nick)) 
|| (i.StartsWith("@") && i.EndsWith(nick)) 
|| (i.StartsWith("&") && i.EndsWith(nick)) 
|| (i.StartsWith("~") && i.EndsWith(nick))) 
{ 
    Roll_Args(nick, args[1], args[2]);//If above is correct, roll the the command 
} 
+0

你覺得'i.Contains(nick)'比EndsWith更合適嗎? – Kyle

+0

也感謝捕捉。我沒有意識到他們沒有被封閉。 <3 – Kyle

+0

@凱爾:我無法回答你的第一個問題。這完全取決於你。無論如何,如果這能解決您的問題,請記得點擊複選標記。 –