Advertisement
Guest User

tox

a guest
Jan 22nd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. module.exports = {
  2.  
  3. //---------------------------------------------------------------------
  4. // Action Name
  5. //
  6. // This is the name of the action displayed in the editor.
  7. //---------------------------------------------------------------------
  8.  
  9. name: "Create Text Channel",
  10.  
  11. //---------------------------------------------------------------------
  12. // Action Section
  13. //
  14. // This is the section the action will fall into.
  15. //---------------------------------------------------------------------
  16.  
  17. section: "Channel Control",
  18.  
  19. //---------------------------------------------------------------------
  20. // Action Subtitle
  21. //
  22. // This function generates the subtitle displayed next to the name.
  23. //---------------------------------------------------------------------
  24.  
  25. subtitle: function(data) {
  26. return `${data.channelName}`;
  27. },
  28.  
  29. //---------------------------------------------------------------------
  30. // Action Storage Function
  31. //
  32. // Stores the relevant variable info for the editor.
  33. //---------------------------------------------------------------------
  34.  
  35. variableStorage: function(data, varType) {
  36. const type = parseInt(data.storage);
  37. if(type !== varType) return;
  38. return ([data.varName, 'Channel']);
  39. },
  40.  
  41. //---------------------------------------------------------------------
  42. // Action Fields
  43. //
  44. // These are the fields for the action. These fields are customized
  45. // by creating elements with corresponding IDs in the HTML. These
  46. // are also the names of the fields stored in the action's JSON data.
  47. //---------------------------------------------------------------------
  48.  
  49. fields: ["channelName", "topic", "position", "storage", "varName"],
  50.  
  51. //---------------------------------------------------------------------
  52. // Command HTML
  53. //
  54. // This function returns a string containing the HTML used for
  55. // editting actions.
  56. //
  57. // The "isEvent" parameter will be true if this action is being used
  58. // for an event. Due to their nature, events lack certain information,
  59. // so edit the HTML to reflect this.
  60. //
  61. // The "data" parameter stores constants for select elements to use.
  62. // Each is an array: index 0 for commands, index 1 for events.
  63. // The names are: sendTargets, members, roles, channels,
  64. // messages, servers, variables
  65. //---------------------------------------------------------------------
  66.  
  67. html: function(isEvent, data) {
  68. return `
  69. Name:<br>
  70. <input id="channelName" class="round" type="text"><br>
  71. <div style="float: left; width: 50%;">
  72. Topic:<br>
  73. <input id="topic" class="round" type="text"><br>
  74. </div>
  75. <div style="float: right; width: 50%;">
  76. Position:<br>
  77. <input id="position" class="round" type="text" placeholder="Leave blank for default!" style="width: 90%;"><br>
  78. </div>
  79. <div>
  80. <div style="float: left; width: 35%;">
  81. Store In:<br>
  82. <select id="storage" class="round" onchange="glob.variableChange(this, 'varNameContainer')">
  83. ${data.variables[0]}
  84. </select>
  85. </div>
  86. <div id="varNameContainer" style="display: none; float: right; width: 60%;">
  87. Variable Name:<br>
  88. <input id="varName" class="round" type="text"><br>
  89. </div>
  90. </div>`
  91. },
  92.  
  93. //---------------------------------------------------------------------
  94. // Action Editor Init Code
  95. //
  96. // When the HTML is first applied to the action editor, this code
  97. // is also run. This helps add modifications or setup reactionary
  98. // functions for the DOM elements.
  99. //---------------------------------------------------------------------
  100.  
  101. init: function() {
  102. const {glob, document} = this;
  103.  
  104. glob.variableChange(document.getElementById('storage'), 'varNameContainer');
  105. },
  106.  
  107. //---------------------------------------------------------------------
  108. // Action Bot Function
  109. //
  110. // This is the function for the action within the Bot's Action class.
  111. // Keep in mind event calls won't have access to the "msg" parameter,
  112. // so be sure to provide checks for variable existance.
  113. //---------------------------------------------------------------------
  114.  
  115. action: function(cache) {
  116. const data = cache.actions[cache.index];
  117. const server = cache.server;
  118. if(server && server.createChannel) {
  119. const name = this.evalMessage(data.channelName, cache);
  120. const storage = parseInt(data.storage);
  121. server.createChannel(name, 'text').then(function(channel) {
  122. const channelData = {};
  123. if(data.position) {
  124. channelData.position = parseInt(data.position);
  125. }
  126. if(data.topic) {
  127. channelData.topic = this.evalMessage(data.topic, cache);
  128. }
  129. channel.edit(channelData);
  130. const varName = this.evalMessage(data.varName, cache);
  131. this.storeValue(channel, storage, varName, cache);
  132. this.callNextAction(cache);
  133. }.bind(this)).catch(this.displayError.bind(this, data, cache));
  134. } else {
  135. this.callNextAction(cache);
  136. }
  137. },
  138.  
  139. //---------------------------------------------------------------------
  140. // Action Bot Mod
  141. //
  142. // Upon initialization of the bot, this code is run. Using the bot's
  143. // DBM namespace, one can add/modify existing functions if necessary.
  144. // In order to reduce conflictions between mods, be sure to alias
  145. // functions you wish to overwrite.
  146. //---------------------------------------------------------------------
  147.  
  148. mod: function(DBM) {
  149. }
  150.  
  151. }; // End of module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement