Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.81 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: "Play YouTube Video",
  10.  
  11. //---------------------------------------------------------------------
  12. // Action Section
  13. //
  14. // This is the section the action will fall into.
  15. //---------------------------------------------------------------------
  16.  
  17. section: "Audio Control",
  18.  
  19. //---------------------------------------------------------------------
  20. // Requires Audio Libraries
  21. //
  22. // If 'true', this action requires audio libraries to run.
  23. //---------------------------------------------------------------------
  24.  
  25. requiresAudioLibraries: true,
  26.  
  27. //---------------------------------------------------------------------
  28. // Action Subtitle
  29. //
  30. // This function generates the subtitle displayed next to the name.
  31. //---------------------------------------------------------------------
  32.  
  33. subtitle: function (data) {
  34. return `${data.url}`;
  35. },
  36.  
  37. //---------------------------------------------------------------------
  38. // DBM Mods Manager Variables (Optional but nice to have!)
  39. //
  40. // These are variables that DBM Mods Manager uses to show information
  41. // about the mods for people to see in the list.
  42. //---------------------------------------------------------------------
  43.  
  44. // Who made the mod (If not set, defaults to "DBM Mods")
  45. author: "DBM, TheMonDon, others?",
  46.  
  47. // The version of the mod (Defaults to 1.0.0)
  48. version: "1.9.6",
  49. version2: "1.0.2", // Just to keep track of this version compared to mod pack version
  50.  
  51. // A short description to show on the mod line for this mod (Must be on a single line)
  52. short_description: "Gets extra video information on YouTube based on video ID.",
  53.  
  54. // If it depends on any other mods by name, ex: WrexMODS if the mod uses something from WrexMods
  55.  
  56. //---------------------------------------------------------------------
  57.  
  58. //---------------------------------------------------------------------
  59. // Action Fields
  60. //
  61. // These are the fields for the action. These fields are customized
  62. // by creating elements with corresponding IDs in the HTML. These
  63. // are also the names of the fields stored in the action's JSON data.
  64. //---------------------------------------------------------------------
  65.  
  66. fields: ["url", "seek", "volume", "passes", "bitrate", "type"],
  67.  
  68. //---------------------------------------------------------------------
  69. // Command HTML
  70. //
  71. // This function returns a string containing the HTML used for
  72. // editting actions.
  73. //
  74. // The "isEvent" parameter will be true if this action is being used
  75. // for an event. Due to their nature, events lack certain information,
  76. // so edit the HTML to reflect this.
  77. //
  78. // The "data" parameter stores constants for select elements to use.
  79. // Each is an array: index 0 for commands, index 1 for events.
  80. // The names are: sendTargets, members, roles, channels,
  81. // messages, servers, variables
  82. //---------------------------------------------------------------------
  83.  
  84. html: function (isEvent, data) {
  85. return `
  86. <div>
  87. <p>This action has been modified by DBM Mods.</p>
  88. </div>
  89. <div>
  90. YouTube URL:<br>
  91. <input id="url" class="round" type="text" value="https://www.youtube.com/watch?v=2zgcFFvEA9g"><br>
  92. </div>
  93. <div style="float: left; width: 50%;">
  94. Seek Position:<br>
  95. <input id="seek" class="round" type="text" value="0"><br>
  96. Passes:<br>
  97. <input id="passes" class="round" type="text" value="1">
  98. </div>
  99. <div style="float: right; width: 50%;">
  100. Volume (0 = min; 100 = max):<br>
  101. <input id="volume" class="round" type="text" placeholder="Leave blank for automatic..."><br>
  102. Bitrate:<br>
  103. <input id="bitrate" class="round" type="text" placeholder="Leave blank for automatic...">
  104. </div><br><br><br><br><br><br><br>
  105. <div>
  106. Play Type:<br>
  107. <select id="type" class="round" style="width: 90%;">
  108. <option value="0" selected>Add to Queue</option>
  109. <option value="1">Play Immediately</option>
  110. </select>
  111. </div>`;
  112. },
  113.  
  114. //---------------------------------------------------------------------
  115. // Action Editor Init Code
  116. //
  117. // When the HTML is first applied to the action editor, this code
  118. // is also run. This helps add modifications or setup reactionary
  119. // functions for the DOM elements.
  120. //---------------------------------------------------------------------
  121.  
  122. init: function () {},
  123.  
  124. //---------------------------------------------------------------------
  125. // Action Bot Function
  126. //
  127. // This is the function for the action within the Bot's Action class.
  128. // Keep in mind event calls won't have access to the "msg" parameter,
  129. // so be sure to provide checks for variable existance.
  130. //---------------------------------------------------------------------
  131.  
  132. action: async function (cache) {
  133. const data = cache.actions[cache.index];
  134. const Audio = this.getDBM()
  135. .Audio;
  136. const WrexMods = this.getWrexMods();
  137. const ytdl = WrexMods.require('ytdl-core');
  138. const getInfoAsync = WrexMods.require('util')
  139. .promisify(ytdl.getInfo);
  140. const url = this.evalMessage(data.url, cache);
  141. const msg = cache.msg;
  142. const options = {};
  143.  
  144. if (url) {
  145.  
  146. if (data.seek) {
  147. options.seek = parseInt(this.evalMessage(data.seek, cache));
  148. }
  149. if (data.volume) {
  150. options.volume = parseInt(this.evalMessage(data.volume, cache)) / 100;
  151. } else if (cache.server) {
  152. options.volume = Audio.volumes[cache.server.id] || 0.5;
  153. } else {
  154. options.volume = 0.5;
  155. }
  156. if (data.passes) {
  157. options.passes = parseInt(this.evalMessage(data.passes, cache));
  158. }
  159. if (data.bitrate) {
  160. options.bitrate = parseInt(this.evalMessage(data.bitrate, cache));
  161. } else {
  162. options.bitrate = 'auto';
  163. }
  164. options.requester = msg.author;
  165.  
  166. const video = await getInfoAsync(url)
  167. .catch((err) => {
  168. console.error(`Error with getInfoAsync in play_youtube: ${err}`);
  169. });
  170. options.title = video.title;
  171. options.duration = parseInt(video.length_seconds);
  172. options.thumbnail = video.player_response.videoDetails.thumbnail.thumbnails[3].url;
  173.  
  174. const info = ['yt', options, url];
  175. if (data.type === "0") {
  176. Audio.addToQueue(info, cache);
  177. } else if (cache.server && cache.server.id !== undefined) {
  178. Audio.playItem(info, cache.server.id);
  179. }
  180. }
  181. this.callNextAction(cache);
  182. },
  183.  
  184. //---------------------------------------------------------------------
  185. // Action Bot Mod
  186. //
  187. // Upon initialization of the bot, this code is run. Using the bot's
  188. // DBM namespace, one can add/modify existing functions if necessary.
  189. // In order to reduce conflictions between mods, be sure to alias
  190. // functions you wish to overwrite.
  191. //---------------------------------------------------------------------
  192.  
  193. mod: function (DBM) {}
  194.  
  195. }; // End of module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement