Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.43 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: "Store Date Info",
  10.  
  11. //---------------------------------------------------------------------
  12. // Action Section
  13. //
  14. // This is the section the action will fall into.
  15. //---------------------------------------------------------------------
  16.  
  17. section: "Other Stuff",
  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 info = ['Day of the Week', 'Month of the Year', 'Unix Timestamp', '', 'Day Number', 'Year', 'Full Time', 'Hour', 'Month Number', 'Minute', 'Second', 'Timezone']
  27. return `Store ${info[parseInt(data.info)]} from Date`;
  28. },
  29.  
  30. //---------------------------------------------------------------------
  31. // DBM Mods Manager Variables (Optional but nice to have!)
  32. //
  33. // These are variables that DBM Mods Manager uses to show information
  34. // about the mods for people to see in the list.
  35. //---------------------------------------------------------------------
  36.  
  37. // Who made the mod (If not set, defaults to "DBM Mods")
  38. author: "iAmaury",
  39.  
  40. // The version of the mod (Defaults to 1.0.0)
  41. version: "1.8.9", //Added in 1.8.9
  42.  
  43. // A short description to show on the mod line for this mod (Must be on a single line)
  44. short_description: "Stores something from a Date.",
  45.  
  46. // If it depends on any other mods by name, ex: WrexMODS if the mod uses something from WrexMods
  47.  
  48. //---------------------------------------------------------------------
  49.  
  50. //---------------------------------------------------------------------
  51. // Action Storage Function
  52. //
  53. // Stores the relevant variable info for the editor.
  54. //---------------------------------------------------------------------
  55.  
  56. variableStorage: function(data, varType) {
  57. const type = parseInt(data.storage);
  58. if(type !== varType) return;
  59. const info = parseInt(data.info);
  60. let dataType = 'Unknown Type';
  61. switch(info) {
  62. case 0:
  63. dataType = 'String';
  64. break;
  65. case 1:
  66. dataType = 'String';
  67. break;
  68. case 2:
  69. dataType = 'Number';
  70. break;
  71. case 4:
  72. dataType = 'Number';
  73. break;
  74. case 5:
  75. dataType = 'Number';
  76. break;
  77. case 6:
  78. dataType = 'String';
  79. break;
  80. case 7:
  81. dataType = 'Number';
  82. break;
  83. case 8:
  84. dataType = 'Number';
  85. break;
  86. case 9:
  87. dataType = 'Number';
  88. break;
  89. case 10:
  90. dataType = 'Number';
  91. break;
  92. case 11:
  93. dataType = 'String';
  94. break;
  95. }
  96. return ([data.varName, dataType]);
  97. },
  98.  
  99. //---------------------------------------------------------------------
  100. // Action Fields
  101. //
  102. // These are the fields for the action. These fields are customized
  103. // by creating elements with corresponding IDs in the HTML. These
  104. // are also the names of the fields stored in the action's JSON data.
  105. //---------------------------------------------------------------------
  106.  
  107. fields: ["date", "info", "storage", "varName"],
  108.  
  109. //---------------------------------------------------------------------
  110. // Command HTML
  111. //
  112. // This function returns a string containing the HTML used for
  113. // editting actions.
  114. //
  115. // The "isEvent" parameter will be true if this action is being used
  116. // for an event. Due to their nature, events lack certain information,
  117. // so edit the HTML to reflect this.
  118. //
  119. // The "data" parameter stores constants for select elements to use.
  120. // Each is an array: index 0 for commands, index 1 for events.
  121. // The names are: sendTargets, members, roles, channels,
  122. // messages, servers, variables
  123. //---------------------------------------------------------------------
  124.  
  125. html: function(isEvent, data) {
  126. return `
  127. <div style="float: left; width: 30%; padding-top: 8px;">
  128. <p><u>Mod Info:</u><br>
  129. Made by <b>iAmaury</b> !</p>
  130. </div><br><br><br>
  131. <div style="padding-top: 8px;">
  132. Source Date:<br>
  133. <textarea id="date" rows="3" placeholder="e.g. Fri Apr 06 2018 13:32:10 GMT+0200" style="width: 99%; font-family: monospace; white-space: nowrap; resize: none;"></textarea>
  134. </div><br>
  135. <div style="padding-top: 8px; width: 70%;">
  136. Source Info:<br>
  137. <select id="info" class="round">
  138. <option value="2" selected>Unix Timestamp</option>
  139. <option value="0">Day of the Week</option>
  140. <option value="4">Day Number</option>
  141. <option value="1">Month of the Year</option>
  142. <option value="8">Month Number</option>
  143. <option value="5">Year</option>
  144. <option value="6">Full Time</option>
  145. <option value="7">Hour</option>
  146. <option value="9">Minute</option>
  147. <option value="10">Second</option>
  148. <option value="11">Timezone</option>
  149.  
  150. </select>
  151. </div><br>
  152. <div style="float: left; width: 35%; padding-top: 8px;">
  153. Store Result In:<br>
  154. <select id="storage" class="round" onchange="glob.variableChange(this, 'varNameContainer')">
  155. ${data.variables[0]}
  156. </select>
  157. </div>
  158. <div id="varNameContainer" style="float: right; display: none; width: 60%; padding-top: 8px;">
  159. Variable Name:<br>
  160. <input id="varName" class="round" type="text">
  161. </div>`
  162. },
  163.  
  164. //---------------------------------------------------------------------
  165. // Action Editor Init Code
  166. //
  167. // When the HTML is first applied to the action editor, this code
  168. // is also run. This helps add modifications or setup reactionary
  169. // functions for the DOM elements.
  170. //---------------------------------------------------------------------
  171.  
  172. init: function() {
  173. const {glob, document} = this;
  174.  
  175. glob.variableChange(document.getElementById('storage'), 'varNameContainer');
  176. },
  177.  
  178. //---------------------------------------------------------------------
  179. // Action Bot Function
  180. //
  181. // This is the function for the action within the Bot's Action class.
  182. // Keep in mind event calls won't have access to the "msg" parameter,
  183. // so be sure to provide checks for variable existance.
  184. //---------------------------------------------------------------------
  185.  
  186. action: function(cache) {
  187. const data = cache.actions[cache.index];
  188. const date = this.evalMessage(data.date, cache);
  189. const info = parseInt(data.info);
  190. if(Date.parse(date) == NaN) {
  191. console.log('Invalid Date ! Check that your date is valid. A Date generally looks like the one stored in "Creation Date" of a server. (variables works)');
  192. this.callNextAction(cache);
  193. }
  194.  
  195. let result;
  196. switch(info) {
  197. case 0:
  198. result = date.slice(0, 3);
  199. break;
  200. case 1:
  201. result = date.slice(4, 7);
  202. if (result == 'Jan') {result = 'Stycznia';}
  203. if (result == 'Feb') {result = 'Lutego';}
  204. if (result == 'Mar') {result = 'Marca';}
  205. if (result == 'Apr') {result = 'Kwietnia';}
  206. if (result == 'May') {result = 'Maja';}
  207. if (result == 'Jun') {result = 'Czerwca';}
  208. if (result == 'Jul') {result = 'Lipca';}
  209. if (result == 'Aug') {result = 'Sierpnia';}
  210. if (result == 'Sep') {result = 'Września';}
  211. if (result == 'Oct') {result = 'Października';}
  212. if (result == 'Nov') {result = 'Listopada';}
  213. if (result == 'Dec') {result = 'Grudnia';}
  214. if (result == date.slice(4, 7)) {
  215. console.log('An error occured on "Store Date Info (Month of the Year)"')
  216. this.callNextAction(cache)
  217. }
  218. break;
  219. case 2:
  220. result = parseInt(Date.parse(date) / 1000);
  221. break;
  222. case 4:
  223. result = parseInt(date.slice(8, 10));
  224. break;
  225. case 5:
  226. result = parseInt(date.slice(11, 15));
  227. break;
  228. case 6:
  229. result = date.slice(16, 24);
  230. break;
  231. case 7:
  232. result = (date.slice(16, 18));
  233. break;
  234. case 8:
  235. result = date.slice(4, 7);
  236. if (result == 'Jan') {result = 1;}
  237. if (result == 'Feb') {result = 2;}
  238. if (result == 'Mar') {result = 3;}
  239. if (result == 'Apr') {result = 4;}
  240. if (result == 'May') {result = 5;}
  241. if (result == 'Jun') {result = 6;}
  242. if (result == 'Jul') {result = 7;}
  243. if (result == 'Aug') {result = 8;}
  244. if (result == 'Sep') {result = 9;}
  245. if (result == 'Oct') {result = 10;}
  246. if (result == 'Nov') {result = 11;}
  247. if (result == 'Dec') {result = 12;}
  248. if (result == date.slice(4, 7)) {
  249. console.log('An error occured on "Store Date Info (Month Number)"')
  250. this.callNextAction(cache)
  251. }
  252. break;
  253. case 9:
  254. result = date.slice(19, 21);
  255. break;
  256. case 10:
  257. result = date.slice(22, 24);
  258. break;
  259. case 11:
  260. result = 'GMT' + date.slice(28, 29) + parseInt(date.slice(29, 33)) / 100;
  261. default:
  262. break;
  263. }
  264. if(result !== undefined) {
  265. const storage = parseInt(data.storage);
  266. const varName = this.evalMessage(data.varName, cache);
  267. this.storeValue(result, storage, varName, cache);
  268. }
  269. this.callNextAction(cache);
  270. },
  271.  
  272. //---------------------------------------------------------------------
  273. // Action Bot Mod
  274. //
  275. // Upon initialization of the bot, this code is run. Using the bot's
  276. // DBM namespace, one can add/modify existing functions if necessary.
  277. // In order to reduce conflictions between mods, be sure to alias
  278. // functions you wish to overwrite.
  279. //---------------------------------------------------------------------
  280.  
  281. mod: function(DBM) {
  282. }
  283.  
  284. }; // End of module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement