LinkBlock - URL Protection - notification messages from a bot

Please explain how you can make the notification messages come from a bot

You need to go to the LinkBlock action and double click on the Execute Code (LinkBlock) Sub-Action.

Scroll down to lines 58 and lines 63 in that code, replace the ‘False’ with ‘True’ as is shown in the picture below. Then press Save and Compile and lastly, ensure you press Save at the top of StreamerBot

1 Like

Hey, I probably discovered a bug, when I provide permit to a user, his message will be deleted after a minute, but I want it to stay in Chat as he received permit. Can this be changed?

i reworked the script, so any URL is blocked, regardless of formating, at least any url twitch actually recognize as url

using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;

public class CPHInline
{
    private bool IsTwitchEmote(string input)
    {
        // Regular expression to match Twitch emote URLs
        string emotePattern = @"https:\/\/(www\.)?twitch\.tv\/emote\/\w+";
        return Regex.IsMatch(input, emotePattern);
    }

    private bool IsWhitelistedUrl(string url, List<string> whitelist)
    {
        // Convert wildcard entries in the whitelist to regex patterns
        foreach (string entry in whitelist)
        {
            // Escape special regex characters and replace '*' with '.*' to match any character
            string pattern = "^" + Regex.Escape(entry).Replace("\\*", ".*") + "$";

            // Check if the URL matches any of the whitelist patterns
            if (Regex.IsMatch(url, pattern, RegexOptions.IgnoreCase))
            {
                return true;
            }
        }

        return false;
    }

    public bool Execute()
    {
        string permitUser = CPH.GetGlobalVar<string>("permitUser", false);

        // Whitelist containing allowed URL patterns (supports wildcards)
        List<string> whitelist = new List<string>()
        {
            "https://www.twitch.tv/aaskjer/clip/*",  // Allow any clip URL from this user
            "www.twitch.tv/aaskjer/clip/*",
            "https://tinyurl.com/Birger-Caps",
            "https://discord.gg/FvffUkmne3"
        };

        // List of suspicious keywords that could indicate spam
        List<string> suspiciousKeywords = new List<string>()
        {
            "viewers",
            "fame",
            "followers",
            "subs",
            "click here",
            "viewer",
            "StreamBoo",
            "Ch̍eap",
            "primes",
            "Best viewers",
            "Best followers",
            "Best subs",
            "Buy followers",
            "Promo-Code",
            "Aloha! Buy viewers",
            "become famous",
            "Big Follows",
            "to streamrise",
            "TwitchLaunch",
            "twitchventures",
            "viewers. shop",
            "Buy",
			"get",
			"free",
			"bits",
			"free subs",
			"giveaway",
			"get famous",
			"PayPal donation",
			"gift card",
			"verification needed",
			"win a prize",
			"boost your channel",
			"Twitch promotion",
			"visit",
			"instant followers",
			"buy Twitch viewers",
			"discounted Twitch services",
			"earn money streaming",
			"amazing offer",
			"huge discount",
			"use code",
			"follow for follow",
			"join our Discord",
			"discord",
			"best",
			"Gutscheincode",
			"Upgrade your channel"
        };

        // Check if the current user is permitted to post URLs
        if (string.IsNullOrEmpty(permitUser) || args["user"].ToString() != permitUser)
        {
            // Pattern to detect URLs in the chat message
            string pattern = @"((https?:\/\/)?([\w\-]+\.)+[a-zA-Z]{2,})(\/[\w\-.~:\/?#[\]@!$&'()*+,;=%]*)?";
            string input = args["message"].ToString();
            RegexOptions options = RegexOptions.Multiline;

            // Search for all URLs in the message
            foreach (Match m in Regex.Matches(input, pattern, options))
            {
                // Check if the URL is whitelisted
                bool allowed = IsWhitelistedUrl(m.Value, whitelist);

                // If not allowed and not a Twitch emote, proceed with further checks
                if (!allowed && !IsTwitchEmote(m.Value))
                {
                    // Check if the message contains any suspicious keywords
                    foreach (string keyword in suspiciousKeywords)
                    {
                        if (input.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            // Ban the user and delete the message
                            string user = args["user"].ToString();
                            CPH.TwitchBanUser(user, "Spam", false);
                            CPH.TwitchDeleteChatMessage(args["msgId"].ToString(), false);
                            CPH.SendAction("User " + user + " schleich di mit deim scheiß! DansGame ");
                            return true;  // Exit after banning the user
                        }
                    }

                    // If no suspicious keywords are found, just delete the message
                    string messageId = args["msgId"].ToString();
                    CPH.TwitchDeleteChatMessage(messageId, false);
                    CPH.SendAction("Bitte keine Links ohne Erlaubnis posten, " + args["user"].ToString() + ". Merce.");
                    break;  // Stop processing after the first non-whitelisted URL
                }
            }
        }

        return true;
    }
}

Do you know if there is a way to block links that end in .RU because bots have seemed to stop using .com recently and it would be great to just block those all together.

i suggest you to use TwitchLinkGuard since LinkBlock seems abandoned

1 Like