JasonYuan869 / AutoWaifuClaimerV3

Automatically claims from the Discord Mudae bot.
MIT License
40 stars 39 forks source link

Hello someone know how i can fix this #14

Open T3Fel opened 3 years ago

T3Fel commented 3 years ago
Sem título
T3Fel commented 3 years ago

The bot sends the -tu message, but after that it closes itself

T3Fel commented 3 years ago

I left the window suspended and it was like this

2021-06-11 22:51:14,998 - discord.client - WARNING - PyNaCl is not installed, voice will NOT be supported 2021-06-11 22:51:14,999 - root - INFO - Parsing likelist 2021-06-11 22:51:14,999 - root - INFO - Starting browser thread 2021-06-11 22:51:15,000 - browsers - INFO - Browser thread started 2021-06-11 22:51:15,000 - discord.client - INFO - logging in using static token 2021-06-11 22:51:15,000 - browsers - INFO - Attempting to open Discord in browser 2021-06-11 22:51:16,510 - discord.gateway - INFO - Shard ID None has sent the IDENTIFY payload. 2021-06-11 22:51:16,903 - discord.gateway - INFO - Shard ID None has connected to Gateway: ["gateway-prd-main-hgcj",{"micros":110382,"calls":["discord-sessions-blue-prd-2-75",{"micros":109049,"calls":["start_session",{"micros":87038,"calls":["api-prd-main-gzmz",{"micros":83325,"calls":["get_user",{"micros":4635},"add_authorized_ip",{"micros":6305},"get_guilds",{"micros":21494},"coros_wait",{"micros":1}]}]},"guilds_connect",{"micros":1,"calls":[]},"presence_connect",{"micros":14316,"calls":[]}]}]}] (Session ID: 0574e9847c7b42accb5e94b9472666cc). 2021-06-11 22:51:28,037 - browsers - INFO - Logging in with provided credentials (this may take up to 30 seconds) 2021-06-11 22:51:31,892 - browsers - INFO - Login successful to server 355359771882160128 and channel 850190115792093194 2021-06-11 22:51:31,892 - root - INFO - Bot connected as Filipe David Braga Machado with ID 853067647562285126 2021-06-11 22:51:33,519 - root - INFO - Attempting to parse $tu command 2021-06-11 22:51:33,519 - browsers - INFO - Sending text: -tu 2021-06-11 22:51:36,531 - root - CRITICAL - Could not parse $tu command, quitting (try again) 2021-06-11 22:51:37,232 - discord.gateway - INFO - Websocket closed with 1000, cannot reconnect. Ignoring exception in on_ready Traceback (most recent call last): File "C:\Users\Felipe\Documents\AutoWaifuClaimerV3-3\AutoWaifuClaimerV3-3\bot.py", line 133, in on_ready await client.wait_for('message', check=parse_tu, timeout=3) File "C:\Users\Felipe\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py", line 490, in wait_for raise exceptions.TimeoutError() asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Felipe\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 333, in _run_event await coro(*args, **kwargs) File "C:\Users\Felipe\Documents\AutoWaifuClaimerV3-3\AutoWaifuClaimerV3-3\bot.py", line 137, in on_ready await close_bot() File "C:\Users\Felipe\Documents\AutoWaifuClaimerV3-3\AutoWaifuClaimerV3-3\bot.py", line 67, in close_bot client.loop.close() File "C:\Users\Felipe\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 674, in close raise RuntimeError("Cannot close a running event loop") RuntimeError: Cannot close a running event loop Traceback (most recent call last): File "C:\Users\Felipe\Documents\AutoWaifuClaimerV3-3\AutoWaifuClaimerV3-3\bot.py", line 288, in browser.close() File "C:\Users\Felipe\Documents\AutoWaifuClaimerV3-3\AutoWaifuClaimerV3-3\browsers.py", line 146, in close self.driver.close() File "C:\Users\Felipe\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 688, in close self.execute(Command.CLOSE) File "C:\Users\Felipe\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Felipe\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidSessionIdException: Message: Tried to run command without establishing a connection

jakingy commented 3 years ago

I had the same issue. It seems to be caused by a Discord Hubs pop-up preventing the bot typing $tu. hubs A temporary fix that worked for me is to add a few lines to the browser_login function in browser.py:

    def browser_login(self):
        self.logger.info('Browser thread started')
        self.logger.info('Attempting to open Discord in browser')
        self.driver.get(f'https://discord.com/channels/{config.SERVER_ID}/{config.CHANNEL_ID}')
        try:
            email = WebDriverWait(self.driver, 10).until(lambda x: x.find_element(By.NAME, 'email'))
        except TimeoutException:
            if f'{config.SERVER_ID}/{config.CHANNEL_ID}' not in self.driver.current_url:
                # No login screen, but wrong channel (some weird error)
                self.logger.critical('The channel did not load and no login was asked!')
                raise TimeoutError
        else:
            self.logger.info('Logging in with provided credentials (this may take up to 30 seconds)')
            email.send_keys(config.LOGIN_INFO[0])
            self.driver.find_element(By.NAME, 'password').send_keys(config.LOGIN_INFO[1])
            self.driver.find_element(By.XPATH, "//button[@type='submit']").click()
            try:
                # Wait for main screen
                WebDriverWait(self.driver, 30).until(lambda x: x.find_element(By.CLASS_NAME, 'slateTextArea-1Mkdgw'))
                if f'{config.SERVER_ID}/{config.CHANNEL_ID}' not in self.driver.current_url:
                    # Logged in, but wrong channel (some weird error)
                    raise ValueError
                ### Added: Close Discord Hub overlay
                try:
                    el = self.driver.find_element(By.CLASS_NAME, "close-hZ94c6")
                    self.logger.info('Closing Discord Hubs overlay')
                    self.actions = ActionChains(self.driver)
                    self.actions.move_to_element_with_offset(el, 5, 5)
                    self.actions.click()
                    self.actions.perform()
                except Exception:
                    self.logger.info('No Discord Hubs overlay found')
                ###
            except TimeoutException or NoSuchElementException:
                self.logger.critical('Login was unsuccessful. Please check LOGIN_INFO entry in config.py')
                raise TimeoutError
            except ValueError:
                self.logger.critical('Login was successful but the channel did not load')
                raise ValueError
            else:
                self.logger.info(f'Login successful to server {config.SERVER_ID} and channel {config.CHANNEL_ID}')
                return True
xdrushxd commented 3 years ago

Having the same issue here, i did try the above code but this changed nothing... weirdly the bot was working in the past and i closed it changed some lines and BAM broken, when't back to the backup...did not work either. Installed everything fresh on a new machine i normally don't use for code. Still nothing, still not working....

Now comes the question: @jakingy How did you find out the error had to do with the "discord hubs", maybe i can then see what causes my error.

Thanks

jakingy commented 3 years ago

@xdrushxd you can comment out line 41 of browsers.py to see what the bot is doing:

        # Selenium browser control here
        options = Options()
        # options.add_argument('-headless') comment out this
        self.driver = webdriver.Firefox(executable_path=config.WEB_DRIVER_PATH, options=options)
        self.actions = ActionChains(self.driver)

In the process of testing, I also found an issue with how $tu is parsed which results in the same error. The structure of the output of $tu can be changed with $tuarrange or when $rt is unlocked for example, but the parser expects a specific structure and will fail otherwise.

xdrushxd commented 3 years ago

@jakingy i have tested the last few days, thanks for your feedback!

i have fixed my pop-up error that i got from "Discord Threads" with this piece of code...

def send_text(self, text: str):
        # For some reason, typing directly into the message box doesn't work
        # ActionChains must be used instead to type character by character
        self.actions = ActionChains(self.driver)
        time.sleep(3)
        self.actions.key_down(Keys.ENTER)
        self.actions.key_up(Keys.ENTER)
        time.sleep(3)
        self.logger.info(f'Sending text: {text}')
        try:
            message_box = WebDriverWait(self.driver, 1).until(
                lambda x: x.find_element(By.CLASS_NAME, 'slateTextArea-1Mkdgw'))
        except TimeoutException:
            self.logger.warning("Discord may have crashed, refreshing page")
            self.refresh()
            return self.send_text(text)
        self.actions.click(on_element=message_box)
        for char in text:
            self.actions.key_down(char)
            self.actions.key_up(char)
        self.actions.key_down(Keys.ENTER)
        self.actions.key_up(Keys.ENTER)
        self.actions.perform()

All it does is just wait couple sec then press enter to close the pop-up and thats it, but then i got another error so still trying to fix the bot.

image

Will upload it if once done.