Search code examples
c#ircspam-preventiontwitchpurge

purging users with an automated c# irc bot


I am making a twitch chat bot with c# and I would like to know how I can purge/timeout users that are spamming or using banned words. I have searched everywhere i can to find a solution for this, but I can not find an answer anywhere.


Solution

  • You don't seem to provide any implementation in your question, so I will make some assumptions. I assume that you have a list of banned words in a List<String> object called bannedWords, and are considering spam as a message that exceeds a given number of characters.

    You have it correct that in order to time out someone, you need to send .timeout [user] [number of seconds], and this will 'delete' any messages they've sent (although users can simply click the <message deleted> link to see the original message).

    One way you could do this is by doing the following:

    // Code attribution: http://stackoverflow.com/a/9032686/2605758    
    if (bannedWords.Any(str => str.Contains(message)) || message.Length >= maxLength)
    {
        /* use whatever method you use to send a message to your channel */
        SendMessage(".timeout " + userNick + " 1"); 
    }