# LinkBlock - URL Protection - notification messages from a bot

**URL:** <https://extensions.streamer.bot/t/linkblock-url-protection-notification-messages-from-a-bot/1328>\
**Category:** The Lounge\
**Created:** [May 7, 2024, 1:46am UTC](https://extensions.streamer.bot/t/linkblock-url-protection-notification-messages-from-a-bot/1328 "2024-05-07T01:46:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![foJiG](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/fojig/32/1714_2.png) [@foJiG](https://extensions.streamer.bot/u/foJiG)\
**Post date:** [May 7, 2024, 1:46am UTC](https://extensions.streamer.bot/t/linkblock-url-protection-notification-messages-from-a-bot/1328/1 "2024-05-07T01:46:38Z")

</div>

> [@LinkBlock - URL Protection](https://extensions.streamer.bot/docs?topic=1232):
>
> Description LinkBlock blocks unwanted messages that contains real URLs. But: it does NOT block typos with forgotten spaces between word.word but will block word.com because this is a real TLD. It does NOT block word...word (typical writing by many users) You can whitelist URLs like your DC or YT channel or any other you want. By default Mods and VIPs are allowed to post links, it can be disabled. You can select how to handle messages with URLs either delete only or timeout user. You can …

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

---

<div class="post-metadata">

**Author:** ![mustached\_maniac](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/mustached_maniac/32/1227_2.png) [@mustached\_maniac](https://extensions.streamer.bot/u/mustached_maniac)\
**Post date:** [May 8, 2024, 11:20am UTC](https://extensions.streamer.bot/t/linkblock-url-protection-notification-messages-from-a-bot/1328/2 "2024-05-08T11:20:50Z")

</div>

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

 ![image](https://extensions.streamer.bot/uploads/default/original/2X/1/1d82d6f30547a360ae618aad35fdbb27d00776e9.png)

---

<div class="post-metadata">

**Author:** ![scholle1309](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/scholle1309/32/3080_2.png) [@scholle1309](https://extensions.streamer.bot/u/scholle1309)\
**Post date:** [August 31, 2024, 11:55am UTC](https://extensions.streamer.bot/t/linkblock-url-protection-notification-messages-from-a-bot/1328/3 "2024-08-31T11:55:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bans](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/bans/32/5669_2.png) [@bans](https://extensions.streamer.bot/u/bans)\
**Post date:** [September 2, 2024, 8:55pm UTC](https://extensions.streamer.bot/t/linkblock-url-protection-notification-messages-from-a-bot/1328/4 "2024-09-02T20:55:27Z")

</div>

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

```auto
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;
    }
}

```

---

<div class="post-metadata">

**Author:** ![Old\_Samos](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/old_samos/32/3223_2.png) [@Old\_Samos](https://extensions.streamer.bot/u/Old_Samos)\
**Post date:** [December 4, 2024, 11:14am UTC](https://extensions.streamer.bot/t/linkblock-url-protection-notification-messages-from-a-bot/1328/5 "2024-12-04T11:14:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bans](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/bans/32/5669_2.png) [@bans](https://extensions.streamer.bot/u/bans)\
**Post date:** [December 4, 2024, 9:10pm UTC](https://extensions.streamer.bot/t/linkblock-url-protection-notification-messages-from-a-bot/1328/7 "2024-12-04T21:10:27Z")

</div>

i suggest you to use [TwitchLinkGuard - Block unwanted links](https://extensions.streamer.bot/t/twitchlinkguard/2145) since LinkBlock seems abandoned

---

<div class="post-metadata">

**Author:** ![iacchus](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/iacchus/32/4201_2.png) [@iacchus](https://extensions.streamer.bot/u/iacchus)\
**Post date:** [February 27, 2025, 1:28pm UTC](https://extensions.streamer.bot/t/linkblock-url-protection-notification-messages-from-a-bot/1328/8 "2025-02-27T13:28:21Z")

</div>

Hey so i faced this same issue so i did a bit a editing to the regex and i think i got a system that will all you have to do is change this line string pattern = @“\b(?:https?://|www.)?[a-zA-Z0-9-.\_~%]+(?:.[a-zA-Z]{2,})(?:/[^\s]_)?(?:?[^]_)?(?:#[^\s]\*)?(?\<![.,;])\b”;
