Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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", "categoryID", "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" style="width: 95%"><br>
  71. Category ID:<br>
  72. <input id= "categoryID" class="round" type="text" placeholder="Keep this empty if you don't want to put it into a category" style="width: 95%"><br>
  73. <div style="float: left; width: 50%;">
  74.     Topic:<br>
  75.     <input id="topic" class="round" type="text"><br>
  76. </div>
  77. <div style="float: right; width: 50%;">
  78.     Position:<br>
  79.     <input id="position" class="round" type="text" placeholder="Leave blank for default!" style="width: 90%;"><br>
  80. </div>
  81. <div>
  82.     <div style="float: left; width: 45%;">
  83.         Store In:<br>
  84.         <select id="storage" class="round" onchange="glob.variableChange(this, 'varNameContainer')">
  85.             ${data.variables[0]}
  86.         </select>
  87.     </div>
  88.     <div id="varNameContainer" style="display: none; float: right; width: 50%;">
  89.         Variable Name:<br>
  90.         <input id="varName" class="round" type="text" style="width: 90%"><br>
  91.     </div>
  92. </div>`
  93. },
  94.  
  95. //---------------------------------------------------------------------
  96. // Action Editor Init Code
  97. //
  98. // When the HTML is first applied to the action editor, this code
  99. // is also run. This helps add modifications or setup reactionary
  100. // functions for the DOM elements.
  101. //---------------------------------------------------------------------
  102.  
  103. init: function() {
  104.     const {glob, document} = this;
  105.  
  106.     glob.variableChange(document.getElementById('storage'), 'varNameContainer');
  107. },
  108.  
  109. //---------------------------------------------------------------------
  110. // Action Bot Function
  111. //
  112. // This is the function for the action within the Bot's Action class.
  113. // Keep in mind event calls won't have access to the "msg" parameter,
  114. // so be sure to provide checks for variable existance.
  115. //---------------------------------------------------------------------
  116.  
  117. action: function(cache) {
  118.     const data = cache.actions[cache.index];
  119.     const server = cache.server;
  120.     if(server && server.createChannel) {
  121.         const name = this.evalMessage(data.channelName, cache);
  122.         const catid = this.evalMessage(data.categoryID, cache);
  123.         const storage = parseInt(data.storage);
  124.         server.createChannel(name, 'text').then(function(channel) {
  125.             const channelData = {};
  126.             if(data.position) {
  127.                 channelData.position = parseInt(data.position);
  128.             }
  129.             if(data.topic) {
  130.                 channelData.topic = this.evalMessage(data.topic, cache);
  131.             }
  132.             channel.edit(channelData);
  133.             if(catid) {
  134.                 channel.setParent(catid);
  135.             }
  136.             const varName = this.evalMessage(data.varName, cache);
  137.             this.storeValue(channel, storage, varName, cache);
  138.             this.callNextAction(cache);
  139.         }.bind(this)).catch(this.displayError.bind(this, data, cache));
  140.     } else {
  141.         this.callNextAction(cache);
  142.     }
  143. },
  144.  
  145. //---------------------------------------------------------------------
  146. // Action Bot Mod
  147. //
  148. // Upon initialization of the bot, this code is run. Using the bot's
  149. // DBM namespace, one can add/modify existing functions if necessary.
  150. // In order to reduce conflictions between mods, be sure to alias
  151. // functions you wish to overwrite.
  152. //---------------------------------------------------------------------
  153.  
  154. mod: function(DBM) {
  155. }
  156.  
  157. }; // End of module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement