Bots Home
|
Create an App
Melody's Personality Test
Author:
lemons_
Description
Source Code
Launch Bot
Current Users
Created by:
Lemons_
// MIND STAT_INTROVERSION = "I" EXTROVERSION = "E" // energy STAT_INTUITION = "N" OBSERVANT = "O" // nature STAT_THINKING = "T" FEELING = "F" // tactics STAT_PROSPECTING = "P" JUDGING = "J" // identity STAT_ASSERTIVE = "-A" TURBULENT = "-T" STATS = [STAT_INTROVERSION, STAT_INTUITION, STAT_THINKING, STAT_PROSPECTING] NEG_STATS = [EXTROVERSION, OBSERVANT, FEELING, JUDGING] CATEGORIES = { [STAT_INTROVERSION]: "Mind", [STAT_INTUITION]: "Energy", [STAT_THINKING]: "Nature", [STAT_PROSPECTING]: "Tactics", } QUESTIONS = [ {text: "I prefer to be alone", affects: STAT_INTROVERSION, direction: +1}, {text: "I prefer to be with others", affects: STAT_INTROVERSION, direction: -1}, {text: "I always know how I feel", affects: STAT_INTUITION, direction: +1}, {text: "I know what other people are thinking", affects: STAT_INTUITION, direction: -1}, {text: "I never trust my gut", affects: STAT_THINKING, direction: +1}, {text: "I prefer to trust my gut", affects: STAT_THINKING, direction: -1}, {text: "I like to prospect", affects: STAT_PROSPECTING, direction: +1}, {text: "I like to judge people", affects: STAT_PROSPECTING, direction: -1}, ] ANSWERS = { 1: "Disagree Strongly", 2: "Disagree Slightly", 3: "Neither Agree or Disagree", 4: "Agree Slightly", 5: "Agree Strongly", } TYPES = { INTP: "Logician", INFP: "Mediator", INTJ: "intj", INFJ: "infj", ENTP: "entp", ENFP: "enfp", ENTJ: "entj", ENFJ: "enfj", IOTP: "iotp", IOFP: "iofp", IOTJ: "iotj", IOFJ: "iofj", EOTP: "eotp", EOFP: "eofp", EOTJ: "eotj", EOFJ: "eofj", } class Player { constructor(name) { this.name = name this.questions = [] this.answers = {} this.index = 0 this.results = {} this.personality = null this.isMod = false this.isTesting = false } get question() { return this.questions[this.index] } get numQuestions() { return this.questions.length } startTest() { this.index = 0 this.results = {} this.questions = QUESTIONS.map((q) => q) this.questions.sort((q) => Math.random()) this.isTesting = true this.ask() } quitTest() { this.isTesting = false } ask() { const lines = [ `Assertion ${this.index + 1}/${this.numQuestions}: ${this.question.text}`, `<- Disagree 1 - 2 - 3 - 4 - 5 Agree ->`, ] print(lines.join("\n"), this) } answer(n) { this.answers[this.index] = n print(`You answered ${n}: ${ANSWERS[n]} `, this) this.index++ if (this.index >= this.numQuestions) { this.calculate() this.isTesting = false } else { this.ask() } } calculate() { this.results = {} for (let i = 1; i < this.numQuestions; i++) { const question = this.questions[i], answer = this.answers[i] if (this.results[question.affects] === undefined) { this.results[question.affects] = 0 } this.results[question.affects] += answer * question.direction } this.personality = "" for (let i = 0; i < STATS.length; i++) { this.personality += (this.results[STATS[i]] || 0) >= 0 ? STATS[i] : NEG_STATS[i] } const stats = STATS.map((k) => `${CATEGORIES[k]}: ${this.results[k]}`) print(`Completed the test ${this.personality} - ${TYPES[this.personality]} [${stats.join(", ")}]`, this) } get isBroadcaster() { return this.name == cb.room_slug } get isAdmin() { return this.isBroadcaster || this.isMod } } // Players class Players { constructor() { this.players = {} } get(name) { if (!this.players[name]) { this.players[name] = new Player(name) } return this.players[name] } } class Game { constructor() { this.players = new Players() if (cb.settings.broadcasterPersonality) { const broadcaster = this.players.get(cb.room_slug) broadcaster.result = cb.settings.broadcasterPersonality } } showHelp(player) { const s = cb.settings const lines = [ title("Help"), `TIP ${s.costToTakeTest} to start test`, "Enter 1, 2, 3, 4 or 5 to answer the questions posed.", "/ptrepeat - Repeat the current question", ] if (player.isAdmin) { //lines.push("/ptset lemons_ INFP - set test results for a user (ADMIN ONLY)") lines.push("/ptstart to start test without tipping (ADMIN ONLY)") } print(lines.join("\n"), player) } player(name) { return this.players.get(name) } } const title = (label) => { return `--- Melody's Personality Test: ${label} ---` } const print = (message, player, background, foreground, weight, to_group) => { return cb.sendNotice(message, (player ? player.name : null), background, foreground, weight, to_group) } const remind = () => { cb.chatNotice("We are playing Melody's Personality Test by lemons_! (/help for instructions)") remindEvent = cb.setTimeout(remind, remindDelayMs) } let game, remindDelayMs // onEnter() cb.onEnter((user) => { print(`Welcome ${user.user}, we are playing Melody's Personality Test (/pthelp for instructions)`, user.user) }) // onStart() cb.onStart((user) => { remindDelayMs = cb.settings.reminderDelayMinutes * 60 * 1000 game = new Game() remindEvent = cb.setTimeout(remind, remindDelayMs) }) // onTip() cb.onTip((tip) => { const amount = tip.amount const name = tip.from_user const s = cb.settings const player = game.player(name) switch (amount) { case s.costToTakeTest: player.startTest() break } }) // onMessage cb.onMessage((msg) => { const message = msg.m const player = game.player(msg.user) player.isMod = msg.is_mod msg.m = (player.personality ? `[${player.personality}] ` : "") + msg.m if (message === "/pthelp") { game.showHelp(player) msg['X-Spam'] = true } else if (message === "/ptrepeat") { if (player.isTesting) { player.ask() } else { print(`Not currently in a personality test (TIP ${cb.settings.costToTakeTest} tokens to start one)!`, player) } msg['X-Spam'] = true } else if (message.startsWith("/ptset") && player.isAdmin) { const args = message.slice(7).split(" ") game.setResult(args[0], args[1]) msg['X-Spam'] = true } else if (message.startsWith("/ptstart") && player.isAdmin) { player.startTest() msg['X-Spam'] = true } else if (["1", "2", "3", "4", "5"].includes(message)) { player.answer(parseInt(message)) msg['X-Spam'] = true } return msg }) cb.settings_choices = [ {name: 'costToTakeTest', type: 'int', defaultValue: 50, minValue: 1, label: "Number of tokens to start test"}, {name: 'broadcasterPersonality', type: 'str', defaultValue: "INFP", required: false, label: "Broadcaster's personality"}, {name: 'reminderDelayMinutes', type: 'int', defaultValue: 4, minValue: 1, label: "Remind users every X minutes"}, ]
© Copyright Chaturbate 2011- 2024. All Rights Reserved.