Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.logInterval = 900000;
  2. if (wgCityId == '1534124') {
  3. importArticles({
  4.     type: 'script',
  5.     articles: [
  6.         'u:dev:ChatLogger.js',
  7.     ]
  8. });
  9.  
  10.  (function() {
  11.     if (mw.config.get('wgCanonicalSpecialPageName') !== 'Chat' || window.BotAntiSpamLoaded) {
  12.         return;
  13.     }
  14.     window.BotAntiSpamLoaded = true;
  15.     var BotAntiSpam = {
  16.         config: $.extend({
  17.             banAfter: 3,
  18.             time: 5,
  19.             size: 10,
  20.             reason: 'Automatically banned for misbehaving in chat.',
  21.             length: 86400,
  22.             lineSep: 1.5,
  23.             links: 10,
  24.             overflow: 300
  25.         }, window.BotAntiSpamConfig),
  26.         init: function() {
  27.             this.data = JSON.parse(localStorage.getItem('BotAntiSpamData') || '{}');
  28.             this.joinTime = Number(new Date());
  29.             this.flood = {};
  30.             mainRoom.model.chats.bind('afteradd', $.proxy(this.onMessage, this));
  31.         },
  32.         onMessage: function(msg) {
  33.             var attr = msg.attributes,
  34.                 user = attr.name,
  35.                 time = attr.timeStamp,
  36.                 text = attr.text;
  37.             if (time < this.joinTime) {
  38.                 return;
  39.             }
  40.             var match = text.match(/https?:\/\//g);
  41.             if (match && match.length > this.config.links) {
  42.                 this.execute(user);
  43.                 return;
  44.             }
  45.             var lines = Math.ceil(text.split('\n').length / this.config.lineSep) +
  46.                         Math.round(text.length / this.config.overflow);
  47.             for (var i = 0; i < lines; ++i) {
  48.                 this.flood[user] = this.flood[user] || [];
  49.                 this.flood[user].push(time);
  50.                 if (this.flood[user].length > this.config.size) {
  51.                     this.flood[user].shift();
  52.                     if ((time - this.flood[user][0]) / 1000 <= this.config.time) {
  53.                         this.execute(user);
  54.                     }
  55.                 }
  56.             }
  57.         },
  58.         execute: function(user) {
  59.             this.data[user] = (this.data[user] || 0) + 1;
  60.             if (this.data[user] === this.config.banAfter) {
  61.                 delete this.data[user];
  62.                 mainRoom.socket.send(new models.BanCommand({
  63.                     userToBan: user,
  64.                     reason: this.config.reason,
  65.                     time: this.config.length
  66.                 }).xport());
  67.             } else {
  68.                 mainRoom.socket.send(new models.KickCommand({
  69.                     userToKick: user
  70.                 }).xport());
  71.             }
  72.             localStorage.setItem('BotAntiSpamData', JSON.stringify(this.data));
  73.         }
  74.     };
  75.     $($.proxy(BotAntiSpam.init, BotAntiSpam));
  76. })();
  77.  
  78.  var words = ['fuck', 'hahaha', 'oo hoo',],
  79.     mainRoom;
  80. mw.hook('dev.chat').add(function (chat) {
  81.     if (wgCityId != '1534124') return;
  82.     mainRoom.socket.bind('chat:add', function(msg) {
  83.         var data = JSON.parse(msg.data).attrs,
  84.         user = mainRoom.model.users.findByName(data.name),
  85.         since = user.attributes.since[0] * 1000 || Date.now();
  86.         if (new RegExp(words.join('|').toUpperCase(), 'm').test(data.text) && Date.now() - since < 1000 * 60 * 60 * 24 * 30) {
  87.             mainRoom.socket.send(JSON.stringify({
  88.                 attrs: {
  89.                     msgType: 'command',
  90.                     command: 'ban',
  91.                     userToBan: data.name,
  92.                     time: 86400,
  93.                     reason: 'Automatically banned for misbehaving in chat.'
  94.                 }
  95.             }));
  96.         }
  97.     });
  98. });
  99. importArticle({
  100.     type: 'script',
  101.     article: 'u:dev:Chat-js.js'
  102. });
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement