Advertisement
joelcedrascool

DBM - set role permissions mod.js

May 21st, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 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: "Set Role Permissions",
  10.  
  11. //---------------------------------------------------------------------
  12. // Action Section
  13. //
  14. // This is the section the action will fall into.
  15. //---------------------------------------------------------------------
  16.  
  17. section: "Role 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. const roles = ['Mentioned Role', '1st Author Role', '1st Server Role', 'Temp Variable', 'Server Variable', 'Global Variable'];
  27. const index = ['Yes', 'No']
  28. const perm = ['Administrator', 'Manage Guild', 'Manage Nicknames', 'Manage Roles', 'Manage Emojis', 'Kick Members', 'Ban Members', 'View Audit Log', 'Change Nickname', 'Create Instant Invite', 'Priority Speaker', 'Manage Channel', 'Manage Webhooks', 'Read Messages', 'Send Messages', 'Send TTS Messages', 'Manage Messages', 'Embed Links', 'Attach Files', 'Read Message History', 'Mention Everyone', 'Use External Emojis', 'Add Reactions', 'Connect to Voice', 'Speak in Voice', 'Mute Members', 'Deafen Members', 'Move Members', 'Use Voice Activity']
  29. return `${roles[data.role]} - ${perm[data.permission]} - ${index[data.state]}`;
  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: "MrGold & EliteArtz",
  41.  
  42. // The version of the mod (Defaults to 1.0.0)
  43. version: "1.9.1", //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: "Allows it to edit a roles permissions",
  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. // Action Fields
  55. //
  56. // These are the fields for the action. These fields are customized
  57. // by creating elements with corresponding IDs in the HTML. These
  58. // are also the names of the fields stored in the action's JSON data.
  59. //---------------------------------------------------------------------
  60.  
  61. fields: ["role", "varName", "permission", "state"],
  62.  
  63. //---------------------------------------------------------------------
  64. // Command HTML
  65. //
  66. // This function returns a string containing the HTML used for
  67. // editting actions.
  68. //
  69. // The "isEvent" parameter will be true if this action is being used
  70. // for an event. Due to their nature, events lack certain information,
  71. // so edit the HTML to reflect this.
  72. //
  73. // The "data" parameter stores constants for select elements to use.
  74. // Each is an array: index 0 for commands, index 1 for events.
  75. // The names are: sendTargets, members, roles,
  76. // messages, servers, variables
  77. //---------------------------------------------------------------------
  78.  
  79. html: function(isEvent, data) {
  80. return `
  81. <div>
  82. <p>
  83. <u>Mod Info:</u><br>
  84. Created by <b>MrGold</b> & <b>EliteArtz</b>!
  85. </p>
  86. </div><br>
  87. <div style="padding-top: 8px;">
  88. <div style="float: left; width: 35%;">
  89. Source Role:<br>
  90. <select id="role" name="second-list" class="round" onchange="glob.roleChange(this, 'varNameContainer')">
  91. ${data.roles[isEvent ? 1 : 0]}
  92. </select>
  93. </div>
  94. <div id="varNameContainer" style="display: none; float: right; width: 60%;">
  95. Variable Name:<br>
  96. <input id="varName" class="round" type="text" list="variableList"><br>
  97. </div>
  98. </div><br><br><br>
  99. <div style="padding-top: 8px;">
  100. <div style="float: left; width: 45%;">
  101. Permission:<br>
  102. <select id="permission" class="round">
  103. <option value="0" selected>Administrator</option>
  104. <option value="1">Manage Guild</option>
  105. <option value="2">Manage Nicknames</option>
  106. <option value="3">Manage Roles</option>
  107. <option value="4">Manage Emojis</option>
  108. <option value="5">Kick Members</option>
  109. <option value="6">Ban Members</option>
  110. <option value="7">View Audit Log</option>
  111. <option value="8">Change Nickname</option>
  112. <option value="9">Create Instant Invite</option>
  113. <option value="10">Priority Speaker</option>
  114. <option value="11">Manage Channel</option>
  115. <option value="12">Manage Webhooks</option>
  116. <option value="13">Read Messages</option>
  117. <option value="14">Send Messages</option>
  118. <option value="15">Send TTS Messages</option>
  119. <option value="16">Manage Messages</option>
  120. <option value="17">Embed Links</option>
  121. <option value="18">Attach Files</option>
  122. <option value="19">Read Message History</option>
  123. <option value="20">Mention Everyone</option>
  124. <option value="21">Use External Emojis</option>
  125. <option value="22">Add Reactions</option>
  126. <option value="23">Connect to Voice</option>
  127. <option value="24">Speak in Voice</option>
  128. <option value="25">Mute Members</option>
  129. <option value="26">Deafen Members</option>
  130. <option value="27">Move Members</option>
  131. <option value="28">Use Voice Activity</option>
  132. </select>
  133. </div>
  134. <div style="padding-left: 5%; float: left; width: 55%;">
  135. Change To:<br>
  136. <select id="state" class="round">
  137. <option value="0" selected>Yes</option>
  138. <option value="1">No</option>
  139. </select>
  140. </div>
  141. </div>`
  142. },
  143.  
  144. //---------------------------------------------------------------------
  145. // Action Editor Init Code
  146. //
  147. // When the HTML is first applied to the action editor, this code
  148. // is also run. This helps add modifications or setup reactionary
  149. // functions for the DOM elements.
  150. //---------------------------------------------------------------------
  151.  
  152. init: function() {
  153. const {glob, document} = this;
  154.  
  155. glob.roleChange(document.getElementById('role'), 'varNameContainer')
  156. },
  157.  
  158. //---------------------------------------------------------------------
  159. // Action Bot Function
  160. //
  161. // This is the function for the action within the Bot's Action class.
  162. // Keep in mind event calls won't have access to the "msg" parameter,
  163. // so be sure to provide checks for variable existance.
  164. //---------------------------------------------------------------------
  165.  
  166. action: function(cache) {
  167. const data = cache.actions[cache.index];
  168. const storage = parseInt(data.role);
  169. const varName = this.evalMessage(data.varName, cache);
  170. const role = this.getRole(storage, varName, cache);
  171. const info = parseInt(data.permission);
  172.  
  173. let result;
  174. switch(info) {
  175. case 0:
  176. result = 8;
  177. break;
  178. case 1:
  179. result = 32;
  180. break;
  181. case 2:
  182. result = 134217728;
  183. break;
  184. case 3:
  185. result = 268435456;
  186. break;
  187. case 4:
  188. result = 1073741824;
  189. break;
  190. case 5:
  191. result = 2;
  192. break;
  193. case 6:
  194. result = 4;
  195. break;
  196. case 7:
  197. result = 128;
  198. break;
  199. case 8:
  200. result = 67108864;
  201. break;
  202. case 9:
  203. result = 1;
  204. break;
  205. case 10:
  206. result = 256;
  207. break;
  208. case 11:
  209. result = 16;
  210. break;
  211. case 12:
  212. result = 536870912;
  213. break;
  214. case 13:
  215. result = 1024;
  216. break;
  217. case 14:
  218. result = 2048;
  219. break;
  220. case 15:
  221. result = 4096;
  222. break;
  223. case 16:
  224. result = 8192;
  225. break;
  226. case 17:
  227. result = 16384;
  228. break;
  229. case 18:
  230. result = 32768;
  231. break;
  232. case 19:
  233. result = 65536;
  234. break;
  235. case 20:
  236. result = 131072;
  237. break;
  238. case 21:
  239. result = 262144;
  240. break;
  241. case 22:
  242. result = 64;
  243. break;
  244. case 23:
  245. result = 1048576;
  246. break;
  247. case 24:
  248. result = 2097152;
  249. break;
  250. case 25:
  251. result = 4194304;
  252. break;
  253. case 26:
  254. result = 8388608;
  255. break;
  256. case 27:
  257. result = 16777216;
  258. break;
  259. case 28:
  260. result = 33554432;
  261. break;
  262. default:
  263. break;
  264. }
  265.  
  266. const options = {};
  267. options[data.permission] = data.state === "0" ? true : (data.state === "1" ? false : null);
  268. if(role && role.id) {
  269. if(Array.isArray(role)) {
  270. this.callListFunc(role, 'setPermissions', [role.id, options]).then(function() {
  271. this.callNextAction(cache);
  272. }.bind(this));
  273. } else if(role && role.setPermissions) {
  274. } if(data.state === "0") {
  275. const perms = role.permissions
  276. role.setPermissions([perms, result]).then(function() {
  277. this.callNextAction(cache);
  278. }.bind(this)).catch(this.displayError.bind(this, data, cache));
  279. } else if(data.state === "1") {
  280. const perms2 = role.permissions - result
  281. role.setPermissions([perms2]).then(function() {
  282. this.callNextAction(cache);
  283. }.bind(this)).catch(this.displayError.bind(this, data, cache));
  284. } else {
  285. this.callNextAction(cache);
  286. }
  287. } else {
  288. this.callNextAction(cache);
  289. }
  290. },
  291.  
  292. //---------------------------------------------------------------------
  293. // Action Bot Mod
  294. //
  295. // Upon initialization of the bot, this code is run. Using the bot's
  296. // DBM namespace, one can add/modify existing functions if necessary.
  297. // In order to reduce conflictions between mods, be sure to alias
  298. // functions you wish to overwrite.
  299. //---------------------------------------------------------------------
  300.  
  301. mod: function(DBM) {
  302. }
  303.  
  304. }; // End of module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement