linkBlocker

  • community
  • anti-cheat
  • by frenchmoilsac
  • Takaro v0.2.1
  • all
Version
View export JSON

Automatically block link sharing to prevent spam and promote safe communication.

This module scans chat messages for links and applies configurable punishments (warnings, kicks, or bans) when links are shared.

Features:

  • Regex-based URL detection
  • Warning and punishment system
  • Custom messages for violations
  • Configurable punishment and reset timing

Ideal For:

  • Blocking phishing or spam links
  • Promoting safer communication environments

Configuration 8

Settings you fill in when installing the module on a server.

SettingTypeDefaultDescription
blockUrls Block URLs boolean true Enable or disable URL blocking
punishmentType Punishment Type string "kick" Action taken when a player sends a link
banDuration Ban Duration number 300000
warningsBeforePunishment Warnings Before Punishment number 1
warningResetTime Warning Reset Time number 600000
kickMessage Kick Message string "Sharing links is not allowed."
banMessage Ban Message string "You have been banned for sharing links. Ban duration: {duration} ms."
noPunishmentMessage No Punishment Message string "Please refrain from sharing links."
Raw config schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "blockUrls": {
      "title": "Block URLs",
      "description": "Enable or disable URL blocking",
      "type": "boolean",
      "default": true
    },
    "punishmentType": {
      "title": "Punishment Type",
      "description": "Action taken when a player sends a link",
      "type": "string",
      "enum": [
        "kick",
        "ban",
        "none"
      ],
      "default": "kick"
    },
    "banDuration": {
      "title": "Ban Duration",
      "type": "number",
      "default": 300000
    },
    "warningsBeforePunishment": {
      "title": "Warnings Before Punishment",
      "type": "number",
      "default": 1
    },
    "warningResetTime": {
      "title": "Warning Reset Time",
      "type": "number",
      "default": 600000
    },
    "kickMessage": {
      "title": "Kick Message",
      "type": "string",
      "default": "Sharing links is not allowed."
    },
    "banMessage": {
      "title": "Ban Message",
      "type": "string",
      "default": "You have been banned for sharing links. Ban duration: {duration} ms."
    },
    "noPunishmentMessage": {
      "title": "No Punishment Message",
      "type": "string",
      "default": "Please refrain from sharing links."
    }
  }
}
Raw UI schema
{}

Hooks 1

Code that runs in reaction to a game or Takaro event.

  • linkChecker

    Hook for chat-message events

    Hook source
    import { takaro, data, TakaroUserError, checkPermission } from '@takaro/helpers';
    
    async function main() {
      const { gameServerId, player, pog } = data;
      if (!pog || !player) return;
      if (checkPermission(pog, 'link_blocker_immunity')) return;
    
      const {
        blockUrls,
        punishmentType,
        warningsBeforePunishment,
        warningResetTime,
        kickMessage,
        banMessage,
        noPunishmentMessage,
        banDuration
      } = data.module.userConfig;
    
      if (!blockUrls) return;
    
      const message = data.eventData.msg.toLowerCase();
      const urlRegex = /https?:\/\/\S+|www\.\S+/g;
      if (!urlRegex.test(message)) return;
    
      const existingVariable = await takaro.variable.variableControllerSearch({
        filters: {
          playerId: [player.id],
          key: ['linkWarnings'],
        },
      });
    
      let currentWarnings = existingVariable.data.data[0]
        ? parseInt(existingVariable.data.data[0].value, 10)
        : 0;
    
      currentWarnings++;
      const now = new Date();
      const warningExpireTime = new Date(now.getTime() + warningResetTime);
    
      let warningText = `You have ${currentWarnings}/${warningsBeforePunishment} warnings. `;
    
      if (punishmentType === 'kick') {
        warningText += kickMessage;
      } else if (punishmentType === 'ban') {
        warningText += banMessage.replace('{duration}', banDuration);
      } else {
        warningText += noPunishmentMessage;
      }
    
      if (currentWarnings >= warningsBeforePunishment && punishmentType !== 'none') {
        if (existingVariable.data.data.length) {
          await takaro.variable.variableControllerDelete(existingVariable.data.data[0].id);
        }
    
        if (punishmentType === 'kick') {
          await takaro.gameserver.gameServerControllerKickPlayer(gameServerId, player.id, {
            reason: 'Shared a prohibited link.',
          });
        } else if (punishmentType === 'ban') {
          const expiresAt = new Date(now.getTime() + banDuration);
          await takaro.player.banControllerCreate({
            gameServerId,
            playerId: player.id,
            until: expiresAt,
            reason: 'Shared a prohibited link.',
          });
        }
    
        await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {
          message: `${player.name} has been ${punishmentType}ed for sharing links.`,
        });
    
      } else {
        await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {
          message: warningText,
          opts: {
            recipient: {
              gameId: pog.gameId,
            },
          },
        });
    
        if (existingVariable.data.data.length) {
          await takaro.variable.variableControllerUpdate(existingVariable.data.data[0].id, {
            value: currentWarnings.toString(),
            expiresAt: warningExpireTime
          });
        } else {
          await takaro.variable.variableControllerCreate({
            playerId: player.id,
            key: 'linkWarnings',
            value: currentWarnings.toString(),
            expiresAt: warningExpireTime
          });
        }
      }
    }
    
    await main();

Permissions 1

Roles you can grant to decide who may use what.

  • InternetLinkBlocker_Immunity

    Grants immunity from link blocking.