Apps Home
|
Create an App
Johns Room
Author:
johndowfoobar
Description
Source Code
Launch App
Current Users
Created by:
Johndowfoobar
var Permission; (function (Permission) { Permission[Permission["Broadcaster"] = 1] = "Broadcaster"; Permission[Permission["Modarator"] = 2] = "Modarator"; Permission[Permission["FanClub"] = 3] = "FanClub"; Permission[Permission["TippedTonsRecently"] = 4] = "TippedTonsRecently"; Permission[Permission["TippedAlotRecently"] = 5] = "TippedAlotRecently"; Permission[Permission["TippedRecently"] = 6] = "TippedRecently"; Permission[Permission["HasTokens"] = 7] = "HasTokens"; })(Permission || (Permission = {})); var Goal = (function () { function Goal(name, cost) { this.name = name; this.cost = cost; } return Goal; }()); var CommandGroup = (function () { function CommandGroup(command, actions) { if (actions === void 0) { actions = []; } this.command = command; this.actions = actions; } return CommandGroup; }()); var CommandAction = (function () { function CommandAction(action, permission, callback) { this.action = action; this.permission = permission; this.callback = callback; } return CommandAction; }()); var Color; (function (Color) { Color["white"] = "#ffffff"; Color["black"] = "#000000"; Color["darkBlue"] = "#173F5f"; Color["blue"] = "#20639b"; Color["green"] = "#2caea3"; Color["yellow"] = "#f6d55c"; Color["red"] = "#ed553b"; })(Color || (Color = {})); var CommandParser = (function () { function CommandParser() { this.commandGroups = {}; this.notice = Notice.getInstance(); } CommandParser.getInstance = function () { if (this.instance === null) { this.instance = new CommandParser(); } return this.instance; }; CommandParser.prototype.createGroup = function (groupName, command) { var _this = this; this.commandGroups[groupName] = new CommandGroup(command); this.registerAction(groupName, Permission.Broadcaster, 'help', function (message) { _this.notice.sendUserNotice(message.user, groupName + " help"); _this.commandGroups[groupName].actions.forEach(function (action) { _this.notice.sendUserNotice(message.user, "" + action.action); }); }); }; CommandParser.prototype.registerAction = function (groupName, permission, action, callback) { if (!this.commandGroups.hasOwnProperty(groupName)) return; this.commandGroups[groupName].actions.push(new CommandAction(action, permission, callback)); }; CommandParser.prototype.parseCommand = function (message) { if (message.m.startsWith('/')) { message['X-Spam'] = true; } if (message.m === '/help') { if (!Permissions.resolve(message, Permission.Broadcaster)) return; this.notice.sendUserNotice(message.user, 'App help'); for (var key in this.commandGroups) { this.notice.sendUserNotice(message.user, key + ": " + this.commandGroups[key].command); } } var messageParts = message.m.split(' '); if (messageParts.length === 0) return; var command = messageParts.shift(); for (var key in this.commandGroups) { var group = this.commandGroups[key]; if (group.command === command) { var executed = CommandParser.parseAction(group, message, messageParts); if (executed) break; } } }; CommandParser.parseAction = function (group, message, messageParts) { if (messageParts.length === 0) return false; var action = messageParts.shift(); for (var _i = 0, _a = group.actions; _i < _a.length; _i++) { var commandAction = _a[_i]; if (commandAction.action === action) { if (!Permissions.resolve(message, commandAction.permission)) return true; commandAction.callback.apply(commandAction, [message].concat(messageParts)); return true; } } return false; }; CommandParser.instance = null; return CommandParser; }()); var TipGoal = (function () { function TipGoal() { this.goals = []; this.activeGoalIndex = 0; this.tipped = 0; this.started = false; this.notice = Notice.getInstance(); this.commandParser = CommandParser.getInstance(); this.configureCommandParser(); } TipGoal.getInstance = function () { if (this.instance === null) { this.instance = new TipGoal(); } return this.instance; }; Object.defineProperty(TipGoal.prototype, "activeGoal", { get: function () { return this.goals[this.activeGoalIndex]; }, enumerable: true, configurable: true }); TipGoal.prototype.createGoal = function (name, cost) { this.goals.push(new Goal(name, cost)); }; TipGoal.prototype.start = function () { if (this.goals.length === 0) return; this.started = true; this.sendNotice('Started!'); this.sendNotice("New goal set: " + this.activeGoal.name + "!"); }; TipGoal.prototype.stop = function () { if (!this.started) return; this.started = false; this.activeGoalIndex = 0; this.tipped = 0; this.sendNotice('Stopped!'); }; TipGoal.prototype.reset = function () { this.stop(); this.start(); this.sendNotice('Goals were reset and start from the beginning.'); }; TipGoal.prototype.status = function () { this.notice.sendUserNotice(cb.room_slug, "Started: " + (this.started ? 'True' : 'False') + ", Goal: " + this.activeGoal.name + ", Cost: " + this.activeGoal.cost + ", Tipped: " + this.tipped); var activeGoals = this.goals.map(function (goal) { return goal.name; }).join(', '); this.notice.sendUserNotice(cb.room_slug, "Active goals: " + activeGoals); }; TipGoal.prototype.addTip = function (tip) { if (!this.started) return; this.tipped += tip.amount; var goal = this.activeGoal; var cost = goal.cost; if (this.tipped < cost) return; this.sendNotice("Goal reached: " + goal.name + "! Thanks everyone for tipping."); if (this.activeGoalIndex === this.goals.length - 1) { this.stop(); return; } this.tipped -= cost; this.activeGoalIndex++; this.sendNotice("New goal set: " + this.activeGoal.name + "!"); }; TipGoal.prototype.sendNotice = function (message) { this.notice.sendRoomNotice("TipGoal: " + message); }; TipGoal.prototype.configureCommandParser = function () { var _this = this; var commandGroup = 'TipGoal'; this.commandParser.createGroup(commandGroup, '/goal'); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'create', function (_) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } if (args.length !== 2) return; _this.createGoal(args[0], Number(args[1])); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'start', function () { _this.start(); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'stop', function () { _this.stop(); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'reset', function () { _this.reset(); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'status', function () { _this.status(); }); }; TipGoal.instance = null; return TipGoal; }()); var Notice = (function () { function Notice() { } Notice.getInstance = function () { if (this.instance === null) { this.instance = new Notice(); } return this.instance; }; Notice.prototype.sendRoomNotice = function (message, background, foreground, fontWeight) { if (background === void 0) { background = Color.white; } if (foreground === void 0) { foreground = Color.black; } if (fontWeight === void 0) { fontWeight = 'normal'; } cb.sendNotice(message, '', background, foreground, fontWeight); }; Notice.prototype.sendUserNotice = function (username, message, background, foreground, fontWeight) { if (background === void 0) { background = Color.white; } if (foreground === void 0) { foreground = Color.black; } if (fontWeight === void 0) { fontWeight = 'normal'; } cb.sendNotice(message, username, background, foreground, fontWeight); }; Notice.prototype.sendGroupNotice = function (group, message, background, foreground, fontWeight) { if (background === void 0) { background = Color.white; } if (foreground === void 0) { foreground = Color.black; } if (fontWeight === void 0) { fontWeight = 'normal'; } cb.sendNotice(message, '', background, foreground, fontWeight, group); }; Notice.instance = null; return Notice; }()); var Permissions; (function (Permissions) { function resolve(user, permission) { switch (permission) { case Permission.Broadcaster: return user.user === cb.room_slug; case Permission.Modarator: return user.user === cb.room_slug || user.is_mod; case Permission.FanClub: return user.user === cb.room_slug || user.is_mod || user.in_fanclub; case Permission.TippedTonsRecently: return user.user === cb.room_slug || user.is_mod || user.in_fanclub || user.tipped_tons_recently; case Permission.TippedAlotRecently: return user.user === cb.room_slug || user.is_mod || user.in_fanclub || user.tipped_tons_recently || user.tipped_alot_recently; case Permission.TippedRecently: return user.user === cb.room_slug || user.is_mod || user.in_fanclub || user.tipped_tons_recently || user.tipped_alot_recently || user.tipped_recently; case Permission.HasTokens: return user.user === cb.room_slug || user.is_mod || user.in_fanclub || user.tipped_tons_recently || user.tipped_alot_recently || user.tipped_recently || user.has_tokens; } } Permissions.resolve = resolve; })(Permissions || (Permissions = {})); var RoomSubject = (function () { function RoomSubject() { this.defaultSubject = ''; this.subject = ''; this.defaultHashtags = []; this.hashtags = []; this.notice = Notice.getInstance(); this.commandParser = CommandParser.getInstance(); this.configureCommandParser(); } RoomSubject.getInstance = function () { if (this.instance === null) { this.instance = new RoomSubject(); } return this.instance; }; RoomSubject.prototype.initialize = function (subject, hashtags) { if (this.defaultSubject === '') { this.defaultSubject = subject; this.subject = this.defaultSubject; } if (this.hashtags.length === 0) { this.defaultHashtags = hashtags; this.hashtags = Object.assign([], this.defaultHashtags); } }; RoomSubject.prototype.addHashtags = function () { var _this = this; var hashtags = []; for (var _i = 0; _i < arguments.length; _i++) { hashtags[_i] = arguments[_i]; } hashtags.forEach(function (hashtag) { if (!hashtag.includes('#')) { _this.hashtags.push("#" + hashtag); } else { _this.hashtags.push(hashtag); } }); }; RoomSubject.prototype.resetHashtags = function () { this.hashtags = Object.assign([], this.defaultHashtags); }; RoomSubject.prototype.clearHashtags = function () { this.hashtags = []; }; RoomSubject.prototype.setNewSubject = function (newSubject) { this.subject = newSubject; }; RoomSubject.prototype.resetSubject = function () { this.subject = this.defaultSubject; }; RoomSubject.prototype.applyChanges = function () { cb.changeRoomSubject("" + this.subject + (this.hashtags.length > 0 ? ' | ' : '') + this.hashtags.join(' ')); }; RoomSubject.prototype.status = function () { this.notice.sendUserNotice(cb.room_slug, "Subject: " + this.subject); this.notice.sendUserNotice(cb.room_slug, "Hashtags: " + this.hashtags.join(' ')); }; RoomSubject.prototype.configureCommandParser = function () { var _this = this; var commandGroup = 'RoomSubject'; this.commandParser.createGroup(commandGroup, '/subject'); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'set', function (_) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } if (args.length === 0) return; _this.setNewSubject(args.join(' ')); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'reset', function () { _this.resetSubject(); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'apply', function () { _this.applyChanges(); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'status', function () { _this.status(); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'add-hashtags', function (_) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } if (args.length === 0) return; _this.addHashtags.apply(_this, args); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'reset-hashtags', function () { _this.resetHashtags(); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'clear-hashtags', function () { _this.clearHashtags(); }); this.commandParser.registerAction(commandGroup, Permission.Broadcaster, 'reset-all', function () { _this.resetSubject(); _this.resetHashtags(); }); }; RoomSubject.instance = null; return RoomSubject; }()); var commandParser = CommandParser.getInstance(); var roomSubject = RoomSubject.getInstance(); var notice = Notice.getInstance(); cb.settings_choices = [ { type: 'str', name: 'subject', label: 'Room subject' }, { type: 'str', name: 'hashtags', label: 'Hashtags' } ]; var subject = ''; if (cb.settings['subject']) { subject = cb.settings['subject']; } var hashtags = []; if (cb.settings['hashtags']) { hashtags = cb.settings['hashtags'].replace(' ', '').split(','); cb.log(hashtags.toString()); } roomSubject.initialize(subject, hashtags); roomSubject.applyChanges(); cb.onTip(function (tip) { notice.sendUserNotice(tip.from_user, 'Thank you for the tip.', Color.white, Color.blue, 'bold'); }); cb.onMessage(function (message) { commandParser.parseCommand(message); return message; });
© Copyright Chaturbate 2011- 2025. All Rights Reserved.