Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Let's Raid Command
- By DryRoastedLemon
- Usage: !letsraid [twitch username]
- Can be used to quickly and easily set your viewers up for raiding a fellow streamer.
- Automatically creates the link and gives your viewers your raiding message, which can
- be customized from within KoalaBot.
- Note: The module was written in a very modular fashion, mostly so that I can easily take
- the HTML interface as create more mods without having to go through every single interface
- element. Also, it prevents typing errors and makes working with long id's a little easier.
- */
- var modLetsRaid = (function() {
- // -------------------- BASIC SETUP --------------------
- // Module information
- var _moduleName = "Lets Raid Command";
- var _moduleSName = "LetsRaid";
- var _timedOut = false;
- // Save function
- var _settingsFilename = "letsRaid.ini";
- var _saveSettings = function()
- {
- apiWriteFile(_settingsFilename, JSON.stringify(_settings));
- };
- // Time-out function
- var _timeOut = function(duration) {
- _timedOut = true;
- setTimeout( function() { _timedOut = false; }, duration )
- };
- // Load / Create settings
- var _settings = apiOpenFile(_settingsFilename);
- if (!_settings) { // If the file doesn't exist create a new save file with the following default values
- _settings = {
- _modRequired: true,
- _timeOutDuration: 10 * 1000,
- _message: "It's a standard issue raid! twitchRaid"
- };
- _saveSettings();
- } else {
- _settings = $.parseJSON(_settings);
- }
- // Add Command
- if (_settings._modRequired) {
- _addCommand("letsraid", "modLetsRaid.letsRaidCmd", "mod");
- } else {
- _addCommand("letsraid", "modLetsRaid.letsRaidCmd", "all");
- }
- // -------------------- PANEL SETUP --------------------
- // Configure panel
- _setupPanel();
- // -------------------- MAIN COMMAND SETUP --------------------
- // !letsraid command
- var _letsRaidCmd = function(params, from)
- {
- // If mod status is required and the user isn't a mod (or the caster) return.
- // Also return if the function's on time-out.
- //if ((!mod && _settings._modRequired) || _timedOut) return;
- if (_timedOut) return;
- if (params[0])
- {
- var _streamer = params[0];
- apiSay("Today we're gonna raid " + _streamer + "!");
- apiSay("Go visit their channel and wait for me to say the message.");
- apiSay("Link: http://twitch.tv/" + _streamer.toLowerCase());
- apiSay("Message: " + _settings._message);
- apiSay("Have fun!");
- _timeOut(_settings._timeOutDuration);
- } else {
- apiSay("Usage: !letsraid [twitch username]");
- }
- };
- return {
- letsRaidCmd: _letsRaidCmd
- };
- // -------------------- Panel configuration function --------------------
- // Declared in this way so it's created at parse-time.
- function _setupPanel() {
- var _myTab = apiAddTab(_moduleName);
- $(_myTab).html(`
- <div class="row-fluid">
- <div class="col-sm-12">
- <div class="panel panel-default">
- <div class="panel-heading">
- <h2 class="panel-title">${_moduleName}</h2>
- </div>
- <ul class="list-group">
- <li class="list-group-item">
- <strong>Requires moderator status:</strong>
- <button id="mod${_moduleSName}EnableMod" class="btn btn-xs">Yes</button>
- <button id="mod${_moduleSName}DisableMod" class="btn btn-xs">No</button>
- </li>
- <li class="list-group-item">
- <strong>Time-out Duration:</strong>
- <input id="mod${_moduleSName}TimeoutInput" type="text" size="4"> seconds.
- </li>
- <li class="list-group-item">
- <p><strong>Raid Message:</strong>
- <input id="mod${_moduleSName}MessageInput" type="text" size="80"></p>
- </li>
- <li class="list-group-item">
- <p><strong>Directions</strong></p>
- <p>Usage: !letsraid [twitch username]</p>
- </li>
- </ul>
- </div>
- </div>
- </div>
- `);
- // Mod status - Setting the initial values
- if (_settings._modRequired) {
- $( "#mod" + _moduleSName + "EnableMod" ).addClass("btn-info");
- $( "#mod" + _moduleSName + "DisableMod" ).addClass("btn-danger");
- } else {
- $( "#mod" + _moduleSName + "EnableMod" ).addClass("btn-danger");
- $( "#mod" + _moduleSName + "DisableMod" ).addClass("btn-info");
- }
- // Change and save the mod status requirement when clicking on the buttons
- $( "#mod" + _moduleSName + "EnableMod" ).click(function(){
- $( "#mod" + _moduleSName + "EnableMod" ).addClass("btn-info").removeClass("btn-danger");
- $( "#mod" + _moduleSName + "DisableMod" ).addClass("btn-danger").removeClass("btn-info");
- _settings._modRequired = true;
- _addCommand("letsraid", "modLetsRaid.letsRaidCmd", "mod");
- _saveSettings();
- });
- $( "#mod" + _moduleSName + "DisableMod" ).click(function() {
- $( "#mod" + _moduleSName + "EnableMod" ).addClass("btn-danger").removeClass("btn-info");
- $( "#mod" + _moduleSName + "DisableMod" ).addClass("btn-info").removeClass("btn-danger");
- _settings._modRequired = false;
- _addCommand("letsraid", "modLetsRaid.letsRaidCmd", "all");
- _saveSettings();
- });
- // Time-out - Load the initial value
- $( "#mod" + _moduleSName + "TimeoutInput" ).val(_settings._timeOutDuration / 1000);
- // Change and save the time-out duration
- $( "#mod" + _moduleSName + "TimeoutInput" ).change(function() {
- var temp = $( "#mod" + _moduleSName + "TimeoutInput" ).val();
- if (Math.floor(temp) == temp && $.isNumeric(temp) && temp >= 0) {
- _settings._timeOutDuration = temp * 1000;
- _saveSettings();
- } else {
- $( "#mod" + _moduleSName + "TimeoutInput" ).val(_settings._timeOutDuration);
- alert("Please enter a positive integer (e.g.: 1, 2, 3).");
- }
- });
- // Message - Load the initial value
- $( "#mod" + _moduleSName + "MessageInput" ).val(_settings._message);
- $( "#mod" + _moduleSName + "MessageInput" ).change(function() {
- _settings._message = $( "#mod" + _moduleSName + "MessageInput" ).val();
- _saveSettings();
- });
- }
- // -------------------- Updating the command --------------------
- // Declared in this way so it's created at parse-time.
- function _addCommand(cmd, functionName, accesslevel) {
- var description = "Raids 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