MediaWiki:AutoMod.js

/** * @Name           AutoMod * @Version        v1.0 * @Author         TheGoldenPatrik1 * @UsingCodeBy    Mario&LuigiBowser'sInsideStory * @Description    Automatically moderate chat. */ $(function {   // Get config    var config = mw.config.get([ 'wgCanonicalSpecialPageName', 'wgUserGroups' ]);   // Load protection    if ( config.wgCanonicalSpecialPageName !== 'Chat' || !/staff|helper|sysop|threadmoderator|chatmoderator/.test(config.wgUserGroups.join) || window.AutoModLoaded ) {       return;    }    window.AutoModLoaded = true;    // Main function    function init(i18n) {        mainRoom.socket.bind('chat:add', function(msg) { // Variables var data = JSON.parse(msg.data).attrs, text = data.text.toLowerCase, self = data.name !== mw.config.get('wgUserName'); // Kick if (               window.AutoMod.kick !== undefined &&                new RegExp(text, 'm').test(window.AutoMod.kick.join('|')) &&                self            ) { mainRoom.kick({                   name: data.name                }); }           // Ban if (               window.AutoMod.ban !== undefined &&                new RegExp(text, 'm').test(window.AutoMod.ban.words.join('|')) &&                self            ) { mainRoom.socket.send(new models.BanCommand({ userToBan: data.name, time: window.AutoMod.ban.duration || 86400, reason: window.AutoMod.ban.reason || i18n.msg('reason').plain }).xport); }       });    }    // Load script    mw.hook('dev.chat.render').add(function(mainRoom) { mw.hook('dev.i18n').add(function(i18n) {           i18n.loadMessages('AutoMod').then(init);        }); });   // Imports    importArticles({ type: 'script', articles: [ 'u:dev:Chat-js.js', 'u:dev:I18n-js/code.js' ]   }); });