Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Basic custom and searchable quotes command for Twitch nightbot. */
- /** Specific quotes can be called by either a number or word (eg. "!myQuote 1" or "!myQuote raid") or random (eg. "!myQuote") */
- /** See author comments for instructions */
- let response = '';
- {
- /****** QUOTE COLLECTION ******/
- /*** EXAMPLE: ["No.","Yes."] */
- const arr = [];
- /*** NOTE: Match to 'arr' but start with 0 not 1 */
- /*** EXAMPLE: {no:0, yes:1} */
- const dict = {};
- /****** SUPPORT FUNCTIONS ******/
- /*** function responsePool: Reserve specific responses
- to special keywords */
- let responsePool = (keyWord) =>{
- let randQuote = -1; let quotes = []; let holder = true;
- switch(keyWord) {
- case 'my_keyword_here': /* <--- Change these values */
- case 'another_keyword': /* <--- stack multiple keywords*/
- quotes = [0,1]; /* <---- Select your responses*/
- randQuote = quotes[Math.floor(Math.random() * 2)]; /* <---- Update number count */
- break; /* <---- Remember to break; to close block */
- default:
- holder = false;
- }
- /*** NOTE: uncomment this block for punctuation functionality
- if (!holder) {
- switch(keyWord.slice(-1)) {
- case '?':
- quotes = [];
- randQuote = quotes[Math.floor(Math.random() * 0)];
- }
- }
- ***/
- return randQuote;
- }
- /*** function buildResponse: Formats output for Twitch chat */
- /*** NOTE: 'commands' lists the Dictionary keys */
- let buildResponse = (input) =>{
- if (input == "commands") { return Object.keys(dict).join(" ").toString(); }
- else {
- isNaN(input)?line = arr[dict[input]] : line = arr[input];
- return `/me '${line}' - John Smith`; /* <---- Nightbot: /me 'a quote' - John Smith */
- }
- };
- /****** MAIN FUNCTION ******/
- var new_q = q;
- let trim_q = new_q.trim().toLowerCase();
- /* is not empty */
- if (trim_q !== ""){
- var input = trim_q.slice(-1) == '?' ? trim_q.split(' ')[0] + trim_q.slice(-1) : trim_q.split(' ')[0];
- /* is string */
- if (isNaN(input)){
- /* ResponsePool */
- const pool_response = responsePool(input);
- if (pool_response > -1) { input = pool_response; }
- /* invalid but not "commands" */
- else if (dict[input] === undefined & input != "commands") { input = Math.floor(Math.random()*arr.length); }
- /* is int */
- } else if (!isNaN(input)) {
- /* out of range */
- if (input >= arr.length | input < 0) { input = 0; }
- }
- /* format output */
- response = buildResponse(input);
- }
- /* is empty */
- else { response = buildResponse(Math.floor(Math.random()*arr.length)); }
- }
- /* Twitch output */
- response;
Advertisement
Comments
-
- Copy and paste this template into a new pastebin
- Copy the RAW url ( https://pastebin.com/raw/whatever )
- Paste URL into line below:
- $(eval q = `$(query)`; $(urlfetch json PASTE_YOUR_RAW_URL_HERE ))
- Use Nightbot's add command
- !addcom !command_name $(eval q = `$(query)`; $(urlfetch json PASTE_YOUR_RAW_URL_HERE ))
- ** For an example see my Arbiter quotes ( https://pastebin.com/hm3WWdj7 )
Add Comment
Please, Sign In to add comment
Advertisement