Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. registerPlugin({
  2.     name: "BadNick Check",
  3.     version: "1.2.1",
  4.     enableWeb: true,
  5.     description: "Kicks or Messages People with a Bad Nickname!",
  6.     author: "Multivitamin <multivitamin.wtf>",
  7.     vars: [{
  8.         name: "badnick",
  9.         title: "List of Banned Nicknames",
  10.         type: "multiline"
  11.     }, {
  12.         name: "action",
  13.         title: "What should happen when a Client with a Bad Nickname has been detected?",
  14.         type: "select",
  15.         options: [ "Kick", "Message" ]
  16.     }, {
  17.         name: "message",
  18.         title: "Kick / Warn DEFAULT Message",
  19.         type: "string",
  20.     }, {
  21.         name: "ignore",
  22.         title: "Comma Seperated List of Groups which should get ignored",
  23.         type: "string",
  24.     }]
  25. }, function(sinusbot, config) {
  26.  
  27.     var sinusbot = null
  28.  
  29.     var event = require("event")
  30.     var engine = require("engine")
  31.     var backend = require("backend")
  32.  
  33.     var badnicks = []
  34.  
  35.     //Load the badnick Multiline Variable into a List of Nicks
  36.     if (config.badnick !== undefined) {
  37.         for (var key in config.badnick.split("\n")) {
  38.             //Check for Valid Regex String
  39.             if (config.badnick.split("\n")[key].match(/^[ ]{0,}\/(.{1,})\/([gmixXsuUAJ]{0,10})[ ]{0,}(\->[ ]{0,}(.{1,})|)$/i)) {
  40.                 var capture = config.badnick.split("\n")[key].match(/^[ ]{0,}\/(.{1,})\/([gmixXsuUAJ]{0,10})[ ]{0,}(\->[ ]{0,}(.{1,})|)$/i)
  41.                 var re = new RegExp(capture[1], capture[2])
  42.                 var msg = capture[4]
  43.             //User Probably does not know Regex try to use it anyway
  44.             } else {
  45.                 engine.log("Invalid Regex Format detected! > "+config.badnick.split("\n")[key])
  46.                 var re = new RegExp(config.badnick.split("\n")[key], "i")
  47.                 var msg = undefined
  48.             }
  49.             badnicks.push([re, msg])
  50.         }
  51.     }
  52.  
  53.     //Validate for errors in the Config Input
  54.     var action = parseInt(config.action, 10)
  55.     if (isNaN(action)) action = 0
  56.     var message = config.message ? config.message : "Please do not use this Nickname!"
  57.     var ignore = config.ignore ? config.ignore.split(",") : []
  58.  
  59.     event.on("chat", function (ev) {
  60.         if (ev.client.isSelf()) return
  61.         if (ev.text.match(/^!help ?$/)) {
  62.             ev.client.chat("[b]BAD NICK CHECK[/b] This Bot uses [URL=https://multivitamin.wtf]Multivitamins[/URL] Bad Nick Check Plugin!")
  63.         }
  64.     })
  65.  
  66.     //Events
  67.     //Event for Client Connect / Move
  68.     event.on("clientMove", function(ev) {
  69.         //Filter all Client Connect Events and check against whitelist
  70.         if (!ev.fromChannel && !whitelist(ev.client)) checkNick(ev.client, ev.clientNick)
  71.     })
  72.  
  73.     //Do Initial FullCheck on all Clients connected to the Server
  74.     event.on("connect", function(ev) {
  75.         fullCheck()
  76.     })
  77.     fullCheck()
  78.  
  79.     //Do a check when Client changes its nickname
  80.     event.on("clientNick", function(client) {
  81.         //Check against whitelist
  82.         if (whitelist(client)) return
  83.         checkNick(client)
  84.     })
  85.  
  86.     //Check if Nick is a Bad Nickname
  87.     function checkNick(client){
  88.         for (var key in badnicks) {
  89.             if (client.nick().match(badnicks[key][0])) {
  90.                 engine.log("BadNick detected: "+client.nick()+" via entry \""+badnicks[key][0]+"\"")
  91.                 if (action === 1) return client.chat(badnicks[key][1] !== undefined ? badnicks[key][1] : message)
  92.                 client.kick(badnicks[key][1] !== undefined ? badnicks[key][1] : message)
  93.             }
  94.         }
  95.     }
  96.  
  97.     //Check all Nicknames on the Server
  98.     function fullCheck() {
  99.         //Get a List of all Clients connected to the Server
  100.         backend.getClients()
  101.             .filter(function(client) {
  102.                 return !client.isSelf()
  103.             })
  104.             .filter(function(client) {
  105.                 return !whitelist(client)
  106.             })
  107.             .forEach(checkNick)
  108.     }
  109.  
  110.     //Check if User is whitelisted via Ignore Settings
  111.     function whitelist(client) {
  112.         return client.getServerGroups().some(function(group) {
  113.             return ignore.indexOf(group.id()) >= 0
  114.         })
  115.     }
  116.  
  117. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement