Repository navigation
Custom Script FeatureCheck
Perry edited this page Apr 17, 2018
·
1 revision
This is a Custom Featured Checker Script for Firebot. Simply save this text to a file and name it featured-checker.js.
Place that file into Firebots script folder and add the script to any button or command with the Custom Script effect:
exports.getDefaultParameters = function() { return new Promise((resolve, reject) => { resolve({ chatter: { type: "enum", options: ["Streamer", "Bot"], default: "Bot", description: "Send From", secondaryDescription: "Which account to send the messages from." }, featuredMessageTemplate: { type: "string", description: "Featured message template", secondaryDescription: "The featured message to show in chat. Here are some variables you can use in this message: ${streamer}", default: "${streamer} is featured right now." }, notFeaturedMessageTemplate: { type: "string", description: "Not featured message template", secondaryDescription: "The not featured message to show in chat. Here are some variables you can use in this message: ${streamer}", default: "${streamer} is not featured right now." } }); }); } exports.getScriptManifest = function() { return { name: "Featured Check", description: "Allows you to check if a given channel is featured or not.", author: "ThePerry", version: "0.1" } } function run(runRequest) { var username = runRequest.user.name; var shouldWhisper = runRequest.parameters.shouldWhisper; const fs = runRequest.modules.fs; const authFile = JSON.parse(fs.readFileSync(SCRIPTS_DIR + "../auth.json", 'utf8')); const channelId = authFile.streamer.channelId; const streamerName = authFile.streamer.username; const request = runRequest.modules.request; // Return a Promise object return new Promise((resolve, reject) => { var url = "https://mixer.com/api/v1/channels/"+ channelId +"?fields=featured"; let featuredMsgTemplate = runRequest.parameters.featuredMessageTemplate; let featuredNotMsgTemplate = runRequest.parameters.notFeaturedMessageTemplate; request(url, function (error, response, data) { var response = {}; if (!error) { // Got response from Mixer. var data = JSON.parse(data); let message; if (data.featured == true) { message = featuredMsgTemplate.replace("${streamer}", streamerName); }else{ message = featuredNotMsgTemplate.replace("${streamer}", streamerName); } // Create a success response response = { success: true, effects:[ { type: EffectType.CHAT, message: message, chatter: runRequest.parameters.chatter } ] } } else { // We had an error with the mixer request. So, create an error popup in Firebot. // Create a failed response response = { success: false, errorMessage: 'There was an error retrieving data from the Mixer API.' } } // Resolve Promise with the response object resolve(response); }) }); } // Export 'run' function so it is visible to Node exports.run = run;
Still need help? Come chat with us in the #help channel of our Discord server.