Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Simple Quotes Command - By DryRoastedLemon
- Used to create quotes.
- Has the following options:
- - Required mod status
- - Timeout duration
- - Quote message
- Quote format:
- [id]: [quote]
- Example: 7: "Poison on your face makes you dead!"
- */
- var modQuote = (function()
- {
- // Replace the built-in quotes command
- for (var i = 0; i < cmdList.length; i++) {
- if (cmdList[i].cmd == "quote") {
- cmdList[i].func = "modQuote.quoteCmd";
- }
- }
- // Create the methods to save the settings and the quotes
- var _saveSettings = function() {
- apiWriteFile(_settingsFileName, JSON.stringify(_quotesSettings));
- };
- var _saveQuotes = function() {
- apiWriteFile(_quotesFileName, JSON.stringify(_quotes));
- };
- // Loading existing settings
- var _settingsFileName = "quoteSettings.ini";
- var _quotesSettings = {
- requiresMod: true,
- timeOut: 10 * 1000,
- message: `Random quote:`
- };
- var _settingsFile = apiOpenFile( _settingsFileName );
- if ( !_settingsFile ) {
- _saveSettings();
- }
- else {
- _quotesSettings = $.parseJSON( _settingsFile );
- }
- var _timedOut = false;
- // Loading existing quotes
- var _quotesFileName = "quotes.ini";
- var _quotes = [];
- var _quotesFile = apiOpenFile ( _quotesFileName );
- if ( !_quotesFile ) {
- _saveQuotes();
- }
- else {
- _quotes = $.parseJSON( _quotesFile );
- }
- // Panels
- var _myTab = apiAddTab( "Simple Quotes" );
- $(_myTab).html(`
- <div class="row-fluid">
- <div class="col-sm-12">
- <div class="panel panel-default">
- <div class="panel-heading">
- <h2 class="panel-title">Simple Quotes Setting</h2>
- </div>
- <ul class="list-group">
- <li class="list-group-item">
- <strong>Requires moderator status:</strong>
- <button id="modQuotesEnableMod" class="btn btn-xs">Yes</button>
- <button id="modQuotesDisableMod" class="btn btn-xs">No</button>
- </li>
- <li class="list-group-item">
- <strong>Time-out Duration:</strong>
- <input id="modQuotesTimeoutInput" type="text" size="4"> seconds.
- </li>
- <li class="list-group-item">
- <p><strong>Message:</strong>
- <input id="modQuotesMessageInput" type="text" size="80">
- <p>You can use the following tags in your message:</p>
- <ul>
- <li>[id]</li>
- <li>[quote]</li>
- </ul>
- </li>
- <li class="list-group-item">
- <p><strong>Directions</strong></p>
- <p>Usage: !quote</p>
- </li>
- </ul>
- </div>
- </div>
- </div>
- `);
- // Engaging the time-out
- var _timeOut = function(duration) {
- _timedOut = true;
- setTimeout( function() { _timedOut = false; }, duration );
- };
- // Main function
- var _quoteCmd = function(params, from, mod, subscriber) {
- if (_timedOut) return;
- if (params[0] == "add" && params[1] != null) {
- var message = "Quote saved: "
- var quote = "";
- for (var i = 1; i < params.length; i++) {
- quote = quote + params[i];
- if (i < params.length-1) quote = quote + " "; // Add a space unless it's the last word in the phrase.
- }
- _quotes.push(quote);
- _saveQuotes();
- apiSay(message + quote);
- } else {
- apiSay("Previously on the DryRoastedLemon Show: " + _quotes[Math.floor(Math.random() * _quotes.length)]);
- }
- _timeOut(_quotesSettings.timeOut);
- };
- return {
- quoteCmd: _quoteCmd
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment