2011-11-20 36 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

@凯尔:我无法回答你的第一个问题。这完全取决于你。无论如何,如果这能解决您的问题,请记得点击复选标记。 –