Nurutomo2

OurWorldOfPixels Chat Bot By Nurutomo

Mar 8th, 2018
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Chat Bot
  2. OWOP.chat.send('Chat Bot by Nurutomo\nUse -help\n/tell ' + OWOP.net.protocol.id + " <commands>");
  3. defaultNick = localStorage.nick;
  4. OWOP.chat.recvModifier = function(msg) {
  5.     if (chatType(msg) == "nickuser") {
  6.         nick = msg.substr((msg.indexOf("]") + 2),(msg.indexOf(": ") - 4));
  7.     }
  8.     if (chatType(msg) == "tell" || chatType(msg) == "nickuser") {
  9.         id = msg.substr(1,msg.indexOf("]") - 1);
  10.     } else {
  11.         if (chatType(msg) == "nonick") {
  12.             id = msg.substr(0,msg.indexOf(": ") - 1);
  13.         }
  14.     }
  15.     console.log(id + nick);
  16.     realText = getRealChat(msg);
  17.     realText = realText;
  18.     if (realText == "-help") {
  19.         sendHelp(msg);
  20.     }
  21.     if (realText.toLowerCase().split(' ')[0] == "-setpixel") {
  22.         console.log(nick);
  23.         x = realText.split(' ')[1];
  24.         y = realText.split(' ')[2];
  25.         r = realText.split(' ')[3];
  26.         g = realText.split(' ')[4];
  27.         b = realText.split(' ')[5];
  28.         x = setMinMax(x, -16777215, 16777215);
  29.         y = setMinMax(y, -16777215, 16777215);
  30.         r = setMinMax(r, 0, 255);
  31.         g = setMinMax(g, 0, 255);
  32.         b = setMinMax(b, 0, 255);
  33.         tp(x, y, false);
  34.         sendChat(msg,'Placed! \nX: ' + x + ' Y: ' + y + '\nrgb( ' + r + ', ' + g + ', ' + b + ')');
  35.         setTimeout(function() {
  36.             console.log(OWOP.world.setPixel(x, y, [r, g, b], 0));
  37.         }, 1000);
  38.     }
  39.     if (realText.toLowerCase() == "-about") {
  40.         console.log(nick);
  41.         sendChat(msg,'Nurutomo\'s Chat Bot v1 \nCredits:\nNurutomo - Commands \nOWOP Script - Get chat, split msg, etc...\nhttps:\/\/pastebin.com\/2UK70sn0');
  42.         setTimeout(function() {
  43.             sendChat(msg,'Discord:\nNurutomo #6541\nBottom-Right for OWOP\'s Discord');
  44.         }, 1000);
  45.         setTimeout(function() {
  46.             sendChat(msg,'You can aslo do with \n/tell ' + myId);
  47.         }, 2000);
  48.     }
  49.     if (realText.toLowerCase().split(' ')[0] == "-setadminnick") {
  50.         console.log(nick);
  51.         message = realText;
  52.         fakeMessage = realText.toLowerCase();
  53.         nick = message.substr(fakeMessage.indexOf('-setadminnick ') + 14,message.length);
  54.         if (nick.length > 12) {
  55.             sendChat(msg,"\nNickname too long! (Max: 12)\n Your nick length: " + nick.length);
  56.         } else {
  57.             sendChat(msg,"\nNickname set to: '" +  nick + "'");
  58.             OWOP.chat.send('/nick ' + nick);
  59.             localStorage["nick"] = defaultNick;
  60.         }
  61.     }
  62.     if (realText.toLowerCase() == "-resetnick") {
  63.         OWOP.chat.send('/nick ' + defaultNick);
  64.         sendChat(msg,"\nNickname set to: '" + defaultNick + "'");
  65.     }
  66.     if (realText.toLowerCase().split(' ')[0] == "-logintp") {
  67.         duration = realText.split(' ')[1];
  68.         pass = realText.split(' ')[2];
  69.         if (pass = load("lol")) {
  70.             save("?", "dont!");
  71.             sendChat(msg,'Log Out in ' + (duration / 1000) + 'sec');
  72.             setTimeout(function() { sendChat(msg,"You has been log out!");save("?", "ok..."); }, duration);
  73.         } else {
  74.             save("?", "ok...");
  75.         }
  76.     }
  77.     if (realText.toLowerCase().split(' ')[0] == "-tp") {
  78.         if (load("?") = "dont!") {
  79.             console.log(nick);
  80.             x = realText.split(' ')[1];
  81.             y = realText.split(' ')[2];
  82.             x = setMinMax(x, -16777215, 16777215);
  83.             y = setMinMax(y, -16777215, 16777215);
  84.             tp(x, y, false);
  85.             sendChat(msg,'\ntp( ' + x + ', ' + y + ')');
  86.         } else {
  87.             sendChat(msg,'You not allowed to do this!\nAsk Owner to allow you!');
  88.         }
  89.     }
  90.     return msg
  91. }
  92.  
  93. function sendHelp(m) {
  94.     helpNone = ['Help: \n-help\n-setPixel <x> <y> <r> <g> <b>\n-setAdminNick <nick>\n-resetNick\n-tp <x> <y> \/\/ You need permission to do this!\n-about','This works too\n/tell ' + OWOP.net.protocol.id + " <commands>"];
  95.     helpLength = helpNone.length;
  96.     for (i = 0; helpLength > i; i++) {
  97.         duration = i * 500;
  98.         setTimeout(sendChat,duration,m,helpNone[i]);
  99.     }
  100.     setTimeout(function() { OWOP.chat.local('Admin Commands:\n-logintp <duration-ms> <password> \n\/\/ Ask Nurutomo on Discord for the password!'); },200);
  101. }
  102.  
  103. WorldOfPixels.camera.teleport = function(x, y) {
  104.     var m = new ArrayBuffer(9);
  105.     var dv = new DataView(m);
  106.     dv.setUint8(0, 3);
  107.     dv.setInt32(1, x, true);
  108.     dv.setInt32(5, y, true);
  109.     var messageEvent = new MessageEvent("message", {
  110.         "data": m,
  111.         "origin": "ws://ourworldofpixels.com:443"
  112.     });
  113.     return WorldOfPixels.net.connection.dispatchEvent(messageEvent);
  114. };
  115.  
  116. function tp(x, y, log) {
  117.     WorldOfPixels.camera.teleport(x, y);
  118.     log = isEmpty(log);
  119.     if (!log) {
  120.         OWOP.chat.local('Teleporting to X: ' + x + ' Y: ' + y);
  121.     }
  122. }
  123.  
  124. function isEmpty(str) {
  125.     return (!str || 0 === str.length);
  126. }
  127.  
  128. function isUndefined(str) {
  129.     return (undefined === str);
  130. }
  131.  
  132. function setMinMax(variable, min, max) {
  133.     if (variable > max) {
  134.         return max;
  135.     } else if (variable < min) {
  136.         return min;
  137.     } else if (isUndefined(variable)) {
  138.         return Math.floor(Math.random() * (max - min));
  139.     } else {
  140.         return variable;
  141.     }
  142. }
  143.  
  144. function getRealChat(message) {
  145.     var nickname = message.split(": ")[0] + ": ";
  146.     var text = message.slice(nickname.length);
  147.     var idIndex = text.indexOf(': ');
  148.     var ntext = text.substr(0, idIndex);
  149.     return ntext.replace(/\d+/g, '') + text.slice(idIndex + 1);
  150. }
  151.  
  152. function save(name, value) {
  153.     localStorage[name.toString()] = value;
  154. }
  155.  
  156. function load(name) {
  157.     return localStorage[name.toString()];
  158. }
  159.  
  160. function sendChat(o,m) {
  161.     if (chatType(o) == "tell") {
  162.         id = o.split(' ')[1];
  163.         OWOP.chat.send("/tell " + id + " "+ m);
  164.     } else {
  165.         OWOP.chat.send(m);
  166.     }
  167. }
  168.  
  169. function chatType(text) {
  170.     text = text.toString();
  171.     if (text.startsWith("[D]")) {
  172.         return "discord";
  173.     } else if (text.startsWith("Server]") || text.startsWith("Server:") || text.startsWith("Nickname set to") || text.startsWith("User: ")) {
  174.         return "server";
  175.     } else if (text.startsWith("->")) {
  176.         return "tell";
  177.     } else if (text.startsWith("(M)")) {
  178.         return "moderator";
  179.     } else if (isNaN(text.split(": ")[0]) && text.split(": ")[0].charAt(0) != "[") {
  180.         return "admin";
  181.     } else if (text.split(": ")[0].charAt(0) == "[") {
  182.         return "nickuser";
  183.     } else {
  184.         return "nonick";
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment