Bots Home
|
Create an App
kilroy_TestBot
Author:
kilroy_was_here_again
Description
Source Code
Launch Bot
Current Users
Created by:
Kilroy_Was_Here_Again
/** * I WAS HERE. I CASHED A CHECK. I CHECKED OUT. This bot has been developed for the general community. This is a test!! */ /** Foreground color used by the bot for messages/notices */ var foreground = cb.settings.foreground; /** Background color used by the bot for messages/notices */ var background = cb.settings.background; /** Hashtags to keep between goals */ var hashtags = cb.settings.hashtags; /** Title to use when no goal is active */ var defaultTitle = cb.settings.defaultTitle; /** Emblem for notifications */ var noticeEmblem = " :notice16 "; /** Emblem for tokens */ var tokenEmblem = " :token16 "; /** User which has broadcaster permissions in the bot */ var trustedUser = cb.settings.trustedUser; cb.settings_choices = [ { name: "hashtags", label: "Room Hashtags", type: "str", required: false }, { name: "defaultTitle", label: "Default Title", type: "str", required: true }, { name: "trustedUser", label: "Trusted User", type: "str", required: false }, { name: "foreground", label: "Foreground Text Color", type: "str", defaultValue: "#000000" }, { name: "background", label: "Background Text Color", type: "str", defaultValue: "#FFFFFF" }, ]; cb.onDrawPanel(function (user) { cb.log("onDrawPanel()"); if (goals.current() == null) { return { 'template': '3_rows_11_21_31', 'row1_value': '-----', 'row2_value': 'No Goal', 'row3_value': '-----', }; } else { return { 'template': '3_rows_11_22_32', 'row1_label': 'Goal', 'row2_label': 'Required', 'row2_value': goals.current()[1], 'row3_label': 'Remaining', 'row3_value': goals.remaining, }; } }); cb.onMessage(function (message) { var commandCandidate = message.m.trim().split(" ").shift(); if (commandCandidate.charAt(0) == "/") { //Message is a command, hide it from chat, and check for a specific command message['X-Spam'] = true; switch (commandCandidate.toLowerCase()) { case "/help": commands.help(message); return; case "/goalhelp": commands.goalhelp(message); return; case "/addgoal": commands.addgoal(message); return; case "/setgoal": commands.setgoal(message); return; case "/settags": case "/sethashtags": commands.settags(message); return; case "/entrust": commands.entrust(message); return; } } }); cb.onTip(function (tip) { cb.log("onTip()"); goals.apply(tip.amount, tip.from_user); }); var commands; (function (commands) { /** * Handle /help * @param request Requesting message */ function help(request) { notice.post("For help with GoalApp, please use /goalhelp", request.user); } commands.help = help; /** * Handle /goalhelp * @param request Requesting message */ function goalhelp(request) { // Not everyone needs to see or can use all commands, so much of the logic here is about showing the right commends to the right people. if (request.user == cb.room_slug || request.user == trustedUser) { notice.add("/addgoal <amount> <title> - Add the goal to the queue"); notice.add("/nextgoal - Clear and remove the current goal, and move to the next goal"); notice.add("/setgoal <amount> <title> - Set the current goal"); } if (request.user == cb.room_slug || request.user == trustedUser) { notice.add("/settags <tags> - Set the hashtags field"); } if (request.user == cb.room_slug) { notice.add("/entrust <username> - Set the user as the trusted user"); } notice.send(request.user); notice.clear(); } commands.goalhelp = goalhelp; /** * Handle /addgoal * @param request Requesting message */ function addgoal(request) { if (request.user != cb.room_slug && request.user != trustedUser) { return; } var m = request.m.split(" "); var command = m.shift(); var amount = Number(m.shift()); var title = m.join(" "); goals.add(title, amount); } commands.addgoal = addgoal; /** * Handle /nextgoal * @param request Requesting message */ function nextgoal(request) { if (request.user != cb.room_slug && request.user != trustedUser) { return; } goals.next(); } commands.nextgoal = nextgoal; /** * Handle /setgoal * @param request Requesting message */ function setgoal(request) { if (request.user != cb.room_slug && request.user != trustedUser) { return; } var m = request.m.split(" "); var command = m.shift(); var amount = Number(m.shift()); var title = m.join(" "); goals.set(title, amount); } commands.setgoal = setgoal; /** * Handle /settags * @param request Requesting message */ function settags(request) { if (request.user != cb.room_slug && request.user != trustedUser) { return; } var m = request.m.split(" "); var command = m.shift(); var tags = m.join(" "); hashtags = tags; } commands.settags = settags; /** * Handle /entrust * @param request Requesting message */ function entrust(request) { if (request.user != cb.room_slug) { return; } var m = request.m.split(" "); var command = m.shift(); var username = m.shift(); trustedUser = username; } commands.entrust = entrust; })(commands || (commands = {})); var goals; (function (goals) { /** Queue of goals left to reach */ var queue = []; goals.remaining = 0; /** * Add the goal to the queue * @param title Title of the goal * @param amount Amount necessary to reach goal */ function add(title, amount) { cb.log("add()"); queue[queue.length] = [title, amount]; if (queue.length == 1) { cb.changeRoomSubject("Goal: " + title + " " + hashtags); goals.remaining = amount; cb.drawPanel(); } else { notice.post(noticeEmblem + amount + tokenEmblem + " for '" + title + "' has been queued"); } } goals.add = add; /** * Apply the amount towards the goal * @param amount Amount to put towards goal * @param from_user User who sent tip */ function apply(amount, tipper) { cb.log("apply()"); if (queue == null || queue == []) { cb.log("queue: " + queue); return; } if (goals.remaining < amount) { var a = amount; while (a > goals.remaining) { a -= goals.remaining; notice.post(noticeEmblem + " Goal '" + queue[0][0] + "' has been reached! Thanks " + tipper); next(); } goals.remaining -= a; } else { goals.remaining -= amount; } if (goals.remaining == 0) { next(); } cb.drawPanel(); } goals.apply = apply; /** * The current goal */ function current() { cb.log("current()"); return queue[0]; } goals.current = current; /** * Get the next goal from the queue */ function next() { cb.log("next()"); var goal = queue.shift(); if (queue.length >= 1) { cb.changeRoomSubject("Goal: " + queue[0][0] + " " + hashtags); goals.remaining = queue[0][1]; } else { cb.changeRoomSubject("Goal: " + defaultTitle + " " + hashtags); } cb.drawPanel(); } goals.next = next; /** * Set the current goal without changing queued goals * @param title Title of the goal * @param amount Amount necessary to reach goal */ function set(title, amount) { cb.log("set()"); queue[0] = [title, amount]; goals.remaining = amount; cb.changeRoomSubject("Goal: " + title + " " + hashtags); cb.drawPanel(); } goals.set = set; })(goals || (goals = {})); /** Manages and queues notices. */ var notice; (function (notice_1) { /** The queue of notices. */ var queue = []; /** * Add the string to the queue of notices. * @param notice Notice to add. */ function add(notice) { queue[queue.length] = notice; } notice_1.add = add; /** * Clear the queue. */ function clear() { queue = []; } notice_1.clear = clear; /** * Send the notices to chat. * @param sendTo User to send notices to * @param foregndColor Foreground color to use * @param backgndColor Background color to use */ function send(sendTo, foregndColor, backgndColor) { if (foregndColor === void 0) { foregndColor = foreground; } if (backgndColor === void 0) { backgndColor = background; } var message = queue.join("\n"); if (sendTo == null) { sendTo = ""; } cb.sendNotice(message, sendTo, backgndColor, foregndColor, "bold"); } notice_1.send = send; /** * Send a single notice to chat. * This bypasses the notice builder, and is just a wrapper for cb.sendNotice. * @param notice Notice to send. * @param sendTo User to send notices to. */ function post(notice, sendTo) { if (sendTo == null) { sendTo = ""; } cb.sendNotice(notice, sendTo, background, foreground, "bold"); } notice_1.post = post; /** * Send the notices to a group. * @param group Group to send notices to. * @param foregndColor Foreground color to use * @param backgndColor Background color to use */ function sendGroup(group, foregndColor, backgndColor) { if (foregndColor === void 0) { foregndColor = foreground; } if (backgndColor === void 0) { backgndColor = background; } var message = queue.join("\n"); cb.sendNotice(message, "", backgndColor, foregndColor, "bold", group); } notice_1.sendGroup = sendGroup; })(notice || (notice = {})); /** * Initialization code */ { cb.changeRoomSubject(defaultTitle + " " + hashtags); cb.drawPanel(); }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.