Bots Home
|
Create an App
Di's
Author:
shy
Description
Source Code
Launch Bot
Current Users
Created by:
Shy
// Author: A Shy Guy var users = {}; var levels = []; var loaded = []; var tm = "//"; var maxLevels = 20; function addToUserList(listName, s, msg) { s = s.trim() if (!s || s == "") return var u = addUser(s) // make sure the user exists if (!userLists[listName]) userLists[listName] = []; if (userLists[listName].indexOf(s) >= 0) { //debug(s + " is already in list '" + listName + "'") return } //debug("adding '" + s + "' to list '" + listName + "'") userLists[listName].push(s); u[listName] = true; if (msg && msg != "") { whisper(s, msg) } } function addNamesToUserList(listName, namesList, msg) { if (!namesList || namesList == "") { //debug("names null while adding to list: " + listName) return } if (!userLists[listName]) userLists[listName] = []; var names = namesList.split(",") for (var i = 0; i < names.length; i++) { addToUserList(listName, names[i], msg) } } function removeFromUserList(listName, s, msg) { var u = addUser(s) // make sure the user exists u[listName] = false; if (!userLists[listName]) return; var idx = userLists[listName].indexOf(s); if (idx < 0) return; userLists[listName].splice(idx, 1); } function startsWith(s, str) { if (s.length < str.length) return false; return s.substring(0, str.length) == str } function getUserList(listName) { if (!userLists[listName]) userLists[listName] = []; return userLists[listName]; } function isInUserList(listName, name) { return (getUserList(listName).indexOf(name) >= 0) } function addTrusteds(names, msg) { addNamesToUserList("trusted", names, msg) } function addTrusted(name) { addToUserList("trusted", name) } function removeTrusted(name) { removeFromUserList("trusted", name) } function getTrusteds(name) { return getUserList("trusted") } function isTrusted(name) { return (getUserList("trusted").indexOf(name) >= 0) } function addTippers(names, msg) { addNamesToUserList("tipper", names, msg) } function addTipper(name) { addToUserList("tipper", name) } function removeTipper(name) { removeFromUserList("tipper", name) } function getTippers(name) { return getUserList("tipper") } function isTipper(name) { return (getUserList("tipper").indexOf(name) >= 0) } function addDebugs(names, msg) { addNamesToUserList("debug", names, msg) } function addDebug(name) { addToUserList("debug", name) } function removeDebug(name) { removeFromUserList("debug", name) } function getDebugs(name) { return getUserList("debug") } function isDebug(name) { return (getUserList("debug").indexOf(name) >= 0) } function makeUserList(roles) { var list = []; if (roles && roles != "") { var parts = roles.split(','); for (var i = 0; i < parts.length; i++) { var rlist = getUserList(parts[i].trim()) for (var i in rlist) { if (list.indexOf(i) < 0) { list.push(rlist[i]) } } } } return list; } function mustNotifyRoom() { return cb.settings['notify_room'] == "Yes"; } function mustNotifyUser() { return cb.settings['notify_user'] == "Yes"; } function mustNotifyBroadcaster() { return cb.settings['notify_bc'] == "Yes"; } function setSubject(newSubject) { cb.changeRoomSubject(newSubject); } function getBroadcaster() { return cb.room_slug; } function getUser(userName) { return users[userName]; } function dumpUser(userName) { return false; var user = getUser(userName); if (!user) return; outputPrivate("User " + userName + ": " + JSON.stringify(user), cb.room_slug, "", "", "bold"); } function getSettings(key) { return sga.settings[key]; } function setSetting(key, value) { sga.settings[key] = value; } function copySettings() { for (var key in cb.settings) { sga.settings[key] = cb.settings[key]; } } function dumpSettings() { var list = [] for (var key in sga.settings) { debug(key + "=" + sga.settings[key]); } return list } function addUser(userName) { var user = getUser(userName); if (user) return user; var newUser = { user: userName, total_tipped: 0, count_tips: 0, count_chats: 0, tip_level: 0, is_present: false, fore_color: sga.defaultForeColor, bg_color: sga.defaultBGColor, is_direct_sender: false, nickname: "", hidden_cam_viewer: false, is_nice: false, is_dick: false, is_dom: false, is_mod: false, current_role: "user", current_mode: "c" }; users[userName] = newUser; return getUser(userName); } function setUser(user) { var userName = user.user; var u = addUser(userName); if (!u) return; u.user = user.user; u.in_fanclub = user.in_fanclub u.has_tokens = user.has_tokens u.is_mod = user.is_mod u.gender = user.gender if (user.has_tokens) u.tip_level = 1 if (user.tipped_recently) u.tip_level = 2 if (user.tipped_alot_recently) u.tip_level = 3 if (user.tipped_tons_recently) u.tip_level = 4 return u } function isMod(userName) { var u = addUser(userName); return u.is_mod; } function suppress(e) { e["X-Spam"] = true; } function cleanString(s) { if (!s) return ""; while (s.lastIndexOf("[nl]") >= 0) { s = s.replace("[nl]", sga.newLineText); } while (s.lastIndexOf("[dots]") >= 0) { s = s.replace("[dots]", sga.leaderText); } return s; } function cleanStringForUser(s, userName) { s = cleanString(s); while (s.lastIndexOf("[user]") >= 0) { s = s.replace("[user]", userName); } return s; } function debug(msg) { var user = sga.debugUser; if (!user || user == "") return; send(msg, user, "", "#969696", ""); } function setDebugUser(userName) { sga.debugUser = userName; debug("Debug user is now: " + sga.debugUser); } function help() { var e = [sga.appCommands]; send(e.join("\n"), cb.room_slug, "", "", "normal"); } function getMessageString(msg) { return cleanString(msg); return msg; } function welcomeUser(userName) { var msg = "" //if (isDick(userName)) { // send(sga.dickWelcome, userName, "#F7F70A", "#ff0000", ""); // return; //} if (sga.settings.welcome_feature != "Yes") { return; } msg = getMessageString(sga.settings.welcome_msga); msg = msg.replace("[user]", userName); msg = msg.replace("[nl]", sga.newLineText); if (useTipMenu()) { msg = msg + "\n... Tip menu is active. Type /tipmenu to see menu\n"; } msg = msg.replace("~", "\n"); if (msg != "") { send(msg, userName, "", sga.settings.welcome_color, "bold"); } } function outputPrivate(e, userName) { if (userName == null) userName = cb.room_slug; send(e, userName) } function send(msg, userName, bgColor, color, fontWeight) { msg = cleanStringForUser(msg, userName); while (msg.indexOf("|") >= 0) { msg = msg.replace("|", ""); } cb.sendNotice(msg, userName, bgColor, color, fontWeight); } cb.onMessage(function (e) { var msg = e["m"]; if (isDevMode()) { debug(msg) } return processMessage(e) }); function loadSettings() { var settings = cb.settings["app_settings"]; if (settings && startsWith(settings, "Notice: ")) { settings = settings.substring(8, settings.length) } if (settings && settings != "") { try { var parsed = JSON.parse(settings) loaded = parsed; send(sga.appName + " settings loaded", getBroadcaster(), "#00FF00"); } catch (e) { send(sga.appName + " FAILED TO READ SETTINGS", getBroadcaster(), "#FF0000"); } } } function createLevels() { for (i = 1; i <= 10; i++) { levelSettings = cb.settings["level_" + i]; if (levelSettings && levelSettings != "") { debug("Settings: " + levelSettings); var parts = levelSettings.split(",") if (parts.length > 2) { levelName = parts[0]; levelPrice = parseInt(parts[1]); levelIcon = parts[2]; color = (parts.length > 3) ? parts[3] : ""; var level = { name: levelName, price: levelPrice, image: levelIcon, color: color, levelNum: i, users: [] }; if (loaded && loaded.length > 0) { for (l = 0; l < loaded.length; l++) { if (loaded[l].name == levelName) { level.users = loaded[l].users; } } } levels.push(level); } } } } function getLevelUserNames(level) { var userNames = level.users; var s = "" for (var i = 0; i < userNames.length; i++) { if (i > 0) s += ","; s += userNames[i] } return s; } function showLevels(userName) { debug("showLevels: " + userName) var msg = ""; for (i = 0; i < maxLevels; i++) { level = levels[i]; if (level && level.name != "") { msg = msg + level.name + " - " + level.price + " tokens :" + level.image + "\n"; msg = msg + getLevelUserNames(level) + "\n"; } } send(msg, userName); } function getLevelForPrice(price) { for (i = 0; i < maxLevels; i++) { level = levels[i]; if (level && level.price == price) return level; } return null; } function getLevelForUser(userName) { for (i = 0; i < maxLevels; i++) { level = levels[i]; if (level && level.users.indexOf(userName) >= 0) { return level; } } return null; } function showSettings() { var s = JSON.stringify(levels); send(s, getBroadcaster()); } function processMessage(e) { var msg = e["m"]; var t = e["m"]; var n = e["user"]; var r = ""; var u = addUser(n); var is_trusted = isTrusted(n); var isBroadcaster = (n == getBroadcaster()); var is_mod = isMod(n); var suppress_direct = false; t = t.replace(/\s+$/, ""); if (t == "/levels") { showLevels(n); suppress(e); return; } var level = getLevelForUser(n); var prefix = ""; var color = ""; if (level && level.price > 0) { prefix = "|" + level.name + "| " + level.image + " "; color = level.color; } if (t == "/me") { var userLevel = getLevelForUser(n); if (userLevel) { send(prefix + "Your level: " + level.name, n); } else { send("You have no level", n); } suppress(e); return; } if (startsWith(t, "/fake ")) { var amt = parseInt(t.substring(6, t.length)) if (amt != NaN) { processTip(n, amt, "fake tip"); } suppress(e); return e; } if (isBroadcaster || isTrusted(n)) { if (t == "/settings") { showSettings(); suppress(e); return; } } if (t[0] == "/") { suppress(e); } e["m"] = prefix + e["m"]; if (color != "") e["c"] = color; //dumpUserDebug(n) return e } function promotUser(newLevel, oldLevel, userName) { if (oldLevel == newLevel) return; newLevel.users.push(userName); if (oldLevel) oldLevel.users.pop(userName); var msg = newLevel.image + " " + userName + " is now " + newLevel.name; if (mustNotifyRoom()) { send(msg, ""); } else { if (mustNotifyUser()) { send(newLevel.image + " You are now " + newLevel.name, userName); } if (mustNotifyBroadcaster()) { send(msg, getBroadcaster()); } } } function processTip(userName, amount, message) { debug("Tip " + userName + ", " + amount + ": " + message) //var u = addUser(userName); //debug("Searching for user: " + userName); var userLevel = getLevelForUser(userName); var priceLevel = getLevelForPrice(amount); /* if (userLevel) { debug("Level: " + userLevel.levelNum); } else { debug("No Level"); } if (priceLevel) { debug("PriceLevel: " + priceLevel.levelNum); } else { debug("No price Level"); } */ if (priceLevel && (!userLevel || priceLevel.price > userLevel.price)) { promotUser(priceLevel, userLevel, userName); } } cb.onTip(function (tip) { var amount = parseInt(tip['amount']) var userName = tip['from_user'] var msg = tip['message']; processTip(userName, amount, msg); }); function start() { tm = "/"; users = {}; copySettings(); tm += "/"; var broadcaster = getBroadcaster(); tm += "i"; addUser(broadcaster) tm += "a"; addTrusteds(sga.defaultTrusteds); tm += "m"; outputPrivate("Type /help for commands", cb.room_slug, "", "", "normal"); outputPrivate(sga.appIntro); //cb.onEnter(handleEnter); //cb.onLeave(handleLeave); tm += "s"; tm += "hy"; //welcomeUser(broadcaster) loadSettings(); createLevels(); } var sga = { appName: "Diana's Universe", appDeveloper: "Shy Guy", appIntro: "Diana's Universe (v1.0)", appCommands: "", appCommandsForMods: "", debugUser: "shy", running: false, defaultTrusteds: "", settings: {} }; var colorGray = "#969696"; var colorLightGray = "#C7C9C9"; var colorDarkGray = "#5B5C5C"; var maxLevels = 20; var userLists = {}; debugMode = false; start(); cb.settings_choices = [ { name: 'notify_room', label: 'Announce level changes to room?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No' }, { name: 'notify_user', label: 'Announce level changes to user?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: 'notify_bc', label: 'Announce level changes to broadcaster?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: "app_settings", label: "Settings", type: "str", required: false, minLength: 1, maxLength: 32000, defaultValue: "" }, { name: "level_1", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "jaba,100,:du-jaba" }, { name: "level_2", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "anakin,200,:du-anakin" }, { name: "level_3", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "han,300,:du-han" }, { name: "level_4", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "jedi,400,:du-jedi" }, { name: "level_5", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "yoda,500,:du-yoda,#000000" }, { name: "level_6", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "" }, { name: "level_7", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "" }, { name: "level_8", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "" }, { name: "level_9", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "" }, { name: "level_10", label: "[level name],[price],[image]:", type: "str", required: false, minLength: 1, maxLength: 1024, defaultValue: "" } ]; function isDevMode() { return false; }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.