Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const WebSocket = require("ws");
- const translate = require("translate");
- const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
- const fs = require("fs");
- const util = require("util");
- let isdi = require("./istro-dictionary.json");
- let account = {
- email: env.email,
- token: env.token
- };
- let chat = {};
- let messageQueue = [];
- function deepStringify(object, isArray) {
- let output = "";
- for (let i in object) {
- let t = object[i];
- if (typeof t === "object") {
- if (t.length !== undefined) {
- output += (isArray ? "" : `"${i}":`) + `[${deepStringify(t, true)}],`;
- } else {
- output += (isArray ? "" : `"${i}":`) + `{${deepStringify(t)}},`;
- }
- } else if (typeof t === "string") {
- output += (isArray ? "" : `"${i}":`) + `"${t}",`;
- } else {
- output += (isArray ? "" : `"${i}":`) + `${t},`;
- }
- }
- return output.slice(0, output.length - 1);
- }
- function connect() {
- let ws = new WebSocket('ws://198.199.109.223:88');
- function sendMessage(text, channel, max) {
- for (let i = 0; i <= Math.round(text.length / 300); i ++) {
- if (i >= (max ? max : 3))
- return;
- messageQueue.push({text: text.slice(i * 300, i * 300 + 300), channel: channel});
- }
- }
- ws.on("error", e => console.error(e));
- ws.on("open", () => {
- console.log("Connected");
- ws.send(JSON.stringify(["authSignIn", account]));
- ws.send(JSON.stringify(["registerBot"]));
- });
- ws.on('message', msg => {
- let data = JSON.parse(msg);
- if (data[0] === "message") {
- let text = data[1].text;
- let name = data[1].name;
- let channel = data[1].channel;
- if (!chat[channel])
- chat[channel] = [];
- chat[channel].push(data[1]);
- let lines = chat[channel];
- let args = text.split(" ");
- let command = args[0].toLowerCase();
- function msgPointer(ify) {
- let output = text.slice(ify.length + 1);
- if(text.toLowerCase().startsWith(ify + "^")) {
- let num = 0;
- if (parseInt(command.slice(ify.length + 1), 10) > 0) {
- num = parseInt(command.slice(ify.length + 1), 10) + 1;
- } else if (command[ify.length + 1] === "^") {
- while (command[ify.length + 1 + num] === "^") {
- num ++;
- }
- num += 2;
- } else {
- num = 2;
- }
- if (num <= lines.length) {
- name = lines[lines.length - num].name;
- output = lines[lines.length - num].text;
- }
- }
- return output;
- }
- //commands
- if (command === ".ping")
- sendMessage("pong!", channel);
- else if (command === ".help")
- sendMessage("List of commands: .ping, .help, .define, owoify, therxify, voidify, xiaoify, ecclify, snullify, smartify, zalgoify", channel);
- else if (command === ".isdi") {
- let phrase = false;
- if (args[2])
- phrase = isdi[args[2].toLowerCase()];
- if (args[1] === "define") {
- if (!args[2])
- sendMessage("Usage: .isdi define [phrase] <rank>", channel);
- if (phrase) {
- let defList = Object.values(phrase).sort((a, b) => { return b.votes.length - a.votes.length; });
- if (parseInt(args[3]) > 0) {
- let num = parseInt(args[3]);
- if (num <= defList.length)
- sendMessage(num + "/" + defList.length + " definition by " + defList[num - 1].poster + " (" + defList[num - 1].votes.length + " votes): " + defList[num - 1].definition, channel);
- else
- sendMessage("Error: number exceeds definition list length!", channel);
- } else
- sendMessage("Top definition by " + defList[0].poster + " (" + defList[0].votes.length + " votes): " + defList[0].definition, channel);
- } else
- sendMessage("Can not find definition :(", channel);
- }
- else if (args[1] === "add") {
- if (!args[2] || !args[3])
- sendMessage("Usage: .isdi add [phrase] [definition]", channel);
- else {
- if (!phrase)
- isdi[args[2].toLowerCase()] = {};
- if (isdi[args[2].toLowerCase()][name.toLowerCase()])
- sendMessage("You already made a definition for this phrase, use '.isdi remove [phrase]' to remove your definition.", channel);
- else {
- let def = args.splice(3, args.length).join(" ");
- isdi[args[2]][name.toLowerCase()] = {definition: def, poster: name.toLowerCase(), votes: []};
- fs.writeFileSync("istro-dictionary.json", `{${deepStringify(isdi)}}`);
- sendMessage(`Created new definition for ${args[2]}: ${def}`, channel);
- }
- }
- }
- else if (args[1] === "vote") {
- if (!args[2] || !args[3])
- sendMessage("Usage: .isdi vote [phrase] [poster]", channel);
- else if (!phrase)
- sendMessage("Can not find phrase :(", channel);
- else if (!phrase[args[3].toLowerCase()])
- sendMessage("Can not find poster :(", channel);
- else {
- for (let i of phrase[args[3].toLowerCase()].votes) {
- if (i === name.toLowerCase())
- return sendMessage("You already voted for this phrase!", channel);
- }
- isdi[args[2].toLowerCase()][args[3].toLowerCase()].votes.push(name.toLowerCase());
- fs.writeFileSync("istro-dictionary.json", `{${deepStringify(isdi)}}`);
- sendMessage("You voted for this post!", channel);
- }
- } else
- sendMessage("Usage: .isdi [action (define:list:vote:add:remove)]", channel);
- }
- else if (command === ".define") {
- let xhr = new XMLHttpRequest();
- xhr.open("GET", "https://www.urbandictionary.com/define.php?term=" + args.splice(1).join("+"), true);
- xhr.onreadystatechange = async function() {
- if (xhr.readyState === 4) {
- let response = xhr.responseText;
- if (response.includes("Sorry, we couldn't find"))
- return sendMessage("Can not find definition :(", channel);
- response = response.slice(response.indexOf("class=\"meaning") + 16, response.length);
- response = response.slice(0, response.indexOf("</div>")).replace(/<br\/>/g, " ").replace(/'/g, "'").replace(/"/g, '"').split("<a").join("</a>").split("</a>").join(");\">").split(");\">");
- for (let i = 0; i < response.length; i ++) {
- if (response[i].startsWith(" class=\"autolink\""))
- response.splice(i, 1);
- }
- sendMessage("Definition from Urban Dictionary: " + response.join(""), channel);
- }
- };
- xhr.send(null);
- }
- else if (text.toLowerCase().startsWith("snullify")) {
- let output = msgPointer("snullify").split(" ");
- for (let i = 0; i < output.length; i ++) {
- if (" hello hey hi ".includes(" " + output[i] + " ")) {
- output[i] += ", r-retard ";
- }
- if (Math.random() < 0.2 || i === 0) {
- output[i] = output[i][0] + "-" + output[i];
- }
- }
- output = output.join(" ");
- if (!".,?!:;".includes(output[output.length - 1]))
- output += "...";
- sendMessage(name + ": " + output, channel)
- }
- else if (text.toLowerCase().startsWith("ecclify")) {
- let output = msgPointer("ecclify");
- let random = Math.random();
- if (random <= 0.25) {
- sendMessage(name + ": " + output + ", also im gay lol", channel, 1);
- } else if (random <= 0.5) {
- sendMessage(name + ": " + output + ", eat my ass", channel, 1);
- } else if (random <= 0.75) {
- sendMessage(name + ": " + output + " libtard", channel, 1);
- } else {
- for (let i = 3; i < 5 + Math.random() * 10; i ++) {
- output += ".";
- }
- sendMessage(name + ": " + output, channel, 1);
- }
- }
- else if (text.toLowerCase().startsWith("zalgoify")) {
- let output = msgPointer("zalgoify").split(" ");
- let zalgoUp = ["\u030d", "\u030e", "\u0304", "\u0305", "\u033f", "\u0311", "\u0306", "\u0310", "\u0352", "\u0357", "\u0351", "\u0307","\u0308", "\u030a", "\u0342", "\u0343","\u0344", "\u034a", "\u034b", "\u034c", "\u0303", "\u0302", "\u030c", "\u0350", "\u0300", "\u0301", "\u030b", "\u030f", "\u0312", "\u0313", "\u0314", "\u033d", "\u0309", "\u0363", "\u0364", "\u0365", "\u0366", "\u0367", "\u0368", "\u0369", "\u036a", "\u036b", "\u036c", "\u036d", "\u036e", "\u036f", "\u033e", "\u035b", "\u0346", "\u031a"];
- let zalgoMid = ["\u0315", "\u031b", "\u0340", "\u0341", "\u0358", "\u0321", "\u0322", "\u0327", "\u0328", "\u0334", "\u0335", "\u0336", "\u034f", "\u035c", "\u035d", "\u035e", "\u035f", "\u0360", "\u0362", "\u0338", "\u0337", "\u0361", "\u0489"];
- let zalgoDown = ["\u0316", "\u0317", "\u0318", "\u0319", "\u031c", "\u031d", "\u031e", "\u031f", "\u0320", "\u0324", "\u0325", "\u0326", "\u0329", "\u032a", "\u032b", "\u032c", "\u032d", "\u032e", "\u032f", "\u0330", "\u0331", "\u0332", "\u0333", "\u0339", "\u033a", "\u033b", "\u033c", "\u0345", "\u0347", "\u0348", "\u0349", "\u034d", "\u034e", "\u0353", "\u0354", "\u0355", "\u0356", "\u0359", "\u035a", "\u0323"];
- for (let i = 0; i < output.length; i ++) {
- if (output[i] === " ")
- continue;
- for (let j = 0; j < Math.random() * 10; j ++) {
- output[i] += zalgoUp[Math.floor(Math.random() * zalgoUp.length)];
- }
- for (let j = 0; j < Math.random() * 10; j ++) {
- output[i] += zalgoDown[Math.floor(Math.random() * zalgoDown.length)];
- }
- output[i] += zalgoMid[Math.floor(Math.random() * zalgoMid.length)];
- }
- sendMessage(name + ": " + output.join(""), channel, 1);
- }
- else if (text.toLowerCase().startsWith("smartify")) {
- let output = msgPointer("smartify").split(" ");
- let stopWords = " i am the ";
- for (let i = 0; i < output.length; i ++) {
- if (stopWords.includes(output[i]) && i !== output.length - 1)
- continue;
- let xhr = new XMLHttpRequest();
- xhr.open("GET", "https://www.thesaurus.com/browse/" + output[i].toLowerCase(), true);
- xhr.onreadystatechange = async function() {
- if (xhr.readyState === 4) {
- let response = xhr.responseText;
- response = response.slice(response.indexOf("h2"), response.length);
- response = response.slice(0, response.indexOf("</ul>")).replace(/li/, "").split("<a");
- response = response.splice(1, response.length);
- for (let j = 0; j < response.length; j ++) {
- response[j] = response[j].slice(response[j].indexOf("\">") + 2, response[j].indexOf("</a"));
- }
- response.sort((a, b) => { return b.length - a.length; });
- if (response[0])
- output[i] = await response[0];
- if (i === output.length - 1) {
- sendMessage(name + ": " + output.join(" "), channel, 1);
- }
- }
- };
- xhr.send(null);
- }
- }
- else if (text.toLowerCase().startsWith("owoify")) {
- let output = msgPointer("owoify").split(" ");
- for (let i in output) {
- for (let j = 0; j < output[i].length; j ++) {
- if (j > 0 && "aeiou".includes(output[i][j]) && output[i][j - 1].toLowerCase() !== "w") {
- output[i] = output[i].slice(0, j) + "w" + output[i].slice(j);
- break;
- }
- }
- let random = Math.random();
- if (random < 0.1) {
- output[i] += " OwO ";
- } else if (random < 0.2) {
- output[i] += " ~nuzzles~ ";
- }
- }
- sendMessage(name + ": " + output.join(" "), channel, 1);
- }
- else if (text.toLowerCase().startsWith("therxify")) {
- let output = msgPointer("therxify").split(" ");
- let keyboard = [
- "qwertyuiop",
- "asdfghjkl;",
- "zxcvbnnm,."
- ];
- let splitSize = output.length > 5 ? Math.ceil(output.length / 3) : 6; //3 chunks max
- output = [output.slice(0, splitSize).join(" "), output.slice(splitSize, splitSize * 2).join(" "), output.slice(splitSize * 2, splitSize * 3 + 1).join(" ")];
- for (let i = 0; i < output.length; i ++) {
- for (let j = 0; j < output[i].length; j ++) {
- if (Math.random() < 0.15) {
- let letter = output[i][j];
- let index = -1;
- if (keyboard[0].includes(letter)) {
- index = 0;
- } else if (keyboard[1].includes(letter)) {
- index = 1;
- } else if (keyboard[2].includes(letter)) {
- index = 2;
- }
- if (index !== -1) {
- let position = [index + Math.floor(Math.random() * 3 - 1), keyboard[index].indexOf(letter) + Math.floor(Math.random() * 3 - 1)];
- if (keyboard[position[0]] !== undefined && keyboard[position[0]][position[1]] !== undefined) {
- output[i] = output[i].slice(0, j) + keyboard[position[0]][position[1]] + output[i].slice(j + 1);
- }
- }
- }
- }
- if ((output[i + 1] === "" || i === 2) && output[i] !== "")
- output[i] += " LOL";
- if (output[i] !== "")
- sendMessage(name + ": " + output[i], channel);
- }
- }
- else if (text.toLowerCase().startsWith("voidify")) {
- let output = msgPointer("voidify").split(" ");
- for (let i in output) {
- console.log(output[i]);
- if ((output.length > 5 && Math.random() < 0.1) || " i he she him her our their my me your its ".includes(output[i].toLowerCase()))
- output.splice(i, 1);
- }
- output = output.join(" ");
- output = output.slice(0, 1).toUpperCase() + output.slice(1);
- if (Math.random() < 0.1)
- output = output.toUpperCase(); //angry void
- if (!".,?!:;".includes(output[output.length - 1]))
- output += ".";
- sendMessage(name + ": " + output, channel);
- }
- else if (text.toLowerCase().startsWith("xiaoify")) {
- let output = msgPointer("xiaoify");
- (async () => {
- output = await translate(output, {to: "zh", engine: "yandex", key: "trnsl.1.1.20200101T020837Z.b6e0dc21ae4464a4.3199765e39be8ec23b1f75aa08f6e3ea9f2137f5"});
- if (Math.random() < 0.9)
- output = await translate(output, {to: "en", from: "zh", engine: "yandex", key: "trnsl.1.1.20200101T020837Z.b6e0dc21ae4464a4.3199765e39be8ec23b1f75aa08f6e3ea9f2137f5"});
- sendMessage(name + ": " + output, channel, 1);
- })();
- }
- }
- });
- setInterval(() => {
- if (messageQueue[0]) {
- ws.send(JSON.stringify(["message", {text: messageQueue[0].text, channel: messageQueue[0].channel}]));
- messageQueue.splice(0, 1);
- }
- }, 500);
- ws.on("close", () => {
- console.log("Reconnecting");
- setTimeout(connect, 500);
- });
- }
- connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement