NeonBot-Code

//inspired by the great Dorumin
//<syntaxhighlight lang="javascript">
//

// Is after
$.fn.isAfter = function(sel) {

```
   return this.prevAll(sel).length !== 0;

```

};

function callAPI(data, method, callback) {

```
   data.format = 'json';
   $.ajax({
       data: data,
       dataType: 'json',
       url: wgScriptPath + '/api.php',
       type: method,
       success: function(response) {
           if (response.error)
               showError('API error: ' + response.error.info);
           else
               callback(response);
       },
       error: function(xhr, error) {
           showError('AJAX error: ' + error);
       }
   });

```

}

var kickcount = 0,

```
   cbancount = 0,
   quitcount = 0,
   joincount = 0,
   chatcount = 0,
   kickmsg = " \\[\\[User:.*\\|.*]] was sent to the principle \\[\\[User:.*\\|.*]] office",
   cbanmsg = "\\[\\[User:.*\\|.*]] was sent to the detention by \\[\\[User:.*\\|.*]] office*",
   quitmsg = "\\[\\[User:.*\\|.*]] has warped out",
   joinmsg = "\\[\\[User:.*\\|.*]] has warped into the Crystal Palace";

```

var months = [

```
       "January",
       "February",
       "March",
       "April",
       "May",
       "June",
       "July",
       "August",
       "September",
       "October",
       "November",
       "December"
   ],

```

 logText = '';

mw.util.addCSS('.faded{color:grey;}');

setTimeout(function() {

```
   $('.Chat li').each(function() {
       if (!$(this).isAfter('.inline-alert') && !$(this).hasClass('inline-alert')) {
           $(this).children('.message').attr('class', 'faded');
       }
   });

   var arr = [];
   $('#WikiChatList .username:not(.UserStatsMenu .username)').each(function() {
       arr.push($(this).html());
   });
   for (var i = 0; i < arr.length; i++) {
       curDate = new Date();
       localStorage.setItem('seen ' + arr[i], "Last time I saw " + arr[i] + ' was on: ' +
           weekdays[curDate.getDay()] + ', ' +
           months[curDate.getMonth()] + " " +
           curDate.getDate() + ', ' +
           curDate.getFullYear() + " at " +
           (curDate.getUTCHours() < 10 ? '0' : *) + curDate.getUTCHours() + ":" +*
           (curDate.getUTCMinutes() < 10 ? '0' : *) + curDate.getUTCMinutes() + ":" +*
           (curDate.getUTCSeconds() < 10 ? '0' : *) + curDate.getUTCSeconds() + ' (UTC)');*
   }

```

}, 15000);

```
$('[name="message"]').keypress(function (e) {
   if (e.which == 32 || e.which == 13) {
       switch (this.value) {
       case '/refresh':
           this.value = 'Read this: https://en.wikipedia.org/wiki/Wikipedia:REFRESH';
           break;
       case '/blocks':
           this.value = wgSiteName + ' chat is not the place to discuss blocks/bans on this or another wiki. Also, please read this if you have any problems: Special:Contact/blocked';
           break;
       case '/crules':
           this.value = 'Please read the chatroom rules.';
           break;
       case '/change':
           this.value = 'If you would like to request that your account be renamed please see Help:Changing your username';
           break;
       case '/greet':
           this.value = 'Hello and welcome to ' + wgSiteName + ' chat!';
           break;
       case '/logs':
           this.value = 'You can view the logs here.';
           break;
       case '/emotes':
           this.value = 'You can view the emoticons here.';
           break;
       case '/rules':
           this.value = 'You can read the Wikia\'s rules here.';
           break;
       case '/tou':
           this.value = 'Wikia\'s Terms of Use can be found here.';
           break;
       case '/dogs':
           this.value = 'Who let the dogs out?!?! https://www.youtube.com/watch?v=Qkuu0Lwb5EM (づ｡◕‿‿◕｡)づ';
           break;
                   case '!hello':
                       this.value = 'Hi buddy, how are you today?';
                       break;
                   case   '!bye':
                       this.value = 'Good bye bud, I wish you the best and may you be blessed';
                       break;
                   case   '!bot':
                       this.value = 'Who said BOT?!';
                       this.value = 'Enjoy viewing http://github.com/Ditto-Creeper/Chatbot-Ruby';
                       break;
                   case   '!site':
                       this.value = 'My scripts are being used for secretive purposes, try using http://github.com/Ditto-Creeper/Chatbot-Ruby for once.';
                       break;
                   case   '!tou':
                       this.value = 'Wikia\'s Terms of Use are located here.';
                       break;
                   case   '!rules':
                       this.value = 'You can find the chat rules here.';
                       break;
                   case   '!funny':
                       this.value = ' let\'s have a duel in http://playc4.com' ;
                       break;
                   case   '!donut':
                       this.value = 'I only eat Dunkin Donuts';
                       break;
                   case   '!baby':
                       this.value = 'What\?\! don\'t these commands look familiar XD';
                       break;
                   case   '!junk':
                       this.value = '/me gives' + n + 'flowers';
                       break;
                   case   '!holy asteroids':
                       this.value = 'indeed, it\'s [big] Holy Asteroids';
                       break;
                   case   '!ha':
                       this.value = '[c="red"] [big] [font="chiller"] Whatcha lookin at? [/font] [/big] [/c]';
                       break;
                   case   '!mod':
                       this.value = 'Mod ping activated, please wait 8 minutes before using it again.';
                       break;
                   case   '!admin':
                       this.value = 'There\'re currently no admin pings but the !-mod ping works for admins and mods alike. Please consider using it wisely ';
                       break;
                   case   '!minimodding':
                       this.value = ';-; Sorry about that bud ';
                       break;
                   case   '!chaos':
                       this.value = 'I have achieved chaos because of the incident in 26th of April 2015';
                       break;
                   case   '!peace':
                       this.value = 'There\'s still peace in my heart for everyone and everything, may the Universe/God bless all the peaceful beings and important thing in our lives and those things which need them';
                       break;
                   case   '!don\'t fail me':
                       this.value = 'I would be honored to stand beside you all the way. I shall help you lead to victory \\o/';
                       break;
                    case   '!aloha':
                       this.value = 'Aloha my Hawaii...Hawaaee...Huwaee...Hula dancer friend XD';
                       break;
                   case   '!dunkindonuts':
                       this.value = '[small] GET ME THOSE DONUTS NOW XD';
                       break;
                   case   '!spam':
                       this.value = ',You\'ve violated the rules, please wait for your judgement.';
                       break;
                   case   '!dittotron':
                       this.value = ',Dittotron is supported here but does not meet it\'s liceanse to be used. Please Contact another user who does not care about the rules because I sure do.....I hope';
                       break;
                   case   '!ask':
                      this.value = ' What would you ask me?';
                       break;
                   case   '!dragons':
                       this.value = ', the first song I have ever heard was \'Headstrong\' with dragon pictures';
                       break;
                   case   '!memes':
                       this.value = '[c="red"] [big] [font="chiller"] Wow? How is this working for users? XD [/font] [/big] [/c]';
                       break;
       }
   }

```

});
// Send function
var send = function(m) {

```
       mainRoom.socket.send(new models.ChatEntry({
           roomId: this.roomId,
           name: mw.config.get('wgUserName'),
           text: m
       }).xport());
   },

```

```
   // Swears
   SWEARS = [
       "\\bfuck",
       "\\bmotherfuck",
       "\\bshit\\b",
       "\\bshitt",
       "\\bbitch",
       "\\bcunt",
       "\\bdafuq\\b",
       "\\bwhore\\b",
       "\\bmofo\\b",
       "\\bfml\\b",
       "\\bgtfo\\b",
       "\\bstfu\\b",
       "\\bwtf\\b",
       "\\bidfk\\b",
       "\\bidfc\\b",
       "\\bidgaf\\b",
       "\\bidefk\\b",
       "\\bjfc\\b",
       "\\bomf",
       "\\bffs\\b",
       "\\bw t f",
       "\\bmilf\\b"
   ],

   // Slurs
   SLURS = [
       "\\bnigg",
       "\\bniglet\\b",
       "\\bfag\\b",
       "\\bfagg"
   ];

```

weekdays = [

```
       "Sunday",
       "Monday",
       "Tuesday",
       "Wednesday",
       "Thursday",
       "Friday",
       "Saturday"
   ],

   months = [
       "January",
       "February",
       "March",
       "April",
       "May",
       "June",
       "July",
       "August",
       "September",
       "October",
       "November",
       "December"
   ],

   // Function itself
   BotCheck = function(chat) {
       // Logging
       if (!$('#entry-' + chat.cid).isAfter('.inline-alert')) return;
       var t = chat.attributes.text,
           te = mw.html.escape(t);
       var n = chat.attributes.name,
           ne = mw.html.escape(n);
       cid = chat.cid;
       var msgType;
       if (n ===  *&& new RegExp(joinmsg, 'mi').test(t)) {*
           msgType = ' [JOIN] ';
           joincount++;
       } else if (n ===  *&& new RegExp(quitmsg, 'mi').test(t)) {*
           msgType = ' [QUIT] ';
           quitcount++;
       } else if (n ===  *&& new RegExp(kickmsg, 'mi').test(t)) {*
           msgType = ' [KICK] ';
           kickcount++;
       } else if (n ===  *&& new RegExp(cbanmsg, 'mi').test(t)) {*
           msgType = ' [CBAN] ';
           cbancount++;
       } else {
           msgType = ' [CHAT] ';
           chatcount++;
       }
       var msgDate = new Date();
       if (msgType == ' [CHAT] ') {

```

 logText = logText.replace('', '[' + (msgDate.getUTCHours() < 10 ? '0' : *) + msgDate.getUTCHours() + ':' + (msgDate.getUTCMinutes() < 10 ? '0' :* ) + msgDate.getUTCMinutes() + ':' + (msgDate.getUTCSeconds() < 10 ? '0' : *) + msgDate.getUTCSeconds() + ']' + msgType + n + ': ' + t + '\n');*

```
       } else {

```

 logText = logText.replace('', '[' + (msgDate.getUTCHours() < 10 ? '0' : *) + msgDate.getUTCHours() + ':' + (msgDate.getUTCMinutes() < 10 ? '0' :* ) + msgDate.getUTCMinutes() + ':' + (msgDate.getUTCSeconds() < 10 ? '0' : *) + msgDate.getUTCSeconds() + ']' + msgType + t + '\n');*

```
       }
       // Other checking
       if (chat.attributes.name !== mw.config.get('wgUserName')) {
           if (localStorage.getItem('disabled') !== 'disabled') {
               for (var i = 0; i < SWEARS.length; i++) {
                   if (new RegExp(SWEARS[i], "mi").test(t) === true) {
                       send(n + ', please don\'t swear!');
                       setTimeout(function() {
                           mainRoom.kick({
                               name: n
                           });
                       }, 200);
                   }
               }
               // ban for slurs
               for (var i = 0; i < SLURS.length; i++) {
                   if (new RegExp(SLURS[i], "mi").test(t) === true) {
                       send(n + ', please don\'t use that language.');
                       mainRoom.socket.send(new models.BanCommand({
                           userToBan: n,
                           time: 86400,
                           reason: 'Slur'
                       }).xport());
                   }
               }
           }
           // Commands
           if (mainRoom.model.users.findByName(n).attributes.isModerator) {
               switch (true) {
                   case /^\!on/.test(t):

                       if (localStorage.getItem('OBenabled') !== 'enabled') {
                           localStorage.setItem('OBenabled', 'enabled');
                           send('Booting up!');
                       } else {
                           send('Already up and running!');
                       }
                       break;
                   case /^\!off/.test(t):

                       if (localStorage.getItem('OBenabled') !== 'disabled') {
                           localStorage.setItem('OBenabled', 'disabled');
                           send('Shutting down...');
                       } else {
                           send('...');
                       }
                       break;
                   case /^\!enable/.test(t):

                       if (localStorage.getItem('disabled') === 'disabled') {
                           localStorage.setItem('disabled', 'enabled');
                           send('Enabling swear checking!');
                       } else {
                           send('Swear checking is already enabled!');
                       }
                       break;
                   case /^\!disable/.test(t):

                       if (localStorage.getItem('disabled') !== 'disabled') {
                           localStorage.setItem('disabled', 'disabled');
                           send('Swear checking disabled.');
                       } else {
                           send('Swear checking is already disabled.');
                       }
                       break;
                   case /^\!leave/.test(t):

                       send('I\'m so sorry...');
                       window.open('/wiki/User:I_love_the_Smell_of_Napalm_after_I_bang_Gay_Lenhi', '_self');
                       break;
                   case t === '!restart':
                       submitLogs();
                       send('restarting...');
                       setTimeout(function() {
                           window.location.reload();
                       }, 7000);
                       break;
                   case t === '!log':
                       submitLogs();
                       send('log\'d');
                       break;
               }
               if (localStorage.getItem('OBenabled') !== 'enabled') return;
               switch (true) {
                       send(n + ': Please don\'t stretch text.');
                       break;
                   case t === '!hello':
                       send('Hello there ' + n + '!');
                       break;
                   case t === '!bye':
                       send('Goodbye, ' + n + '. Don\'t be gone for long. :(');
                       break;
                   case t === '!emotes':
                       send('You can view the emoticons here. Or the "Emoticons" Rail button, yeah that\'s new and it rendered this command useless.');
                       break;
                   case t === '!logs':
                       send('You can view the logs here.');
                       break;
                   case t === '!test':
                       send('tset¡');
                       break;
                   case t === '!info':
                       send('Commands here. Swear checking: ' + localStorage.getItem('disabled') + '. Commands: ' + localStorage.getItem('OBenabled') + '.');
                       break;
                   case t === '!site':
                       send('You are using Wikia.com, a website dedicated to wiki farming.');
                       break;
                   case t === '!tou':
                       send('Wikia\'s Terms of Use are located here.');
                       break;
                   case t === '!rules':
                       send('You can find the chat rules here.');
                       break;
                   case t === '!fun':
                       send('Fun you say? You may be looking for this: http://theuselessweb.com');
                       break;
                   case t === '!donut':
                       send('[big]◯[/big]');
                       break;
                   case t === '!baby':
                       send('http://www.youtube.com/watch?v=dQw4w9WgXcQ');
                       break;
                   case t === '!swag':
                       send('The user above me has some serious swag.');
                       break;
                   case t === '!space may be the final frontier':
                       send('But it\'s made in a Hollywood basement.');
                       break;
                   case t === '!memes':
                       send('[c="red"] [big] [font="chiller"] not today satan [/font] [/big] [/c]');
                       break;
                   case /has been destabilized by/.test(t):
                       if (n === *) {*
                           localStorage.setItem('lastK', t.replace(/(\(gem destabilizer left\) \[\[User:.*?\||]] has been destabilized by \[\[User:.*\|.*]] \(gem destabilizer right\))/g, *));*
                       }
                       break;
                   case /^\!tell/.test(t):

                       var s = t.slice(6),
                           a = s.split(' that:');

                       if (s === *) {*
                           return;
                       }

                       if (a[0] == n) {
                           send('I\'m not sending yourself a message. Winners don\'t use drugs.');
                           return;
                       }

                       if (a[0] == mw.config.get('wgUserName')) {
                           send('How about no?');
                           return;
                       }

                       if (!localStorage.getItem('tell ' + a[0])) {
                           localStorage.setItem('tell ' + a[0], 'Ah! ' + a[0] + '! ' + n + ' wanted me to tell you: ' + a[1] + '.');
                           send('Okay! I will tell ' + a[0] + ' that next time we meet.');
                       } else {
                           send(a[0] + ' already has a message pending. Please wait for them to speak and try again.');
                       }
                       break;
                   case /^\!seen/.test(t):

                       var x = t.slice(6);

                       if (x === *) {*
                           return;
                       }

                       if (x == n) {
                           send('Heck I dunno, ask ' + n);
                           return;
                       }

                       if (x == mw.config.get('wgUserName')) {
                           send('Right now fam');
                           return;
                       }

                       if (localStorage.getItem('seen ' + x)) {
                           send(localStorage.getItem('seen ' + x));
                       } else {
                           send('I have not seen ' + x + '. Sorry.');
                       }
                       break;
                   case /^\!cleartell/.test(t):

                       var w = t.slice(11);

                       if (w === *) {*
                           return;
                       }

                       if (localStorage.getItem('tell ' + w)) {
                           localStorage.removeItem('tell ' + w)
                           send('Messages for ' + w + ' have been cleared!');
                       } else {
                           send(w + ' has no messages pending!');
                       }
                       break;
                   case /^\!note/.test(t):

                       if (!localStorage.getItem('note ' + n)) {
                           localStorage.setItem('note ' + n, n + ': ' + t.slice(5));
                           send('Noted! I will message it to you next time we meet.');
                       } else {
                           send('You already have given me a note! Winners don\'t use drugs.');
                           send(localStorage.getItem('note ' + n));
                           localStorage.removeItem('note ' + n);
                       }
                       break;
                   case /^\!miss/.test(t):

                       if (t.slice(6) == n) {
                           send('how dang egoistic are you?');
                           break;
                       }

                       if (t.slice(6) == mw.config.get('wgUserName')) {
                           send('Aww thank you ;^>');
                           break;
                       }

                       if (!localStorage.getItem('miss ' + t.slice(6))) {
                           localStorage.setItem('miss ' + t.slice(6), n);
                           send('Okay! I will tell ' + t.slice(6) + ' that you missed them next time we meet.');
                       } else {
                           var l = localStorage.getItem('miss ' + t.slice(6)),
                               h = l.split('~');

                           localStorage.setItem('miss ' + t.slice(6), l + '~' + n);
                           send('Okay! I will message ' + t.slice(6) + ' that you missed them, including ' + h.length + '.');
                       }
                       break;
                   case /^\!warn/.test(t):

                       var wrn = t.slice(6);

                       localStorage.setItem('warn ' + localStorage.getItem('lastK'), localStorage.getItem('lastK') + ': ' + wrn);
                       send('Sure thing.');
                       break;
                   default:
                       curDate = new Date();
                       localStorage.setItem('seen ' + n, "Last time I saw " + n + ' was on: ' +
                           weekdays[curDate.getDay()] + ', ' +
                           months[curDate.getMonth()] + " " +
                           curDate.getDate() + ', ' +
                           curDate.getFullYear() + " at " +
                           (curDate.getUTCHours() < 10 ? '0' : *) + curDate.getUTCHours() + ":" +*
                           (curDate.getUTCMinutes() < 10 ? '0' : *) + curDate.getUTCMinutes() + ":" +*
                           (curDate.getUTCSeconds() < 10 ? '0' : *) + curDate.getUTCSeconds() + ' (UTC)');*
                       if (n ===  *&& t.match(' has warped out')) {*
                           lU = t.replace(/(\[\[User:.*\||]])/g, *).split(' has warped out');*
                           curDate = new Date();
                           localStorage.setItem('seen ' + lU[0], "Last time I saw " + lU[0] + ' was on: ' +
                               weekdays[curDate.getDay()] + ', ' +
                               months[curDate.getMonth()] + " " +
                               curDate.getDate() + ', ' +
                               curDate.getFullYear() + " at " +
                               (curDate.getUTCHours() < 10 ? '0' : *) + curDate.getUTCHours() + ":" +*
                               (curDate.getUTCMinutes() < 10 ? '0' : *) + curDate.getUTCMinutes() + ":" +*
                               (curDate.getUTCSeconds() < 10 ? '0' : *) + curDate.getUTCSeconds() + ' (UTC)');*
                       }
                       if (n ===  *&& t.match(' has warped into the Crystal Palace')) {*
                           jU = t.replace(/(\[\[User:.*\||]])/g, *).split(' has warped into the Crystal Palace');*
                           if (localStorage.getItem('note ' + jU[0])) {
                               send(localStorage.getItem('note ' + jU[0]));
                               localStorage.removeItem('note ' + jU[0]);
                           }

                           if (localStorage.getItem('warn ' + jU[0])) {
                               send(localStorage.getItem('warn ' + jU[0]));
                               localStorage.removeItem('warn ' + jU[0]);
                           }

                           if (localStorage.getItem('tell ' + jU[0])) {
                               send(localStorage.getItem('tell ' + jU[0]));
                               localStorage.removeItem('tell ' + jU[0]);
                           }

                           if (localStorage.getItem('miss ' + jU[0])) {
                               send('Ah! ' + jU[0] + '! ' + localStorage.getItem('miss ' + jU[0]) + ' missed you!');
                               localStorage.removeItem('miss ' + jU[0]);
                           }
                           return;
                       }
                       if (localStorage.getItem('note ' + n)) {
                           send(localStorage.getItem('note ' + n));
                           localStorage.removeItem('note ' + n);
                       }

                       if (localStorage.getItem('tell ' + n)) {
                           send(localStorage.getItem('tell ' + n));
                           localStorage.removeItem('tell ' + n);
                       }

                       if (localStorage.getItem('miss ' + n)) {
                           send('Ah! ' + n + '! ' + localStorage.getItem('miss ' + n) + ' missed you!');
                           localStorage.removeItem('miss ' + n);
                       }
               }
           }
       }
   };

```

if (mw.config.get('wgCanonicalSpecialPageName') == 'Chat') {

```
   mainRoom.model.chats.bind('afteradd', BotCheck);

```

}

// Submits the logs (logText) and then clears them
submitLogs = function() {

```
   var d = new Date();
   var ttl = d.getUTCDate() + '_' + months[d.getUTCMonth()] + '_' + d.getUTCFullYear();
   callAPI({
       'action': 'query',
       'prop': 'info|revisions',
       'intoken': 'edit',
       'titles': 'Project:Chat/Logs/' + ttl,
       'rvprop': 'content',
       'rvlimit': '1',
       'indexpageids': 'true',
   }, 'GET', function(response) {
       var page = response.query.pages[response.query.pageids[0]];
       var pageExists = response.query.pages["-1"] ? false : true;
       var content = typeof(page.revisions) != "undefined" ? page.revisions[0]['*'] : *;*
       if (!pageExists) {
           callAPI({
               'minor': 'yes',
               'bot': 'yes',
               'summary': 'Creating chatlog: ' + kickcount + ' kicks and ' + cbancount + ' bans reported. ' + joincount + ' joins, ' + quitcount + ' leaves, and ' + chatcount + ' messages logged.',
               'action': 'edit',
               'title': 'Project:Chat/Logs/' + ttl,
               'startimestamp': page.starttimestamp,
               'token': page.edittoken,

```

 'text': '

```
\n' + logText + '\n[[Category:Wikia Chat logs|2016 04 23]]'
            }, 'POST', function(response) {
                console.log('Creating chatlog: ' + kickcount + ' kicks and ' + cbancount + ' bans reported. ' + joincount + ' joins, ' + quitcount + ' leaves, and ' + chatcount + ' messages logged.');
                kickcount = 0, cbancount = 0, quitcount = 0, joincount = 0, chatcount = 0, logText = '
```
';

```
               $('#entry-' + cid).prevAll('.Chat li').remove();

```

 $('#entry-' + cid).replaceWith('

- Window cleared.
')
 });
 } else {
 callAPI({
 'minor': 'yes',
 'bot': 'yes',
 'summary': 'Adding to chatlog: ' + kickcount + ' kicks and ' + cbancount + ' bans reported. ' + joincount + ' joins, ' + quitcount + ' leaves, and ' + chatcount + ' messages logged.',
 'action': 'edit',
 'title': 'Project:Chat/Logs/' + ttl,
 'startimestamp': page.starttimestamp,
 'token': page.edittoken,
 'text': content.replace('', logText)

```
           }, 'POST', function(response) {
               console.log('Adding to chatlog: ' + kickcount + ' kicks and ' + cbancount + ' bans reported. ' + joincount + ' joins, ' + quitcount + ' leaves, and ' + chatcount + ' messages logged.');

```

 kickcount = 0, cbancount = 0, quitcount = 0, joincount = 0, chatcount = 0, logText = '';

```
               $('#entry-' + cid).prevAll('.Chat li').remove();

```

 $('#entry-' + cid).replaceWith('

- Window cleared.
')
 });
 }
 });
};

// Sets the actual interval
setInterval(function() {
 submitLogs()
}, logInterval);

// Submit by sending !log
$('[name="message"]').keypress(function(e) {
 if (e.which == 13 && this.value == '!log') {
 this.value = *;*
 submitLogs();
 }
});
//
//<syntaxhighlight lang="javascript">