{
  "name": "ProfanityFilter",
  "author": "limon",
  "supportedGames": [
    "all"
  ],
  "takaroVersion": "main",
  "versions": [
    {
      "tag": "latest",
      "description": "**Maintain a respectful and positive gaming environment.**\n\nThis module helps you automatically moderate chat and reduce profanity. It allows you to:\n\n* **Customize your list of prohibited words:** Easily add, remove, or modify the list of offensive terms you want to filter.\n* **Choose from various punishment options:** Issue warnings, impose fines (in-game currency), kick, or even ban players for using inappropriate language.\n* **Set up a swear jar:** Encourage players to watch their language by adding a fine to the swear jar for each infraction.\n* **Configure warnings and reset times:** Fine-tune the module's sensitivity by adjusting the number of warnings before punishment and how long it takes for warnings to reset.\n* **Send customizable messages:** Inform players about the rules, warn them about their language, or notify them of the consequences of continued profanity.\n\n**Key Features:**\n\n* Customizable profanity list\n* Flexible punishment options (warnings, fines, kicks, bans)\n* Swear jar functionality\n* Configurable warnings and reset times\n* Customizable messages\n\n**Benefits:**\n\n* Creates a more welcoming and inclusive gaming environment\n* Reduces toxic behavior and promotes positive interactions\n* Encourages players to be mindful of their language\n* Provides a clear and consistent system for moderating profanity",
      "configSchema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"required\":[],\"additionalProperties\":false,\"properties\":{\"HVB_Profanity\":{\"title\":\"HVB_Profanity\",\"description\":\"add the words you want\",\"default\":[\"faggot\",\"shit\",\"gay\",\"cunt\",\"fegg\",\"homo\",\"gey\",\"fag\"],\"type\":\"array\",\"items\":{\"type\":\"string\"},\"minItems\":1,\"maxItems\":10},\"noPunishmentMessage\":{\"title\":\"noPunishmentMessage\",\"description\":\"Send a message top make the player  know that he should not swear.\",\"default\":\"Please stop swearing!\",\"type\":\"string\",\"minLength\":1,\"maxLength\":100},\"punishmentType\":{\"title\":\"punishmentType\",\"description\":\"this is to decide what to do  kick ban\",\"default\":\"kick\",\"type\":\"string\",\"enum\":[\"kick\",\"ban\",\"none\"]},\"banDuration\":{\"title\":\"banDuration\",\"description\":\"If you choose ban, you can decide how long\",\"default\":300000,\"x-component\":\"duration\",\"type\":\"number\"},\"warningsBeforePunishment\":{\"title\":\"warningsBeforePunishment\",\"default\":1,\"type\":\"number\",\"maximum\":100},\"warningResetTime\":{\"title\":\"warningResetTime\",\"default\":600000,\"x-component\":\"duration\",\"type\":\"number\"},\"kickMessage\":{\"title\":\"kickMessage\",\"description\":\"Continuing will result in being kicked.\",\"default\":\"Continuing will result in being kicked.\",\"type\":\"string\",\"minLength\":1,\"maxLength\":100},\"banMessage\":{\"title\":\"banMessage\",\"description\":\"Continuing will result in a {duration} ban\",\"default\":\"Continuing will result in a {duration} ban\",\"type\":\"string\",\"minLength\":1,\"maxLength\":100},\"enableSwearJar\":{\"title\":\"enableSwearJar\",\"description\":\"Enable the swear jar\",\"default\":false,\"type\":\"boolean\"},\"swearJarAmount\":{\"title\":\"swearJarAmount\",\"description\":\"swearJarAmount\",\"default\":0,\"type\":\"number\"}}}",
      "uiSchema": "{}",
      "commands": [],
      "hooks": [
        {
          "name": "profanityChecker",
          "eventType": "chat-message",
          "description": "Hook for chat-message events",
          "regex": null,
          "function": "import { takaro, data, TakaroUserError, checkPermission } from '@takaro/helpers';\n\nasync function main() {\n    const { gameServerId, player, pog } = data;\n    if (!pog || !player) return;\n    if (checkPermission(pog, `item_ban_immunity`)) {\n        return;\n    }\n\n    const existingVariable = await takaro.variable.variableControllerSearch({\n        filters: {\n            playerId: [player.id],\n            key: ['profanity'],\n        },\n    });\n\n    const {\n        warningsBeforePunishment,\n        noPunishmentMessage,\n        kickMessage,\n        banMessage,\n        HVB_Profanity,\n        punishmentType,\n        banDuration,\n        enableSwearJar,\n        swearJarAmount,\n        warningResetTime\n    } = data.module.userConfig;\n\n    let currentWarnings = existingVariable.data.data[0] ? parseInt(existingVariable.data.data[0].value, 10) : 0;\n    const now = new Date();\n    const warningExpireTime = new Date(now.getTime() + warningResetTime);\n\n    for (const profanity of HVB_Profanity) {\n        if (data.eventData.msg.toLowerCase().includes(profanity)) {\n            currentWarnings++;\n\n            let warningText = '';\n            if (punishmentType !== 'none') {\n                warningText = `You have received ${currentWarnings} of ${warningsBeforePunishment} warnings. `;\n            }\n\n            if (enableSwearJar) {\n                try {\n                    await takaro.playerOnGameserver.playerOnGameServerControllerDeductCurrency(\n                        gameServerId,\n                        player.id,\n                        { currency: swearJarAmount }\n                    );\n                    warningText += `${swearJarAmount} coins have been added to the swear jar. `;\n                } catch (error) {\n                    console.error('Failed to deduct currency:', error);\n                }\n            }\n\n            if (punishmentType === 'kick') {\n                warningText += kickMessage;\n            } else if (punishmentType === 'ban') {\n                warningText += banMessage.replace('{duration}', banDuration);\n            } else if (punishmentType === 'none') {\n                warningText += noPunishmentMessage;\n            }\n\n            if (currentWarnings >= warningsBeforePunishment && punishmentType !== 'none') {\n                if (punishmentType === 'kick') {\n                    if (existingVariable.data.data.length) {\n                        await takaro.variable.variableControllerDelete(existingVariable.data.data[0].id);\n                    }\n\n                    await takaro.gameserver.gameServerControllerKickPlayer(gameServerId, player.id, {\n                        reason: `You sweared too much`,\n                    });\n\n                    await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {\n                        message: `${player.name} has been kicked for profanity.`,\n                    });\n                } else if (punishmentType === 'ban') {\n                    if (existingVariable.data.data.length) {\n                        await takaro.variable.variableControllerDelete(existingVariable.data.data[0].id);\n                    }\n\n                    const expiresAt = new Date(now.getTime() + banDuration);\n                    await takaro.player.banControllerCreate({\n                        gameServerId,\n                        playerId: player.id,\n                        until: expiresAt,\n                        reason: `You sweared too much`,\n                    });\n\n                    await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {\n                        message: `${player.name} has been banned for profanity.`,\n                    });\n                }\n            } else {\n                await takaro.gameserver.gameServerControllerSendMessage(gameServerId, {\n                    message: warningText,\n                    opts: {\n                        recipient: {\n                            gameId: pog.gameId,\n                        },\n                    },\n                });\n\n                if (existingVariable.data.data.length) {\n                    await takaro.variable.variableControllerUpdate(existingVariable.data.data[0].id, {\n                        value: currentWarnings.toString(),\n                        expiresAt: warningExpireTime\n                    });\n                } else {\n                    await takaro.variable.variableControllerCreate({\n                        playerId: player.id,\n                        key: 'profanity',\n                        value: currentWarnings.toString(),\n                        expiresAt: warningExpireTime\n                    });\n                }\n            }\n            break;\n        }\n    }\n}\n\nawait main();"
        }
      ],
      "cronJobs": [],
      "functions": [],
      "permissions": [
        {
          "permission": "profanity_immunity",
          "friendlyName": "HVB_PROFANITY_FILTER_v3_HVB_PROFANITY_FILTER_v2_profanity_immunity ",
          "description": "This grants immunity for profanity",
          "canHaveCount": false
        }
      ]
    }
  ]
}