Bots Home
|
Create an App
randomstuff
Author:
en3rgy1204
Description
Source Code
Launch Bot
Current Users
Created by:
En3rgy1204
var morseAlphabet = { 'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.', 'q': '--.-', 'r': '.-.', 's': '...', 't': '-', 'u': '..-', 'v': '...-', 'w': '.--', 'x': '-..-', 'y': '-.--', 'z': '--..', ' ': '/', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', '6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----', }; const reverseMapping = o => Object.keys(o).reduce((r, k) => Object.assign(r, { [o[k]]: (r[o[k]] || []).concat(k) }), {}); const inverseMorse = reverseMapping(morseAlphabet); // console.log(inverseMorse); cb.onMessage(function (msg) { if (msg["m"].startsWith("/morseto")) { msg["X-Spam"] = true; var splitString = msg["m"].split(" "); const [command, username, ...msgTokens] = splitString; var toEncode = msgTokens.join(" "); if (username.charAt(0) === "@") { var newUsername = username.substring(1); // remove leading @ from username var encodedMsg = toEncode // encode msg .split("") .map(function (e) { return morseAlphabet[e.toLowerCase()] || ""; }) .join(" ") .replace(/ +/g, ' '); cb.sendNotice("message from " + msg["user"] + ": " + encodedMsg, newUsername); // send to user } else { cb.sendNotice("please put @ in front of username!", msg["user"]); // send error notice if @ is missing } } if (msg["m"].startsWith("/morse") && !(msg["m"].startsWith("/morseto"))) { msg["X-Spam"] = true; var toEncode = msg["m"].substring(msg["m"].indexOf(" ")+1); var encoded = toEncode .split("") .map(function (e) { return morseAlphabet[e.toLowerCase()] || ""; }) .join(" ") .replace(/ +/g, ' '); cb.sendNotice("message from " + msg["user"] + ": " + encoded); } if (msg["m"].startsWith("/demorse")) { msg["X-Spam"] = true; var toDecode = msg["m"].substring(msg["m"].indexOf(" ")+1); cb.sendNotice("message: " + decodeMorse(toDecode)); } }); const decodeLetter = letter => { return inverseMorse[letter]; } const decodeWord = word => { return word.split(' ').map(decodeLetter).join(''); } const decodeMorse = morseCode => { return morseCode.trim().split("/").map(decodeWord).join(' '); }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.