Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Discord
- const Discord = require('discord.js');
- const client = new Discord.Client();
- //Selenium
- const {Builder, By, Key, until} = require('selenium-webdriver');
- const webdriver = require('selenium-webdriver');
- const chrome = require('selenium-webdriver/chrome');
- let driver = new Builder().forBrowser('chrome').build();
- var sendButton;
- var inputField;
- client.on('ready', () => {
- //Send login success message to NodeJs console
- console.log(`Logged in as ${client.user.tag}!`);
- //Load the bot page
- driver.get('https://www.eviebot.com/en/');
- //Hook on the send button
- sendButton = driver.findElement(By.name('sayitbutton'));
- //Hook on the input field
- inputField = driver.findElement(By.name('stimulus'));
- });
- client.on('message', msg => {
- if (msg.content.startsWith("<@404650294673276929>")){
- //Get the message, remove the bot's name from the string
- var message = msg.content.replace("<@404650294673276929> ", "");
- //Send the message to the input field
- inputField.sendKeys(message, Key.RETURN);
- //Send the message
- sendButton.click();
- //Message sent by the client
- console.log("Client sent: "+message);
- //Sleep for 1 second before starting to check if the refresh icon is visible
- driver.sleep(500).then(function(){
- //Promise for locating the refresh icon element
- var refreshIconPromise = driver.wait(until.elementLocated(By.id('refreshicon')), 20000);
- //Wait for the location of the refresh icon element
- refreshIconPromise.then(function(){
- //Hook on the element
- var refreshIcon = driver.findElement(By.id('refreshicon'));
- //Wait for 20 for the refresh icon to appear
- driver.wait(function() {
- return refreshIcon.then(function(el) {
- return el.isDisplayed();
- });
- }, 20000).then(function(){
- getBotResponse(msg);
- });
- });
- });
- };
- });
- function getBotResponse(msg){
- var linePromise = driver.findElements(By.xpath('//*[@id="line1"]/span'));
- linePromise.then(function(line) {
- textPromise = line[0].getText();
- textPromise.then(function(botResponse){
- console.log("Evie responded with: "+botResponse);
- });
- });
- }
- client.login('');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement