DryRoastedLemon

Simple Quotes Command for KoalaBot

Feb 15th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. /*
  2. Simple Quotes Command - By DryRoastedLemon
  3. Used to create quotes.
  4. Has the following options:
  5. - Required mod status
  6. - Timeout duration
  7. - Quote message
  8.  
  9. Quote format:
  10. [id]: [quote]
  11. Example: 7: "Poison on your face makes you dead!"
  12. */
  13.  
  14. var modQuote = (function()
  15. {
  16. // Replace the built-in quotes command
  17. for (var i = 0; i < cmdList.length; i++) {
  18. if (cmdList[i].cmd == "quote") {
  19. cmdList[i].func = "modQuote.quoteCmd";
  20. }
  21. }
  22.  
  23. // Create the methods to save the settings and the quotes
  24. var _saveSettings = function() {
  25. apiWriteFile(_settingsFileName, JSON.stringify(_quotesSettings));
  26. };
  27.  
  28. var _saveQuotes = function() {
  29. apiWriteFile(_quotesFileName, JSON.stringify(_quotes));
  30. };
  31.  
  32. // Loading existing settings
  33. var _settingsFileName = "quoteSettings.ini";
  34. var _quotesSettings = {
  35. requiresMod: true,
  36. timeOut: 10 * 1000,
  37. message: `Random quote:`
  38. };
  39. var _settingsFile = apiOpenFile( _settingsFileName );
  40. if ( !_settingsFile ) {
  41. _saveSettings();
  42. }
  43. else {
  44. _quotesSettings = $.parseJSON( _settingsFile );
  45. }
  46. var _timedOut = false;
  47.  
  48. // Loading existing quotes
  49. var _quotesFileName = "quotes.ini";
  50. var _quotes = [];
  51. var _quotesFile = apiOpenFile ( _quotesFileName );
  52. if ( !_quotesFile ) {
  53. _saveQuotes();
  54. }
  55. else {
  56. _quotes = $.parseJSON( _quotesFile );
  57. }
  58.  
  59. // Panels
  60. var _myTab = apiAddTab( "Simple Quotes" );
  61. $(_myTab).html(`
  62. <div class="row-fluid">
  63. <div class="col-sm-12">
  64. <div class="panel panel-default">
  65. <div class="panel-heading">
  66. <h2 class="panel-title">Simple Quotes Setting</h2>
  67. </div>
  68. <ul class="list-group">
  69. <li class="list-group-item">
  70. <strong>Requires moderator status:</strong>
  71. <button id="modQuotesEnableMod" class="btn btn-xs">Yes</button>
  72. <button id="modQuotesDisableMod" class="btn btn-xs">No</button>
  73. </li>
  74. <li class="list-group-item">
  75. <strong>Time-out Duration:</strong>
  76. <input id="modQuotesTimeoutInput" type="text" size="4"> seconds.
  77. </li>
  78. <li class="list-group-item">
  79. <p><strong>Message:</strong>
  80. <input id="modQuotesMessageInput" type="text" size="80">
  81. <p>You can use the following tags in your message:</p>
  82. <ul>
  83. <li>[id]</li>
  84. <li>[quote]</li>
  85. </ul>
  86. </li>
  87. <li class="list-group-item">
  88. <p><strong>Directions</strong></p>
  89. <p>Usage: !quote</p>
  90. </li>
  91. </ul>
  92. </div>
  93. </div>
  94. </div>
  95. `);
  96.  
  97. // Engaging the time-out
  98. var _timeOut = function(duration) {
  99. _timedOut = true;
  100. setTimeout( function() { _timedOut = false; }, duration );
  101. };
  102.  
  103. // Main function
  104. var _quoteCmd = function(params, from, mod, subscriber) {
  105. if (_timedOut) return;
  106.  
  107. if (params[0] == "add" && params[1] != null) {
  108. var message = "Quote saved: "
  109. var quote = "";
  110. for (var i = 1; i < params.length; i++) {
  111. quote = quote + params[i];
  112. if (i < params.length-1) quote = quote + " "; // Add a space unless it's the last word in the phrase.
  113. }
  114. _quotes.push(quote);
  115. _saveQuotes();
  116. apiSay(message + quote);
  117. } else {
  118. apiSay("Previously on the DryRoastedLemon Show: " + _quotes[Math.floor(Math.random() * _quotes.length)]);
  119. }
  120. _timeOut(_quotesSettings.timeOut);
  121. };
  122.  
  123. return {
  124. quoteCmd: _quoteCmd
  125. };
  126.  
  127. })();
Advertisement
Add Comment
Please, Sign In to add comment