Advertisement
joelcedrascool

DBM mod - webhook creator

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