Advertisement
Blue_Label

Send Gmail

Jun 4th, 2019
1,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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: "Send Gmail",
  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.     return `from:"${data.username}" to: "${data.mailto}"`;
  27. },
  28.  
  29. //---------------------------------------------------------------------
  30. // Action Storage Function
  31. //
  32. // Stores the relevant variable info for the editor.
  33. //---------------------------------------------------------------------
  34.  
  35. variableStorage: function(data, varType) {
  36.     const type = parseInt(data.storage);
  37.     if(type !== varType) return;
  38.     return ([data.varName, 'Unknown Type']);
  39. },
  40.  
  41. //---------------------------------------------------------------------
  42. // Action Fields
  43. //
  44. // These are the fields for the action. These fields are customized
  45. // by creating elements with corresponding IDs in the HTML. These
  46. // are also the names of the fields stored in the action's JSON data.
  47. //---------------------------------------------------------------------
  48.  
  49. fields: ["username", "password", "mailto", "subject", "text", "iffalse", "iffalseVal"],
  50.  
  51. //---------------------------------------------------------------------
  52. // Command HTML
  53. //
  54. // This function returns a string containing the HTML used for
  55. // editting actions.
  56. //
  57. // The "isEvent" parameter will be true if this action is being used
  58. // for an event. Due to their nature, events lack certain information,
  59. // so edit the HTML to reflect this.
  60. //
  61. // The "data" parameter stores constants for select elements to use.
  62. // Each is an array: index 0 for commands, index 1 for events.
  63. // The names are: sendTargets, members, roles, channels,
  64. //                messages, servers, variables
  65. //---------------------------------------------------------------------
  66.  
  67. html: function(isEvent, data) {
  68.     return `
  69. <div style="width: 550px; height: 350px; overflow-y: scroll;">
  70.     <div><u>Add-On Info:</u><br>Made by <b>Blue Label</b></div><br>
  71.     <div style="float: left; width: 50%;">
  72.         Username:<br>
  73.         <input id="username" class="round" type="text">
  74.     </div>
  75.     <div style="float: left; width: 50%;">
  76.         Password:<br>
  77.         <input id="password" class="round" type="text">
  78.     </div><br><br><br>
  79.     <div style="float: left; width: 50%;">
  80.         mailto:<br>
  81.         <input id="mailto" class="round" type="text">
  82.     </div><br><br><br>
  83.     <div style="float: left; width: 50%;">
  84.         Subject:<br>
  85.         <input id="subject" class="round" type="text" name="is-eval"><br>
  86.     </div><br><br><br>
  87.     <div style="float: left; width: 90%;">
  88.     Text:<br>
  89.     <textarea id="text" rows="9" style="width: 90%;"></textarea>
  90.     </div>
  91.     <div style="padding-top: 8px;">
  92.         <div style="float: left; width: 35%;">
  93.             If Mail Delivery Fails:<br>
  94.             <select id="iffalse" class="round" onchange="glob.onChangeFalse(this)">
  95.                 <option value="0" selected>Continue Actions</option>
  96.                 <option value="1">Stop Action Sequence</option>
  97.                 <option value="2">Jump To Action</option>
  98.                 <option value="3">Skip Next Actions</option>
  99.          </select>
  100.         </div><br><br><br>
  101.         <div id="iffalseContainer" style="display: none; float: right; width: 60%;"><span id="iffalseName">Action Number</span>:<br><input id="iffalseVal" class="round" type="text"></div>
  102.     </div>
  103.     </div>
  104. </div>`
  105. },
  106. //---------------------------------------------------------------------
  107. // Action Editor Init Code
  108. //
  109. // When the HTML is first applied to the action editor, this code
  110. // is also run. This helps add modifications or setup reactionary
  111. // functions for the DOM elements.
  112. //---------------------------------------------------------------------
  113.  
  114. init: function() {
  115.     const {glob, document} = this;
  116.  
  117.     glob.onChangeFalse(document.getElementById('iffalse'));
  118. },
  119.  
  120. //---------------------------------------------------------------------
  121. // Action Bot Function
  122. //
  123. // This is the function for the action within the Bot's Action class.
  124. // Keep in mind event calls won't have access to the "msg" parameter,
  125. // so be sure to provide checks for variable existance.
  126. //---------------------------------------------------------------------
  127.  
  128. action: function(cache) {
  129.     const _this = this
  130.     const data = cache.actions[cache.index];
  131.     const AddOns = this.getAddOns();
  132.       const username = data.username;
  133.     const password = data.password;
  134.     const mailto = data.mailto;
  135.     const subject = data.subject;
  136.     const text = data.text;
  137.    
  138.     //Big thank to W3schools.com for this code.
  139.     const nodemailer = AddOns.require('nodemailer');
  140.  
  141.     var transporter = nodemailer.createTransport({
  142.       service: 'gmail',
  143.       auth: {
  144.         user: username,
  145.         pass: password
  146.       }
  147.     });
  148.  
  149.     var mailOptions = {
  150.       from: username,
  151.       to: mailto,
  152.       subject: subject,
  153.       text: text
  154.     };
  155.  
  156.     transporter.sendMail(mailOptions, function(error, info){
  157.       if (error) {
  158.         console.log(error);
  159.         _this.executeResults(false, data, cache);
  160.       } else {
  161.         console.log('Email successfully sent to: ' + mailto);
  162.         _this.callNextAction(cache);
  163.       }
  164.     });
  165. },
  166.  
  167. //---------------------------------------------------------------------
  168. // Action Bot Mod
  169. //
  170. // Upon initialization of the bot, this code is run. Using the bot's
  171. // DBM namespace, one can add/modify existing functions if necessary.
  172. // In order to reduce conflictions between mods, be sure to alias
  173. // functions you wish to overwrite.
  174. //---------------------------------------------------------------------
  175.  
  176. mod: function(DBM) {
  177. }
  178.  
  179. }; // End of module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement