Search code examples
c#irc

Checking ranks in IRC


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
    }
}

For some reason it doesn't work for @ but it works for the + rank. I don't know how else to check ranks in IRC.

Is there a more dependable/efficient way to check for ranks in IRC?

Thanks for reading.

Edit: It sometimes doesn't always work for some people's usernames/nicknames. For example: @Oh_Herro_Der doesn't work with the command.


Solution

  • You need to enclose each of your && conditions within parentheses.

    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
    }