Apps Home
|
Create an App
dennis8211
Author:
dennis8211_bc
Description
Source Code
Launch App
Current Users
Created by:
Dennis8211_Bc
const advertiseInterval = 180000; const advertiseMessage = 'Activate my lovense without tipping!'; const command = 'level'; const errorMessage = 'Whoops, I didn\'t understand your request, please try again!'; const thankYouMessage = 'Thank you so much for buzzing me! Send me some more :-)'; const welcomeMessage = 'Welcome to my room!'; const colorError = '#B42626'; const colorNotice = '#2671B4'; const colorSuccess = '#26B439'; // @TODO can we prevent "duplicate message not sent"? class App { constructor() { // Set up event listeners cb.onMessage((message) => { this.handleMessage(message); }); cb.onStart(() => { this.advertise() }); cb.onEnter((user) => { this.handleNewUser(user); }); this.advertiseOnNextInterval(); } handleMessage(message) { const regex = new RegExp('^\/' + command + '\\b', 'i'); if (message.m.match(regex)) { message = this.handleCommand(message); } return message; } handleCommand(message) { const regex = new RegExp('^\/' + command + '\\s+(\\d+)\\s*$', 'i'); const matches = message.m.match(regex); if (!matches) { this.error(errorMessage) this.error('Invalid usage: "' + message.m + '"'); this.help(); return message; } const level = matches[1]; // @TODO: check if level != 0 and level <= max message.m = 'activated level ' + level; this.success(thankYouMessage); // @TODO Activate lovense return message; } handleNewUser(user) { // @TODO: order of messages is weird this.notice(welcomeMessage, user.user); this.advertise(user.user); } advertiseOnNextInterval() { cb.setTimeout(() => { this.advertise(); this.advertiseOnNextInterval(); }, advertiseInterval); } advertise(username) { this.notice(advertiseMessage, username); this.help(username); } help(username) { // @TODO: list available levels this.notice('Usage:', username); this.notice('HELP HERE. LIST AVAILABLE LEVELS', username); } success(message, user) { cb.sendNotice(message, user, colorSuccess, '#FFFFFF', 'bold'); } notice(message, user) { cb.sendNotice(message, user, colorNotice, '#FFFFFF', 'bold'); } error(message, user) { cb.sendNotice(message, user, colorError, '#FFFFFF', 'bold'); } } new App();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.