Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Caster Command - By DryRoastedLemon
- Used to call out a streamer and show what game he/she last played.
- Can be configured via the panel. You can change the following:
- - Whether mod status is needed or not
- - The timeout duration
- - The message that's sent
- */
- var modCaster = (function() {
- // Saving the settings
- var _saveSettings = function() {
- apiWriteFile( _settingsFileName, JSON.stringify(_casterSettings) );
- };
- // Private variables
- var _myTab = apiAddTab( "Caster Command" );
- var _casterSettings = {
- requiresMod: true,
- timeOut: 10 * 1000,
- message: `Check out [caster]'s stream over at [link] and drop them a follow! [caster] last played [game]`
- };
- var _settingsFileName = "modCasterSettings.ini";
- var _timedOut = false;
- // Load settings
- var _settingsFile = apiOpenFile( _settingsFileName );
- if ( !_settingsFile) { // If the file doesn't exist save settings
- _saveSettings();
- } else {
- _casterSettings = $.parseJSON( _settingsFile ); // If the file exists load the settings
- }
- // Add the !caster command
- if (_casterSettings.requiresMod) {
- _addCommand( "caster", "modCaster.casterCmd", "mod");
- } else {
- _addCommand( "caster", "modCaster.casterCmd", "all");
- }
- // Module tab
- $(_myTab).html(`
- <div class="row-fluid">
- <div class="col-sm-12">
- <div class="panel panel-default">
- <div class="panel-heading">
- <h2 class="panel-title">Caster Command options</h2>
- </div>
- <ul class="list-group">
- <li class="list-group-item">
- <strong>Requires moderator status:</strong>
- <button id="modCasterEnableMod" class="btn btn-xs">Yes</button>
- <button id="modCasterDisableMod" class="btn btn-xs">No</button>
- </li>
- <li class="list-group-item">
- <strong>Time-out Duration:</strong>
- <input id="modCasterTimeoutInput" type="text" size="4"> seconds.
- </li>
- <li class="list-group-item">
- <p><strong>Message:</strong>
- <input id="modCasterMessageInput" type="text" size="80">
- <p>You can use the following tags in your message:</p>
- <ul>
- <li>[caster] - The caster's username.</li>
- <li>[link] - The link to the caster's Twitch channel.</li>
- <li>[game] - The caster's last played game.</li>
- </ul>
- </li>
- <li class="list-group-item">
- <p><strong>Directions</strong></p>
- <p>Usage: !caster [twitch username]</p>
- </li>
- </ul>
- </div>
- </div>
- </div>`);
- // Initial panel settings
- // Mod button colors
- if (_casterSettings.requiresMod) {
- $("#modCasterEnableMod")
- .addClass("btn-info");
- $("#modCasterDisableMod")
- .addClass("btn-danger");
- } else {
- $("#modCasterEnableMod")
- .addClass("btn-danger");
- $("#modCasterDisableMod")
- .addClass("btn-info");
- }
- // Time-out duration
- $( "#modCasterTimeoutInput" ).val(_casterSettings.timeOut / 1000);
- $( "#modCasterMessageInput" ).val(_casterSettings.message);
- // Message
- $( "#modCasterMessageInput" ).val(_casterSettings.message);
- // Settings are automatically saved as you change any settings
- // Mod requirement settings
- $( "#modCasterEnableMod" ).click(function() {
- $( "#modCasterEnableMod" ).removeClass( "btn-danger" ).addClass( "btn-info" );
- $( "#modCasterDisableMod" ).removeClass( "btn-info" ).addClass("btn-danger");
- _casterSettings.requiresMod = true;
- _addCommand( "caster", "modCaster.casterCmd", "mod");
- _saveSettings();
- });
- $( "#modCasterDisableMod" ).click(function() {
- $( "#modCasterEnableMod" ).removeClass( "btn-info" ).addClass( "btn-danger" );
- $( "#modCasterDisableMod" ).removeClass( "btn-danger" ).addClass("btn-info");
- _casterSettings.requiresMod = false;
- _addCommand( "caster", "modCaster.casterCmd", "all");
- _saveSettings();
- });
- // Time-out duration
- $( "#modCasterTimeoutInput" ).change(function() {
- var temp = $( "#modCasterTimeoutInput" ).val();
- if (Math.floor(temp) == temp && $.isNumeric(temp) && temp >= 0) {
- _casterSettings.timeOut = temp * 1000;
- _saveSettings();
- } else {
- $( "#modCasterTimeoutInput" ).val(_casterSettings.timeOut);
- alert("Please enter a positive integer (e.g.: 1, 2, 3).");
- }
- });
- // Message
- $( "#modCasterMessageInput" ).change(function() {
- _casterSettings.message = $( "#modCasterMessageInput" ).val();
- _saveSettings();
- });
- // Engaging the time-out
- var _timeOut = function(duration) {
- _timedOut = true;
- setTimeout( function() { _timedOut = false; }, duration );
- };
- // The !caster Command
- var _casterCmd = function(params, from) {
- // Check for mod requirement and mod status
- //if (_casterSettings.requiresMod && (!mod || from.toLowerCase() != apiGetChannelName())) return;
- if (!params[0]) {
- return apiSay( "Usage: !caster [castername]" );
- } else {
- if( _timedOut ) return;
- var caster = params[0];
- $.get(
- "https://api.rtainc.co/twitch/game",
- { "channel": caster },
- function( data ){
- if ( data.includes( "<br />" )) return apiSay( "Couldn't find any results!" ); // I don't know how to properly check for errors, but this works for the time being.
- else {
- // Replace the [caster], [link] and [game] tags with actual data.
- // The code's ugly, but I had to escape the brackets.
- var message = _casterSettings.message;
- message = message.replace( /\[caster\]/g, caster );
- message = message.replace( /\[link\]/g, "http://twitch.tv/" + caster.toLowerCase() );
- message = message.replace( /\[game\]/g, data );
- apiSay( message );
- _timeOut(_casterSettings.timeOut);
- }
- });
- }
- };
- return {
- casterCmd: _casterCmd
- };
- // -------------------- Updating the command --------------------
- // Declared in this way so it's created at parse-time.
- function _addCommand(cmd, functionName, accesslevel) {
- var description = "Gives a shoutout to other streamers.";
- // Remove the command if it exists
- for (var i = 0; i < cmdList.length; i++) {
- if (cmdList[i].cmd == cmd) {
- cmdList.splice(i, 1);
- }
- }
- // Add the command with the correct accesslevel
- apiAddCmd(cmd, functionName, accesslevel, description);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement