Advertisement
wroughtwheat

Twitch nightbot quotes template

May 22nd, 2025 (edited)
201
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.04 KB | Source Code | 0 0
  1. /** Basic custom and searchable quotes command for Twitch nightbot. */
  2. /** Specific quotes can be called by either a number or word (eg. "!myQuote 1" or "!myQuote raid") or random (eg. "!myQuote") */  
  3. /** See author comments for instructions */
  4.  
  5. let response = '';
  6. {
  7.                                         /****** QUOTE COLLECTION ******/
  8.                                                                     /*** EXAMPLE: ["No.","Yes."] */
  9. const arr = [];
  10.  
  11.                                                                     /*** NOTE: Match to 'arr' but start with 0 not 1 */
  12.                                                                     /*** EXAMPLE: {no:0, yes:1} */
  13. const dict = {};
  14.  
  15.  
  16.                                          /****** SUPPORT FUNCTIONS ******/
  17.                                                                     /*** function responsePool: Reserve specific responses
  18.                                                                                                 to special keywords */
  19. let responsePool = (keyWord) =>{
  20.     let randQuote = -1; let quotes = []; let holder = true;
  21.  
  22.     switch(keyWord) {
  23.         case 'my_keyword_here':                                     /* <--- Change these values */
  24.         case 'another_keyword':                                     /* <--- stack multiple keywords*/
  25.             quotes = [0,1];                                         /* <---- Select your responses*/
  26.             randQuote = quotes[Math.floor(Math.random() * 2)];      /* <---- Update number count */
  27.             break;                                                  /* <---- Remember to break; to close block */
  28.         default:
  29.             holder = false;
  30.     }
  31.  
  32.                                                                     /*** NOTE: uncomment this block for punctuation functionality
  33.     if (!holder) {
  34.         switch(keyWord.slice(-1)) {
  35.         case '?':
  36.             quotes = [];
  37.             randQuote = quotes[Math.floor(Math.random() * 0)];
  38.         }
  39.     }
  40.                                                                     ***/
  41.     return randQuote;
  42. }
  43.  
  44.                                                                     /*** function buildResponse: Formats output for Twitch chat */
  45.                                                                     /*** NOTE: 'commands' lists the Dictionary keys */
  46. let buildResponse = (input) =>{
  47.     if (input == "commands") { return Object.keys(dict).join(" ").toString(); }
  48.     else {
  49.         isNaN(input)?line = arr[dict[input]] : line = arr[input];
  50.         return `/me '${line}' - John Smith`;                        /* <---- Nightbot: /me 'a quote' - John Smith */
  51.     }
  52. };
  53.  
  54.  
  55.                                          /****** MAIN FUNCTION ******/
  56.   var new_q = q;
  57.   let trim_q = new_q.trim().toLowerCase();
  58.  
  59.   /* is not empty */
  60.   if (trim_q !== ""){
  61.       var input = trim_q.slice(-1) == '?' ? trim_q.split(' ')[0] + trim_q.slice(-1) : trim_q.split(' ')[0];
  62.      
  63.       /* is string */
  64.       if (isNaN(input)){
  65.           /* ResponsePool */
  66.           const pool_response = responsePool(input);
  67.           if (pool_response > -1) { input = pool_response; }
  68.           /* invalid but not "commands" */
  69.           else if (dict[input] === undefined & input != "commands") { input = Math.floor(Math.random()*arr.length); }
  70.  
  71.       /* is int */
  72.       } else if (!isNaN(input)) {
  73.           /* out of range */
  74.           if (input >= arr.length | input < 0) { input = 0; }
  75.       }
  76.      
  77.       /* format output */
  78.       response = buildResponse(input);
  79.   }
  80.  
  81.   /* is empty */
  82.   else { response = buildResponse(Math.floor(Math.random()*arr.length)); }
  83. }
  84. /* Twitch output */
  85. response;
Advertisement
Comments
  • wroughtwheat
    16 days
    # text 0.40 KB | 0 0
    1. Copy and paste this template into a new pastebin
    2. Copy the RAW url ( https://pastebin.com/raw/whatever )
    3. Paste URL into line below:
    4. $(eval q = `$(query)`; $(urlfetch json PASTE_YOUR_RAW_URL_HERE ))
    5. Use Nightbot's add command
    6. !addcom !command_name $(eval q = `$(query)`; $(urlfetch json PASTE_YOUR_RAW_URL_HERE ))
    7.  
    8. ** For an example see my Arbiter quotes ( https://pastebin.com/hm3WWdj7 )
Add Comment
Please, Sign In to add comment
Advertisement