Search code examples
c#twitch

certain user(s) can only use a command


Essentially this program allows a user to use a command !weaponrequest, it then saves their request into a list, with !nextweapon you can see what the next weapon in the list is, this allows a streamer to take weapon requests in a game with a fully automated system.

Anyway moving onto my problem, I need a way to make it so that a certain user(s) can only use a command. I know that I am going to need a list to store the users in. I will write them in manually so I don't need any kind of system for that. All I am wondering is using an IF statement how would I check to see if the user is in this list and then make it so that only that user(s) can activate that command and receive a response.

case "nextweapon":
{
    if (new FileInfo("MyFile.txt").Length == 0)
    {
        irc.sendChatMessage("There are no weapons in the list!");
        break;
    }

    string Lines = File.ReadLines("MyFile.txt").Take(1).First();
    //irc.sendChatMessage(Lines);

    List<string> WeaponList = File.ReadAllLines("MyFile.txt").ToList();
    string FirstItem = WeaponList[0];
    WeaponList.RemoveAt(0);
    File.WriteAllLines("MyFile.txt", WeaponList.ToArray());
    irc.sendChatMessage(Lines);
    break;
}

This is the command that I want to only be used by a certain user(s).


Solution

  • if ((username == "") || (username == "") || (username == ""))
    {
    
    }
    

    This is how I solved the issue, it's not the most efficient way but there are only limited users that I needed so making a list was not necessary.

    Obviously you need to replace the names with your own names you want to be able to use the command. For example:

    (username == "RandomStranger")
    {
    
    }