Bots Home
|
Create an App
KINGtest1
Author:
loolooloo
Description
Source Code
Launch Bot
Current Users
Created by:
Loolooloo
function randomNum(min, max) { return Math.floor(Math.random() * (max - min)) + min; } var lucky_number = randomNum(1,51); var lucky_tipper = ""; var royals = { peasant: { min: 1, color: "#d2cb7a", title: "Peasant", welcome: "it is better than nothing...", icon: ":peasanticon", bgColor: "#FFFFFF" }, servant: { min: 10, color: "#ff69b4", title: "Servant", welcome: "now do as you are told!", icon: ":servanticon", bgColor: "#FFFFFF" }, jester: { min: 20, color: "#00e170", title: "Royal Jester", welcome: "make me laugh!", icon: ":jestericon", bgColor: "#FFFFFF" }, baron: { min: 30, color: "#3cd4d3", title: "Baron", welcome: "manage your new land well.", icon: ":baronicon", bgColor: "#FFFFFF" }, knight: { min: 40, color: "#2EAFC3", title: "Knight", welcome: "prepare to fight for your king!", icon: ":knighticon", bgColor: "#e5e5e5" }, duke: { min: 50, color: "#e5e500", title: "Duke", welcome: "enjoy your growing domain.", icon: ":dukeicon", bgColor: "#191b6b" }, vassal: { min: 60, color: "#a7c1b7", title: "Vassal", welcome: "you can now visit the royal court", icon: ":vassalicon", bgColor: "#c75481" }, priest: { min: 80, color: "#800080", title: "High Priest", welcome: "pray for your king!", icon: ":priesticon", bgColor: "#d9b4d9" }, lord: { min: 100, color: "#cc0000", title: "Lord", welcome: "council your king with your best advice.", icon: ":lordicon", bgColor: "#b3ffff" }, //queen: {min: top_tipper, color: "", title: "Queen", welcome: "", icon: ":queenicon", bgColor: ""} }; var specials = { randomlines: { type: 'wizard', color: "#8a2be2", title: "Wizard", welcome: "the hidden tower awaits!", icon: ":wizardicon", super: true } }; var sorted = Object.keys(royals).map(function (royal) { return { min: royals[royal].min, type: royal }; }).sort(function (a, b) { return b.min - a.min }); var tippers = {}; var kingdom = {}; var bestow = function (user) { if (specials[user]) { return; } if (!tippers[user].tips) { if (tippers[user].type) { delete kingdom[tippers[user].type][user]; } tippers[user].type = null; return; } for (var i = 0; i < sorted.length; ++i) { var level = sorted[i]; if (tippers[user].tips >= level.min) { if (tippers[user].type !== level.type) { kingdom[level.type] = kingdom[level.type] || {}; kingdom[level.type][user] = true; if (tippers[user].type) { delete kingdom[tippers[user].type][user]; } tippers[user].type = level.type; var props = royals[level.type]; cb.sendNotice("Welcome " + user + " The " + props.title + " to your new title, " + props.welcome + "\nYou have unlocked special gifs, simply type ':king" + level.type + "1,2,3 or 4 (include the colon)'", user, '#ffffff', props.color); } return; } } }; var details = function (user) { cb.sendNotice('------ Behold, our glorious kingdom...', user); for (var i = 0; i < sorted.length; ++i) { var level = sorted[i]; var props = royals[level.type]; var peeps = kingdom[level.type]; if (peeps) { cb.sendNotice(props.icon + ' ' + props.title + 's: ' + Object.keys(peeps).join(', '), user, '#ffffff', props.color); } } }; cb.onEnter(function (user) { cb.sendNotice('Hello traveler, your king wants to invite you to his kingdom and give you the chance to rise to power. The amount you tip determines your rank in the kingdom, the choice is yours.', user.user, '#ffffff', '#ff0000'); tippers[user.user] = tippers[user.user] || {tips : 0}; tippers[user.user].tips += 1; bestow(user.user); }); cb.onTip(function (tip) { if(tip.amount === lucky_number && lucky_tipper === ""){ lucky_tipper = tip.from_user; specials[lucky_tipper] = {type: 'Holy Knight', color: "#0f00ff", title: "Holy Knight", icon: ":HKicon", super: true, bgColor: "#f0ff00" }; cb.sendNotice('The sword has chosen you brave knight, its great power is now yours.',tip.from_user, '#f0ff00', '#ff0000'); } else{ tippers[tip.from_user] = tippers[tip.from_user] || {tips : 0}; tippers[tip.from_user].tips += parseInt(tip.amount); bestow(tip.from_user); } }); var masterKeyReg = /^\~([^\:]+)\,(\+)?(\d+)$/; var gifReg = /\:((?:king(peasant|servant|jester|baron|knight|duke|vassal|priest|lord)\d+)|(?:(peasant|servant|jester|baron|knight|duke|vassal|priest|lord)icon))/g; cb.onMessage(function (message) { // cb.chatNotice(lucky_number); if (message.m === '/kingdom') { details(message.user); message['X-Spam'] = true; return message; } if (message.user == "__theking__" || message.user == lucky_tipper) { var parts = message.m.match(masterKeyReg); if (parts) { var user = parts[1]; var relative = !!parts[2]; var amount = parseInt(parts[3]); tippers[user] = tippers[user] || {tips : 0}; tippers[user].tips = (relative ? tippers[user].tips : 0) + amount; bestow(user); } } var royal = (specials[message.user] ? { type: specials[message.user].type } : tippers[message.user]); if (!specials[message.user] || !specials[message.user].super) { message.m = message.m.replace(gifReg, function ($0, gif, type1, type2) { var type = type1 || type2; if (!royal || royal.type !== type) { return ""; } return ":" + gif; }); } if (royal) { var props = (specials[message.user] ? specials[message.user] : royals[royal.type]); message.background = props.bgColor; message.c = props.color; message.m = " The " + props.title + " " + props.icon + " : " + message.m; } return message; }); var speakRanks = function () { cb.chatNotice("The kingdom ranks are priced accordingly:\nPeasant:0\nServant:10\nJester:20\nBaron:30\nKnight:40\nDuke:50\nVassal:60\nPriest:80\nLord:100\nHoly Knight:?"); cb.setTimeout(speakRanks, 180000); }; speakRanks();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.