Advertisement
Guest User

Untitled

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