Bots Home
|
Create an App
Wagner
Author:
francy76
Description
Source Code
Launch Bot
Current Users
Created by:
Francy76
/* Title: "Wagner: a concert of notifications." bot Author: francy76 Version: 0.1 (02/11/2017) Tip menu customized for groups. */ const MAX_MENU_ITEMS = 2; const GROUPS = [{ name: 'regular', label: 'All', target: [] }, { name: 'fanClub', label: 'Fan Club', target: ['green'] }]; /**++SETTINGS-->**/ function intSetting(name, label, minValue, maxValue) { return { name: name, label: label, type: 'int', minValue: minValue, maxValue: maxValue }; } function strSetting(name, label, minLength, maxLength) { return { name: name, label: label, type: 'str', minLength: minLength, maxLength: maxLength }; } function choiceSetting(name, label, choices) { let result = { name: name, label: label, type: 'choice' }; for (let i = 0; i < choices.length; i++) { result['choice' + (i + 1)] = choices[i]; } return result; } function menuRow(index, kind) { let opt = strSetting(kind + '_item' + index, kind + ' text ' + (index + 1), 1, 100); opt.required = false; return opt; } function menuPrice(index, kind) { let opt = intSetting(kind + '_price' + index, kind + ' price of ' + (index + 1), 1); opt.required = false; return opt; } function tipMenu(kind) { let menu = []; for (let i = 0; i < MAX_MENU_ITEMS; i++) { menu.push(menuRow(i, kind)); menu.push(menuPrice(i, kind)); } return menu; } function groupSetting(group) { let result = []; let groupSet = strSetting(group.name + '_name', group.label + ' displayed name', 1, 15); result.push(groupSet); let delayOpt = intSetting(group.name + '_delay', 'Seconds between group ' + group.label + ' message', 1, 60000); result.push(delayOpt); let opening = strSetting(group.name + '_opening', group.label + ' Menu start', 1, 100); result.push(opening); return result; } function globalSettings() { let result = []; let menuRow = strSetting('menuRow', 'Menu Row (eg. %TEXT: %PRICE )', 1, 200); menuRow.defaultValue = '%TEXT (%PRICE)'; result.push(menuRow); let separator = strSetting('separator', 'Line separator', 1, 100); separator.defaultValue = ':smile'; result.push(separator); let bgRow = strSetting('background', 'Background of rows', 7, 7); bgRow.defaultValue = '#FFFFFF'; result.push(bgRow); let fgRow = strSetting('foreground', 'Foreground of rows', 7, 7); fgRow.defaultValue = '#000000'; result.push(fgRow); let weightRow = choiceSetting('weight', 'Weight of rows', ['normal', 'bold', 'bolder']); weightRow.defaultValue = 'normal'; result.push(weightRow); return result; } function settings() { let settings = []; settings.push.apply(settings, globalSettings()); for (let i = 0; i < GROUPS.length; i++) { settings.push.apply(settings, groupSetting(GROUPS[i])); settings.push.apply(settings, tipMenu(GROUPS[i].name)); } return settings; } /**<--SETTINGS++MESSAGES-->**/ function rowText(groupName, index) { let text = cb.settings[groupName + '_item' + index]; return text; } function rowPrice(groupName, index) { return cb.settings[groupName + '_price' + index]; } function row(text, price) { let row = cb.settings.menuRow; if (text != '') { row = row.replace(new RegExp('%TEXT', 'g'), text); row = row.replace(new RegExp('%PRICE', 'g'), price); } else { row = ''; } return row; } function addWithSeparator(total, delta, separator) { if (delta != '') { return total + " " + delta + " " + separator; } else { return total; } } function message(group) { let message = ''; let separator = cb.settings.separator; message = addWithSeparator(message, cb.settings[group.name + '_opening'], separator); for (let i = 0; i < MAX_MENU_ITEMS; i++) { let text = row(rowText(group.name, i), rowPrice(group.name, i)); message = addWithSeparator(message, text, i != (MAX_MENU_ITEMS - 1) ? separator : ''); } return message; } function notify(group) { let msg = message(group); if (group.target.length > 0) { for (let t = 0; t < group.target.length; t++) { cb.sendNotice(msg, '', cb.settings.background, cb.settings.foreground, cb.settings.weigth, group.target[t]); } } else { cb.sendNotice(msg, '', cb.settings.background, cb.settings.foreground, cb.settings.weigth); } } /**<--MESSAGES++SCHEDULING-->**/ function schedule(group) { let scheduleIt = function () { notify(group); schedule(group); } cb.setTimeout(scheduleIt, cb.settings[group.name + '_delay'] * 1000); } function initSchedule() { for (let g = 0; g < GROUPS.length; g++) { schedule(GROUPS[g]); } } /**<--SCHEDULING++INIT-->**/ function init() { cb.settings_choices = settings(); initSchedule(); } init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.