Bots Home
|
Create an App
RBOT4
Author:
codeanon_master
Description
Source Code
Launch Bot
Current Users
Created by:
Codeanon_Master
cb.settings_choices = function () { var sc = []; ins_index = 0; makeInstructions('[ROOM NOTICES] --------------- These notices will display when a user increases in rank. You can customize the exact text and color or disable the notice entirely.'); sc.push({name: 'rankup_notice_use', type: 'choice', label: 'Display notice when a user levels up', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes'}); sc.push({name: 'rankup_notice_text', type: 'str', label: 'Text to be displayed when a user levels up', defaultValue: '[user] has been promoted to Level [rank]!'}); sc.push({name: 'notice_fg', label: 'Text foreground color', type: 'str', defaultValue: '#E40000', required: false}); sc.push({name: 'notice_bg', label: 'Text background color', type: 'str', defaultValue: '#FFFF00', required: false}); makeInstructions('[RANK SETTINGS] --------------- Set up the thresholds at which viewers gain different ranks, and customize how they appear in the chat. If the chat display is enabled but a level left blank, a unicode enclosed alphanumeric will be used.'); sc.push({name: 'chat_rank_use', label: 'Display a user\'s rank at the beginning of their message', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes'}); makeLevel(1, 25, ''); makeLevel(2, 50, ''); makeLevel(3, 75, ''); makeLevel(4, 100, ''); makeLevel(5, 150, ''); function makeLevel(i, min) { var str = 'level_' + i + '_'; sc.push({name: str + 'use', label: '[LEVEL ' + i + '] --- Enabled', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes'}); sc.push({name: str + 'min', label: 'Tokens required', type: 'int', minValue: 1, defaultValue: min}); sc.push({name: str + 'lab', label: 'Custom chat label', type: 'str', required: false}); } function makeInstructions(text) { sc.push({name: 'instructions_' + ins_index, label: text, type: 'choice', choice1: '', required: false}); ins_index++; } return sc; }(); var notice_fg = $('notice_fg'); var notice_bg = $('notice_bg'); var rankup_notice = function () {if ($('rankup_notice_use') === 'Yes') return $('rankup_notice_text') || '[user] has been promoted to [level]!';}(); var tipLedger = function () { if ($('previous_tips')) return parseTips($('previous_tips')); return {}; }(); var ranks = function () { var arr = []; for (var i = 1; i < 6; i++) { var str = 'level_' + i + '_'; if ($(str + 'use') === 'Yes') { arr.push({ num: i, lab: $(str + 'lab') || String.fromCharCode(Number('931' + (i + 1))), min: $(str + 'min') }); } } return arr; }(); cb.onTip(function (tip) { var user = tip.from_user; tipLedger[user] = tipLedger[user] || 0; var oldRank = getRank(tipLedger[user]); tipLedger[user] += tip.amount; var newRank = getRank(tipLedger[user]); if ($('rankup_notice_use') === 'Yes' && newRank > oldRank) { var output = rankup_notice.replace(/\[user\]/g, user).replace(/\[rank\]/g, ranks[newRank].num); say(output, '', notice_fg, notice_bg); } }); cb.onMessage(function (msg) { if (msg.m.charAt(0) === '/' && isCommander(msg.user)) { msg['X-Spam'] = true; var cmd = msg.m.match(/^\/([^\s]+)(\s|$)/)[1]; cb.log(cmd); switch(cmd) { case 'save': saveTips(msg.user); break; }; } else { var user = msg.user; var rank = getRank(tipLedger[user]); if (rank > -1) msg.m = '=' + ranks[rank].lab + '= ' + msg.m; } return msg; }); function isCommander(user) { return user === cb.room_slug; } function getRank (num) { if (num) { for (var i = ranks.length - 1; i > -1; i--) if (num >= ranks[i].min) return i; } return -1; } function saveTips (cmdr) { var output = ''; for (var user in tipLedger) output += user + ':' + tipLedger[user] + ','; if (output.length > 0) { output = '=== Save the string below to paste into the bot\'s settings for the next show. ===\n' + output.slice(0, -1); say(output, cmdr, notice_fg, notice_bg, 'bold', ''); } else { say('=== There are currently no tips to save.', cmdr, notice_fg, notice_bg, 'bold', ''); } } /********** ------------ COMMUNICATION ------------ **********/ //send a message to the user function say(text, user, fg, bg) { cb.sendNotice(newLines(text), user, bg, fg, 'bold', ''); } /********** ------------ MISC ------------ **********/ function $ (str, uc) { var setting = cb.settings[str]; if (typeof setting === 'string') { if (uc) setting = setting.toUpperCase(); setting = setting.trim(); if (setting.length > 0) return setting; } else { if (setting) return setting; } } function newLines(input) { return '\u25A0 ' + input.replace(new RegExp('\n', 'g'), '\n\u25A0 '); }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.