Bots Home
|
Create an App
evie's droid testbed
Author:
evie_android_testbed
Description
Source Code
Launch Bot
Current Users
Created by:
Evie_Android_Testbed
/* Evie's droid v1 * created 2019/01/31 by evie_android */ // startup settings cb.settings_choices = [{ name: 'keyword1', type: 'str', minlength: 1, maxlength: 60, label: "keyword(s) to detect, separated by commas, single line: e.g. hi,hello,hey,Hi,Hello,Hey" }, { name: 'response1', type: 'str', minlength: 1, maxlength: 255, label: "response to keyword(s) (max length 255 characters)" }, { name: 'keyword2', type: 'str', minlength: 1, maxlength: 60, label: "keyword(s) 2", required: false }, { name: 'response2', type: 'str', minlength: 1, maxlength: 255, label: "response 2", required: false }, { name: 'keyword3', type: 'str', minlength: 1, maxlength: 60, label: "keyword(s) 3", required: false }, { name: 'response3', type: 'str', minlength: 1, maxlength: 255, label: "response 3", required: false }, { name: 'keyword4', type: 'str', minlength: 1, maxlength: 60, label: "keyword(s) 4", required: false }, { name: 'response4', type: 'str', minlength: 1, maxlength: 255, label: "response 4", required: false }, { name: 'keyword5', type: 'str', minlength: 1, maxlength: 60, label: "keyword(s) 5", required: false }, { name: 'response5', type: 'str', minlength: 1, maxlength: 255, label: "response 5", required: false }]; // keyword regex + response pairs var keyResponsePairs = [{ keywordRegex: null, response: '' }, { keywordRegex: null, response: '' }, { keywordRegex: null, response: '' }, { keywordRegex: null, response: '' }, { keywordRegex: null, response: '' }]; //functions function parseCSV(str) { //parsing the single user-entered string into an a array of keyword strings var arr = []; // iterate over each character, keep track of current column (of the returned array) for (col = 0, index = 0; index < String(str).length; index++) { var cc = String(str)[index], nc = String(str)[index+1]; // current character, next character arr[col] = arr[col] || ''; // create a new column (start with empty string) if necessary // If it's a comma, move on to the next column if (cc == ',') { ++col; continue; } // If it's a newline, move on to the next column if (cc == '\r' && nc == '\n') { ++index; continue; } // Otherwise, append the current character to the current column arr[col] += cc; } return arr; } function parseToRegExp(arr) { //parsing the array of strings into a single regex line var regexContent = '/'; for(var i = 0; i < arr.length; i++) { regexContent = regexContent.concat('(?:' + arr[i] + ') '); } regexContent = regexContent.concat('/'); //DEBUGv cb.log('parsing, regex is' + regexContent); //DEBUG^ var regex = new RegExp(regexContent); return regex; } function init() { //parse csv strings into arrays var keywordArrays = [[]]; if(cb.settings.keyword1 !== null) { keywordArrays.push(parseCSV(cb.settings.keyword1)); } else { keywordArrays.push([]); } if(cb.settings.keyword2 !== null) { keywordArrays.push(parseCSV(cb.settings.keyword2)); } else { keywordArrays.push([]); } if(cb.settings.keyword3 !== null) { keywordArrays.push(parseCSV(cb.settings.keyword3)); } else { keywordArrays.push([]); } if(cb.settings.keyword4 !== null) { keywordArrays.push(parseCSV(cb.settings.keyword4)); } else { keywordArrays.push([]); } if(cb.settings.keyword5 !== null) { keywordArrays.push(parseCSV(cb.settings.keyword5)); } else { keywordArrays.push([]); } //build the regex + response pairs for use in scanning and producing messages keyResponsePairs[0].keywordRegex = parseToRegExp(keywordArrays[0]); keyResponsePairs[1].keywordRegex = parseToRegExp(keywordArrays[1]); keyResponsePairs[2].keywordRegex = parseToRegExp(keywordArrays[2]); keyResponsePairs[3].keywordRegex = parseToRegExp(keywordArrays[3]); keyResponsePairs[4].keywordRegex = parseToRegExp(keywordArrays[4]); } // handlers cb.onMessage(function(msg) { //parsing incoming messages to detect keyword(s) switch(msg['m']) { //DEBUGv case 'regex': for(var i = 0; i < 5; i++) { cb.log(keyResponsePairs[i].keywordRegex.pattern); } //DEBUG^ default: break; }; }); init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.