Apps Home
|
Create an App
test5651464
Author:
twistinreality
Description
Source Code
Launch App
Current Users
Created by:
Twistinreality
var settings = [ { name: "tokens", type: "int", label: "Cost for each PM (\"to-user\" PMs are free)", defaultValue: 4 }, { name: "cooldown", type: "int", label: "Advertise PM cost in chat (minutes)", choice1: 1, choice2: 2, choice3: 3, choice4: 4, choice5: 5, choice6: 10, choice7: 15, choice8: 20, choice9: 25, choice10: 30, choice11: 45, choice12: 60, defaultValue: 5 } ]; cb.onEnter(function(user) { advertise(user['message']); }); cb.onMessage(function(msg) { if (parseInt(msg['m']) == cb.settings['tokens']) { var userTokens = Math.floor(parseInt(msg['m']) / cb.settings['tokens']); updateSpecialUsers(msg['user'], userTokens, true); if (!isFreeMessages()) { cb.sendNotice("Advertised " + getUserMessageQty(msg['user']) + " PM(s) to chat (minutes)", msg['user'], "", "", ""); } } }); cb.onTip(function(tip) { if (tip['amount'][0] == '#') { tip['amount'][0] = true; var messageArr = tip['amount'].split(" "); var toUser = messageArr[0].slice(1); messageArr.shift(); var messageText = messageArr.join(" "); sendMessage(tip['from_user'], toUser, messageText); }; return tip; }); var specialUsers = []; function isFreeMessages() { return cb.settings['tokens'] === 0; } function sendMessage(fromUser, toUser, message) { if (fromUser === toUser) { cb.sendNotice("Cannot send PM to yourself", fromUser, "", "", ""); } else { if (userCanSendMessage(fromUser)) { cb.sendNotice("PM from " + fromUser + ": " + message, toUser, "", "", ""); cb.sendNotice("PM sent to " + toUser, fromUser); cb.sendNotice("Message to " + toUser + " sent", toUser); if (!isFreeMessages() && toUser !== cb.room_slug) { updateSpecialUsers(toUser, 1); cb.sendNotice("Advertised " + getUserMessageQty(toUser) + " PM(s) to chat", toUser, "", "", ""); } } else { cb.sendNotice("Sorry, you must tip #token(s) to send one PM.", fromUser, "", "", ""); } } } function getSpecialIndex(user) { if (specialUsers.length) { for (var i = 0; i < specialUsers.length; i++) { if (specialUsers[i][0].indexOf(user) >= 0) { return i; } } } return null; } function updateSpecialUsers(user, tokens, add) { var userIndex = getSpecialIndex(user); if (userIndex !== null) { if (add) { specialUsers[userIndex][1] += tokens; } else { if (specialUsers[userIndex][1] > 0) { specialUsers[userIndex][1] -= tokens; if (specialUsers[userIndex][1] < 0) { specialUsers[userIndex][1] = 0; } } } } else { specialUsers.push([user, tokens]); } } function userCanSendMessage(user) { if (user === cb.room_slug || user === "bold") { return true; } if (!isFreeMessages()) { var userIndex = getSpecialIndex(user); if (userIndex !== null) { var tokens = specialUsers[userIndex][1]; if (tokens > 0) { return true; } } return false; } return true; } function getUserMessageQty(user) { var userIndex = getSpecialIndex(user); if (userIndex !== null) { return specialUsers[userIndex][1]; } return 0; } function advertise(user) { if (user === undefined) { user = ""; } var message = "Please, send token(s) to your message."; message += "\n"; message += "Tokens are required to send private messages."; if (isFreeMessages()) { message += "Your token balance: " + cb.settings['tokens'] + " tokens"; } else { message += "Your token balance: " + cb.settings['tokens'] + " tokens"; } cb.sendNotice(message, user, "", "", ""); if (!user) { cb.setTimeout(advertise, cb.settings['cooldown'] * 60000); } } function init() { advertise(); } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.