Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.88 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: "Edit Channel",
  10. //Changed by Lasse in 1.8.7 from "Edit channel" to "Edit Channel"
  11.  
  12. //---------------------------------------------------------------------
  13. // Action Section
  14. //
  15. // This is the section the action will fall into.
  16. //---------------------------------------------------------------------
  17.  
  18. section: "Channel Control",
  19.  
  20. //---------------------------------------------------------------------
  21. // Action Subtitle
  22. //
  23. // This function generates the subtitle displayed next to the name.
  24. //---------------------------------------------------------------------
  25.  
  26. subtitle: function(data) {
  27. const names = ['Same Channel', 'Mentioned Channel', 'Default Channel', 'Temp Variable', 'Server Variable', 'Global Variable'];
  28. const opt = ['Name', 'Topic', 'Position', 'Bitrate', 'User Limit', 'Category ID', 'Rate Limit Per User'];
  29. return `${names[parseInt(data.storage)]} - ${opt[parseInt(data.toChange)]}`;
  30. },
  31.  
  32. //---------------------------------------------------------------------
  33. // DBM Mods Manager Variables (Optional but nice to have!)
  34. //
  35. // These are variables that DBM Mods Manager uses to show information
  36. // about the mods for people to see in the list.
  37. //---------------------------------------------------------------------
  38.  
  39. // Who made the mod (If not set, defaults to "DBM Mods")
  40. author: "Lasse, MrGold & NetLuis", // UI fixed by MrGold
  41.  
  42. // The version of the mod (Defaults to 1.0.0)
  43. version: "1.9.5", //Added in 1.8.2
  44.  
  45. // A short description to show on the mod line for this mod (Must be on a single line)
  46. short_description: "Edits a specific channel",
  47.  
  48. // If it depends on any other mods by name, ex: WrexMODS if the mod uses something from WrexMods
  49.  
  50.  
  51. //---------------------------------------------------------------------
  52.  
  53.  
  54. //---------------------------------------------------------------------
  55. // Action Fields
  56. //
  57. // These are the fields for the action. These fields are customized
  58. // by creating elements with corresponding IDs in the HTML. These
  59. // are also the names of the fields stored in the action's JSON data.
  60. //---------------------------------------------------------------------
  61.  
  62. fields: ["storage", "varName", "channelType", "toChange", "newState"],
  63.  
  64. //---------------------------------------------------------------------
  65. // Command HTML
  66. //
  67. // This function returns a string containing the HTML used for
  68. // editting actions.
  69. //
  70. // The "isEvent" parameter will be true if this action is being used
  71. // for an event. Due to their nature, events lack certain information,
  72. // so edit the HTML to reflect this.
  73. //
  74. // The "data" parameter stores constants for select elements to use.
  75. // Each is an array: index 0 for commands, index 1 for events.
  76. // The names are: sendTargets, members, roles, channels,
  77. // messages, servers, variables
  78. //---------------------------------------------------------------------
  79.  
  80. html: function(isEvent, data) {
  81. return `
  82. <div>
  83. <p>
  84. <u>Mod Info:</u><br>
  85. Created by Lasse, MrGold & NetLuis!
  86. </p>
  87. </div><br>
  88. <div>
  89. <div style="float: left; width: 35%;">
  90. Source Channel:<br>
  91. <select id="storage" class="round" onchange="glob.channelChange(this, 'varNameContainer')">
  92. ${data.channels[isEvent ? 1 : 0]}
  93. </select>
  94. </div>
  95. <div id="varNameContainer" style="display: none; float: right; width: 60%;">
  96. Variable Name:<br>
  97. <input id="varName" class="round" type="text" list="variableList"><br>
  98. </div>
  99. </div><br><br><br>
  100. <div>
  101. <div style="float: left; width: 35%;">
  102. Channel Type:<br>
  103. <select id="channelType" class="round">
  104. <option value="0" selected>Text Channel</option>
  105. <option value="1">Voice Channel</option>
  106. </select>
  107. </div><br><br><br>
  108. </div>
  109. <div>
  110. <div style="float: left; width: 35%;">
  111. Change:<br>
  112. <select id="toChange" class="round">
  113. <option value="0" selected>Name</option>
  114. <option value="1">Topic</option>
  115. <option value="2">Position</option>
  116. <option value="3">Bitrate</option>
  117. <option value="4">User Limit</option>
  118. <option value="5">Category ID</option>
  119. <option value="6">Rate Limit Per User</option>
  120. </select>
  121. </div><br><br><br>
  122. <div>
  123. <div style="float: left; width: 80%;">
  124. Change to:<br>
  125. <input id="newState" class="round" type="text"><br>
  126. </div>
  127. </div>`
  128. },
  129.  
  130. //---------------------------------------------------------------------
  131. // Action Editor Init Code
  132. //
  133. // When the HTML is first applied to the action editor, this code
  134. // is also run. This helps add modifications or setup reactionary
  135. // functions for the DOM elements.
  136. //---------------------------------------------------------------------
  137.  
  138. init: function() {
  139. const {glob, document} = this;
  140.  
  141. glob.channelChange(document.getElementById('storage'), 'varNameContainer');
  142. },
  143.  
  144. //---------------------------------------------------------------------
  145. // Action Bot Function
  146. //
  147. // This is the function for the action within the Bot's Action class.
  148. // Keep in mind event calls won't have access to the "msg" parameter,
  149. // so be sure to provide checks for variable existance.
  150. //---------------------------------------------------------------------
  151.  
  152. action: function(cache) {
  153. const data = cache.actions[cache.index];
  154. const storage = parseInt(data.storage);
  155. const varName = this.evalMessage(data.varName, cache);
  156. const channelType = parseInt(data.channelType);
  157. const newState = this.evalMessage(data.newState, cache);
  158. const toChange = parseInt(data.toChange, cache);
  159.  
  160. let channel;
  161. switch(channelType) {
  162. case 0:
  163. channel = this.getChannel(storage, varName, cache);
  164. break;
  165. case 1:
  166. channel = this.getVoiceChannel(storage, varName, cache);
  167. break;
  168. default:
  169. channel = this.getChannel(storage, varName, cache);
  170. break;
  171. }
  172.  
  173. if(toChange === 1) {
  174. channel.edit({topic: newState});
  175. } else if(toChange === 0) {
  176. channel.edit({name: newState});
  177. } else if(toChange === 2) {
  178. channel.edit({position: newState});
  179. } else if(toChange === 3) {
  180. channel.edit({bitrate: parseInt(newState)});
  181. } else if(toChange === 4) {
  182. channel.edit({userLimit: parseInt(newState)});
  183. } else if(toChange === 5) {
  184. channel.setParent(newState); // Added by Lasse in 1.8.7
  185. } else if(toChange === 6) {
  186. if(newState >= 0 && newState <= 120) {
  187.  
  188. new Promise((resolve, _reject) => {
  189. WrexMODS.require('snekfetch').patch('https://discordapp.com/api/channels/' + channel.id)
  190. .set('Authorization', `Bot ${this.getDBM().Files.data.settings.token}`)
  191. .send({rate_limit_per_user: newState})
  192. .catch();
  193. });
  194. // First Version by Lasse in 1.9 // Second Version by MrGold with help by NetLuis in 1.9.4
  195.  
  196. } else {
  197. console.log('Edit Channel ERROR: The value must be between 0 and 120')
  198. }
  199. } else {
  200. console.log('Please update your edit_channel_MOD.js in your projects action folder!');
  201. }
  202. this.callNextAction(cache);
  203. },
  204.  
  205. //---------------------------------------------------------------------
  206. // Action Bot Mod
  207. //
  208. // Upon initialization of the bot, this code is run. Using the bot's
  209. // DBM namespace, one can add/modify existing functions if necessary.
  210. // In order to reduce conflictions between mods, be sure to alias
  211. // functions you wish to overwrite.
  212. //---------------------------------------------------------------------
  213.  
  214. mod: function(DBM) {
  215. // aliases for backwards compatibility, in the bot only, DBM will still say the action is missing.
  216. DBM.Actions["Edit channel"] = DBM.Actions["Edit Channel"];
  217. //Thank You Wrex!
  218. }
  219.  
  220. }; // End of module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement