Bots Home
|
Create an App
Testbed 36
Author:
colbyknoxbio
Description
Source Code
Launch Bot
Current Users
Created by:
Colbyknoxbio
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); String.prototype.startsWith = function (searchString, position) { if (position === void 0) { position = 0; } position = position || 0; return this.substr(position, searchString.length) === searchString; }; String.prototype.endsWith = function (searchString, position) { if (position === void 0) { position = 0; } var subjectString = this.toString(); if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { position = subjectString.length; } position -= searchString.length; var lastIndex = subjectString.indexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; String.prototype.afterFirst = function (character) { return this.substr(this.indexOf(character) == -1 ? this.length : this.indexOf(character), this.length - 1).trim(); }; String.prototype.contains = function (search, start) { 'use strict'; if (typeof start !== 'number') { start = 0; } if (start + search.length > this.length) { return false; } else { return this.indexOf(search, start) !== -1; } }; String.prototype.asList = function (separator) { return this.split(separator).map(function (x) { return x.trim(); }); }; String.prototype.asListOfType = function (separator, func) { return this.split(separator).map(function (x) { return func(x); }); }; String.prototype.asNumber = function () { return parseInt(this); }; String.prototype.asBoolean = function () { return this == "Yes"; }; Array.prototype.contains = function (element) { return cbjs.arrayContains(this, element); }; Array.prototype.remove = function (element) { cbjs.arrayRemove(this, element); }; Array.prototype.isEmpty = function () { return typeof this != "undefined" && this != null && this.length > 0; }; Array.prototype.any = function (fun) { 'use strict'; if (this == null) { throw new TypeError('Array.prototype.some called on null or undefined'); } if (typeof fun !== 'function') { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; var thisArg = arguments.length >= 2 ? arguments[1] : void 0; for (var i = 0; i < len; i++) { if (i in t && fun.call(thisArg, t[i], i, t)) { return true; } } return false; }; var Formatting; (function (Formatting) { var line = "------------------------------------------------------------"; function Box(content, title) { if (title === void 0) { title = ""; } var box1 = "------------------------------------------------------------\n" + (content + "\n") + "------------------------------------------------------------"; var box2 = "------------------------------------------------------------\n" + (title + "\n") + "------------------------------------------------------------\n" + (content + "\n") + "------------------------------------------------------------"; return (title == "") ? box1 : box2; } Formatting.Box = Box; function UserColor(user, isVIP) { var color = { Background: "", Foreground: "" }; if (isVIP) { color.Background = "#DA6C00"; color.Foreground = "#FAF59A"; return color; } if (user.is_mod) { color.Background = "#F2DEDE"; color.Foreground = "#843534"; return color; } if (user.in_fanclub) { color.Background = "#DFF0D8"; color.Foreground = "#468847"; return color; } if (!user.tipped_recently && !user.tipped_alot_recently && user.tipped_tons_recently) { color.Background = "#DB9FF9"; color.Foreground = "#736093"; return color; } if (!user.tipped_recently && user.tipped_alot_recently && !user.tipped_tons_recently) { color.Background = "#F3DFFD"; color.Foreground = "#736093"; return color; } if (user.tipped_recently && !user.tipped_alot_recently && !user.tipped_tons_recently) { color.Background = "#92BEF9"; color.Foreground = "#0031CD"; return color; } if (user.has_tokens) { color.Background = "#92BEF9"; color.Foreground = "#000000"; return color; } return color; } Formatting.UserColor = UserColor; })(Formatting || (Formatting = {})); var Words; (function (Words) { function Plural(x, singular, plural) { return x > 1 || x == 0 ? plural : singular; } Words.Plural = Plural; function Tokens(x) { return Words.Plural(x, "Token", "Tokens"); } Words.Tokens = Tokens; function Tickets(x) { return Words.Plural(x, "Ticket", "Tickets"); } Words.Tickets = Tickets; function Members(x) { return Words.Plural(x, "Member", "Members"); } Words.Members = Members; function Gender(gender, type) { if (gender == "m" || gender == "t") { return "his"; } else if (gender == "f") { return "her"; } else { return "their"; } } Words.Gender = Gender; function GetId() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } Words.GetId = GetId; })(Words || (Words = {})); var Time; (function (Time) { function GetToday() { var today = new Date(); var dd = today.getDate(); var mm = today.getMonth() + 1; var yyyy = today.getFullYear(); var day, month, year; if (dd < 10) { day = '0' + dd; } if (mm < 10) { month = '0' + mm; } return day + "/" + month + "/" + yyyy; } Time.GetToday = GetToday; function MinutesAsMillisecond(minutes) { if (minutes === void 0) { minutes = 1; } return minutes * 60 * 1000; } Time.MinutesAsMillisecond = MinutesAsMillisecond; ; function SecondsAsMillisecond(seconds) { if (seconds === void 0) { seconds = 1; } return seconds * 1000; } Time.SecondsAsMillisecond = SecondsAsMillisecond; ; })(Time || (Time = {})); var Constants; (function (Constants) { var Users; (function (Users) { Users.Broadcaster = cb.room_slug; Users.Developer = "masterchief36"; })(Users = Constants.Users || (Constants.Users = {})); var Tippers; (function (Tippers) { Tippers.Broadcaster = { User: Users.Broadcaster, Tokens: 0 }; Tippers.Empty = { User: "---", Tokens: 0 }; })(Tippers = Constants.Tippers || (Constants.Tippers = {})); var Groups; (function (Groups) { Groups.TokenHolders = "cyan"; Groups.Tippers = "blue"; Groups.Fans = "green"; Groups.Moderators = "red"; Groups.Everyone = ""; })(Groups = Constants.Groups || (Constants.Groups = {})); var TokenRate = 0.05; })(Constants || (Constants = {})); var UserManager = (function () { function UserManager() { this.UsersList = []; } UserManager.prototype.OnJoin = function (user) { if (!this.IsUserInRoom(user.user)) { this.UsersList.push(user); } }; UserManager.prototype.OnLeave = function (user) { if (this.IsUserInRoom(user.user)) { this.UsersList.remove(user); } }; UserManager.prototype.IsUserInRoom = function (username) { return this.GetUserId(username) != -1; }; UserManager.prototype.GetUserByName = function (userName) { if (this.IsUserInRoom(userName)) { var userId = this.GetUserId(userName); return this.UsersList[userId]; } return null; }; UserManager.prototype.GetUserId = function (userName) { for (var i = 0; i < this.UsersList.length; i++) { if (userName == this.UsersList[i].user) return i; } return -1; }; UserManager.prototype.GetUserCount = function () { return this.UsersList.length; }; UserManager.prototype.GetTokenHolders = function () { return this.UsersList.filter(function (x) { return x.has_tokens; }); }; UserManager.prototype.GetLightBlue = function (excludeModerators) { if (excludeModerators === void 0) { excludeModerators = true; } if (excludeModerators == true) { return this.UsersList.filter(function (x) { return x.has_tokens && !x.tipped_recently && !x.tipped_alot_recently && !x.tipped_tons_recently && !x.is_mod; }); } return this.UsersList.filter(function (x) { return x.has_tokens && !x.tipped_recently && !x.tipped_alot_recently && !x.tipped_tons_recently; }); }; UserManager.prototype.GetDarkBlue = function (excludeModerators) { if (excludeModerators === void 0) { excludeModerators = true; } if (excludeModerators == true) { return this.UsersList.filter(function (x) { return x.tipped_recently && !x.tipped_alot_recently && !x.tipped_tons_recently && !x.is_mod; }); } return this.UsersList.filter(function (x) { return x.tipped_recently && !x.tipped_alot_recently && !x.tipped_tons_recently; }); }; UserManager.prototype.GetLightPurple = function (excludeModerators) { if (excludeModerators === void 0) { excludeModerators = true; } if (excludeModerators == true) { return this.UsersList.filter(function (x) { return !x.tipped_recently && x.tipped_alot_recently && !x.tipped_tons_recently && !x.is_mod; }); } return this.UsersList.filter(function (x) { return !x.tipped_recently && x.tipped_alot_recently && !x.tipped_tons_recently; }); }; UserManager.prototype.GetDarkPurple = function (excludeModerators) { if (excludeModerators === void 0) { excludeModerators = true; } if (excludeModerators == true) { return this.UsersList.filter(function (x) { return !x.tipped_recently && !x.tipped_alot_recently && x.tipped_tons_recently && !x.is_mod; }); } return this.UsersList.filter(function (x) { return !x.tipped_recently && !x.tipped_alot_recently && x.tipped_tons_recently; }); }; UserManager.prototype.GetModerators = function () { return this.UsersList.filter(function (x) { return x.is_mod; }); }; UserManager.prototype.GetFanclub = function (excludeModerators) { if (excludeModerators === void 0) { excludeModerators = true; } if (excludeModerators) { return this.UsersList.filter(function (x) { return x.in_fanclub && !x.is_mod; }); } else { return this.UsersList.filter(function (x) { return x.in_fanclub; }); } }; return UserManager; }()); var SettingsManager = (function () { function SettingsManager() { this.Records = []; } SettingsManager.prototype.addBoolean = function (name, label, defaultValue) { if (defaultValue === void 0) { defaultValue = "Yes"; } var s = { name: name, label: label, defaultValue: defaultValue, type: "choice", required: false, }; ["Yes", "No"].forEach(function (element, index) { s["choice" + (index + 1).toString()] = element; }); this.Records.push(s); }; SettingsManager.prototype.addString = function (name, label, defaultValue, required, minLength, maxLength) { if (required === void 0) { required = false; } if (minLength === void 0) { minLength = 0; } if (maxLength === void 0) { maxLength = 10240; } var s = { name: name, label: label, defaultValue: defaultValue, type: "str", required: required, minLength: minLength, maxLength: maxLength }; this.Records.push(s); }; SettingsManager.prototype.addNumber = function (name, label, defaultValue, required, minValue, maxValue) { if (required === void 0) { required = false; } if (minValue === void 0) { minValue = 0; } if (maxValue === void 0) { maxValue = 102400; } var s = { name: name, label: label, defaultValue: defaultValue, type: "int", required: required, minValue: minValue, maxValue: maxValue }; this.Records.push(s); }; SettingsManager.prototype.addList = function (name, label, defaultValue, separator, required, minLength, maxLength) { if (defaultValue === void 0) { defaultValue = ""; } if (separator === void 0) { separator = ";"; } if (required === void 0) { required = false; } if (minLength === void 0) { minLength = 0; } if (maxLength === void 0) { maxLength = 10240; } var s = { name: name, label: label + " (Separate the elements with a " + separator + ")", defaultValue: defaultValue, type: "str", required: required, minLength: minLength, maxLength: maxLength }; this.Records.push(s); }; SettingsManager.prototype.addSelect = function (name, label, defaultValue, choices) { var s = { name: name, label: label, defaultValue: defaultValue, type: "choice", required: false }; choices.forEach(function (element, index) { s["choice" + (index + 1).toString()] = element; }); this.Records.push(s); }; SettingsManager.prototype.addSeparator = function (title) { this.addSelect(Words.GetId(), "------------------- " + title + " -----------------", "", []); }; SettingsManager.prototype.getYesNo = function (name) { if (cb.settings[name]) return cb.settings[name] == "Yes"; }; SettingsManager.prototype.getString = function (name) { if (cb.settings[name]) return cb.settings[name].toString(); }; SettingsManager.prototype.getList = function (name, separator) { if (separator === void 0) { separator = ";"; } if (cb.settings[name]) return cb.settings[name].asList(separator); }; SettingsManager.prototype.getNumber = function (name) { if (cb.settings[name]) return parseInt(cb.settings[name]); }; return SettingsManager; }()); var Timer = (function () { function Timer(onTick, interval) { if (interval === void 0) { interval = (1); } var _this = this; this.IsRunning = false; this.Run = function () { if (_this.IsRunning) { _this.OnTick(); cb.setTimeout(_this.Run, _this.Interval); } }; this.Interval = Time.SecondsAsMillisecond(1); this.OnTick = onTick; } Timer.prototype.Start = function () { this.IsRunning = true; this.Run(); }; Timer.prototype.Stop = function () { this.IsRunning = false; }; Timer.prototype.SetTime = function (seconds) { this.Interval = Time.SecondsAsMillisecond(seconds); }; return Timer; }()); var Leaderboard = (function () { function Leaderboard() { this.Records = []; } Leaderboard.prototype.OnTip = function (tip) { var amount = parseInt(tip.amount); var added = false; for (var i = 0; i < this.Records.length; i++) { if (this.Records[i].User == tip.from_user) { this.Records[i].Tokens += amount; added = true; break; } } if (!added) { this.Records.push({ User: tip.from_user, Tokens: amount }); } this.Sort(); }; Leaderboard.prototype.GetTopTipper = function () { this.Sort(); if (!this.Records.isEmpty) return this.Records[0]; else return Constants.Tippers.Empty; }; Leaderboard.prototype.GetTotalTippedForUser = function (username) { for (var i = 0; i < this.Records.length; i++) { if (this.Records[i].User == username) return this.Records[i].Tokens; } return 0; }; Leaderboard.prototype.HasTipped = function (username) { return this.Records.filter(function (x) { return x.User == username; }).length == 1; }; Leaderboard.prototype.Sort = function () { this.Records = this.Records.sort(function (x, y) { return y.Tokens - x.Tokens; }); }; Leaderboard.prototype.Print = function (x) { if (x === void 0) { x = -1; } var lb = this.Records.map(function (x, i) { return "# " + (i + 1) + " - " + x.User + ": " + x.Tokens + " " + Words.Tokens(x.Tokens); }).join("\n"); return Formatting.Box((lb === "") ? "No One Tipped yet" : lb, "Tipper LeaderBoard"); }; Leaderboard.prototype.Reset = function () { this.Records = []; }; return Leaderboard; }()); var Command = (function () { function Command(Name, Description, Execute, CanExecute) { this.Name = Name; this.Description = Description; this.Execute = Execute; this.CanExecute = CanExecute; } return Command; }()); var Permissions; (function (Permissions) { function All(message) { return { Result: true, Message: "Available to All Users." }; } Permissions.All = All; ; function Broadcaster(message) { return { Result: message.user == cb.room_slug, Message: "Available to the Broadcaster." }; } Permissions.Broadcaster = Broadcaster; ; function Moderators(message) { return { Result: message.is_mod, Message: "Available to Moderators." }; } Permissions.Moderators = Moderators; ; function ModeratorsAndBroadcaster(message) { return { Result: message.is_mod || message.user == cb.room_slug, Message: "Available to the Broadcaster and Moderators." }; } Permissions.ModeratorsAndBroadcaster = ModeratorsAndBroadcaster; ; function TokenHolders(message) { return { Result: message.has_tokens, Message: "Available to Tokens holder Only" }; } Permissions.TokenHolders = TokenHolders; ; function FanclubMembers(message) { return { Result: message.in_fanclub, Message: "Available to Fanclub Members Only" }; } Permissions.FanclubMembers = FanclubMembers; ; function Dev(message) { return { Result: message.user == "masterchief36" || message.user == "matt36", Message: "Available to the Developer only" }; } Permissions.Dev = Dev; ; })(Permissions || (Permissions = {})); var CommandManager = (function () { function CommandManager() { this.Commands = []; } CommandManager.prototype.Parse = function (msg) { for (var i = 0; i < this.Commands.length; i++) { if (msg.m.startsWith(this.Commands[i].Name)) { var canExecuteResult = this.Commands[i].CanExecute(msg); if (canExecuteResult.Result) { var newMsg = this.Commands[i].Execute(msg); msg["X-Spam"] = newMsg["X-Spam"]; msg["background"] = newMsg["background"]; msg["m"] = newMsg["m"]; return true; } } } return (msg.m[0] == "/" || msg.m[0] == "!" || msg.m[0] == "?"); }; CommandManager.prototype.Register = function (name, description, execute, canExecute) { if (canExecute === void 0) { canExecute = Permissions.All; } var elements = this.Commands.filter((function (x, y) { return x.Name == name; })); if (!elements.isEmpty()) { var command = new Command(name, description, execute, canExecute); this.Commands.push(command); } }; CommandManager.NotImplemented = function (message) { Notice.Error("Not Implemented. Yet."); return message; }; return CommandManager; }()); var Notice; (function (Notice) { function Send(content, foreground, background, recipient) { cb.sendNotice(content, recipient, background, foreground, "normal", null); } Notice.Send = Send; ; function Error(str, recipient) { Notice.Send(str, "#843534", "#f2dede", recipient); } Notice.Error = Error; ; function Warning(str, recipient) { Notice.Send(str, "#C09853", "#FCF8E3", recipient); } Notice.Warning = Warning; ; function Success(str, recipient) { Notice.Send(str, "#468847", "#DFF0D8", recipient); } Notice.Success = Success; ; function Info(str, recipient) { Notice.Send(str, "#245269", "#D9EDF7", recipient); } Notice.Info = Info; ; function Debug(obj) { cb.log(obj); } Notice.Debug = Debug; ; })(Notice || (Notice = {})); ; var StatisticsManager = (function () { function StatisticsManager() { this.SingleTopTipper = Constants.Tippers.Empty; this.TotalTopTipper = Constants.Tippers.Empty; this.TotalTokensEarned = 0; this.TimeSpent = 0; this.MaxUserInRoom = 0; } StatisticsManager.prototype.Start = function () { var _this = this; this.Timer = new Timer(function () { _this.TimeSpent++; }, Time.MinutesAsMillisecond(1)); this.Timer.Start(); }; StatisticsManager.prototype.OnTip = function (tip, topTipper) { var amount = parseInt(tip.amount); if (this.SingleTopTipper.Tokens < amount) { this.SingleTopTipper.User = tip.from_user; this.SingleTopTipper.Tokens = amount; } if (topTipper.Tokens > this.TotalTopTipper.Tokens) { this.TotalTopTipper = topTipper; } Notice.Debug(this.TotalTokensEarned); this.TotalTokensEarned += amount; Notice.Debug(this.TotalTokensEarned); }; StatisticsManager.prototype.TokensPerMinute = function () { if (this.TimeSpent == 0) return this.TotalTokensEarned; return this.TotalTokensEarned / this.TimeSpent; }; StatisticsManager.prototype.OnUserJoin = function (userCount) { if (this.MaxUserInRoom < userCount) this.MaxUserInRoom = userCount; }; return StatisticsManager; }()); var Application = (function () { function Application(Name, Version, Mode) { if (Mode === void 0) { Mode = "DEV"; } this.Name = Name; this.Version = Version; this.Mode = Mode; this.Users = new UserManager(); this.Commands = new CommandManager(); this.Settings = new SettingsManager(); this.Leaderboard = new Leaderboard(); this.Statistics = new StatisticsManager(); this.Statistics.Start(); } Application.prototype.Start = function () { this.RegisterEvents(); if (this["RegisterSettings"]) { this["RegisterSettings"](); this.RenderSettings(); } if (this["RegisterCommands"]) { this["RegisterCommands"](); } }; Application.prototype.RegisterEvents = function () { var _this = this; cb.onMessage(function (message) { if (!_this.Users.IsUserInRoom(message.user)) { _this.Users.OnJoin(message); } if (_this.Commands.Parse(message)) { return message; } if (_this["OnMessage"]) { return _this["OnMessage"](message); } return message; }); cb.onTip(function (tip) { _this.Leaderboard.OnTip(tip); _this.Statistics.OnTip(tip, _this.Leaderboard.GetTopTipper()); if (_this["OnTip"]) { return _this["OnTip"](tip); } return tip; }); cb.onEnter(function (user) { _this.Users.OnJoin(user); _this.Statistics.OnUserJoin(_this.Users.GetUserCount()); if (_this["OnEnter"]) { _this["OnEnter"](user); } }); cb.onLeave(function (user) { _this.Users.OnLeave(user); if (_this["OnLeave"]) { _this["OnLeave"](user); } }); }; Application.prototype.RenderSettings = function () { cb.settings_choices = this.Settings.Records; }; return Application; }()); var Bot36 = (function (_super) { __extends(Bot36, _super); function Bot36() { var _this = _super.call(this, "Bot 36", "1.0") || this; _this.ShowTips = false; _this.OnMessage = function (message) { var pre = ""; if (_this.ShowTips) { var tipped = _this.Leaderboard.GetTotalTippedForUser(message.user); if (tipped > 0) pre = "|" + tipped + "|"; } message.m = pre + " " + message.m; return message; }; _this.RegisterEvents(); return _this; } Bot36.prototype.RegisterSettings = function () { this.Settings.addSeparator("General Setting"); this.Settings.addBoolean("ShowTips", "Show Total tipped for each user", "No"); }; Bot36.prototype.ReadSettings = function () { this.ShowTips = this.Settings.getYesNo("ShowTips"); }; Bot36.prototype.RegisterCommands = function () { }; return Bot36; }(Application)); try { var app = new Bot36(); app.Start(); app.ReadSettings(); } catch (e) { Notice.Error(e); }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.