Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Discord
  2. const Discord = require('discord.js');
  3. const client = new Discord.Client();
  4.  
  5. //Selenium
  6. const {Builder, By, Key, until} = require('selenium-webdriver');
  7. const webdriver = require('selenium-webdriver');
  8. const chrome = require('selenium-webdriver/chrome');
  9. let driver = new Builder().forBrowser('chrome').build();
  10.  
  11. var sendButton;
  12. var inputField;
  13.  
  14. client.on('ready', () => {
  15.    
  16.     //Send login success message to NodeJs console
  17.     console.log(`Logged in as ${client.user.tag}!`);
  18.  
  19.     //Load the bot page
  20.     driver.get('https://www.eviebot.com/en/');
  21.  
  22.     //Hook on the send button
  23.     sendButton = driver.findElement(By.name('sayitbutton'));
  24.  
  25.     //Hook on the input field
  26.     inputField = driver.findElement(By.name('stimulus'));
  27.  
  28. });
  29.  
  30. client.on('message', msg => {
  31.    
  32.     if (msg.content.startsWith("<@404650294673276929>")){
  33.  
  34.         //Get the message, remove the bot's name from the string
  35.         var message = msg.content.replace("<@404650294673276929> ", "");
  36.  
  37.         //Send the message to the input field
  38.         inputField.sendKeys(message, Key.RETURN);
  39.  
  40.         //Send the message
  41.         sendButton.click();
  42.  
  43.         //Message sent by the client
  44.         console.log("Client sent: "+message);
  45.        
  46.         //Sleep for 1 second before starting to check if the refresh icon is visible
  47.         driver.sleep(500).then(function(){
  48.            
  49.             //Promise for locating the refresh icon element
  50.             var refreshIconPromise = driver.wait(until.elementLocated(By.id('refreshicon')), 20000);
  51.            
  52.             //Wait for the location of the refresh icon element
  53.             refreshIconPromise.then(function(){
  54.                
  55.                 //Hook on the element
  56.                 var refreshIcon = driver.findElement(By.id('refreshicon'));
  57.                
  58.                 //Wait for 20 for the refresh icon to appear
  59.                 driver.wait(function() {
  60.                     return refreshIcon.then(function(el) {
  61.                         return el.isDisplayed();
  62.                     });
  63.                 }, 20000).then(function(){
  64.                     getBotResponse(msg);
  65.                 });
  66.                
  67.             });
  68.         });
  69.    
  70.     };
  71.        
  72.    
  73.        
  74.        
  75. });
  76.  
  77.  
  78. function getBotResponse(msg){
  79.     var linePromise = driver.findElements(By.xpath('//*[@id="line1"]/span'));
  80.     linePromise.then(function(line) {
  81.         textPromise = line[0].getText();
  82.         textPromise.then(function(botResponse){
  83.             console.log("Evie responded with: "+botResponse);
  84.         });
  85.     });
  86. }
  87.  
  88.  
  89.  
  90.  
  91. client.login('');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement