PanagiotisIatrou / chess-auto-bot

A bot for chess.com and lichess.org that automatically plays chess for you
MIT License
76 stars 28 forks source link

option to disable keypress listener on linux. #36

Open kusayuzayushko opened 1 year ago

kusayuzayushko commented 1 year ago
Exception in thread Thread-4 (keypress_listener_thread):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/crypt/ssd1/chess-auto-bot/src/gui.py", line 349, in keypress_listener_thread
    if keyboard.is_pressed("1"):
  File "/home/crypt/ssd1/chess-auto-bot/venv/lib/python3.10/site-packages/keyboard/__init__.py", line 410, in is_pressed
    _listener.start_if_necessary()
  File "/home/crypt/ssd1/chess-auto-bot/venv/lib/python3.10/site-packages/keyboard/_generic.py", line 35, in start_if_necessary
    self.init()
  File "/home/crypt/ssd1/chess-auto-bot/venv/lib/python3.10/site-packages/keyboard/__init__.py", line 196, in init
    _os_keyboard.init()
  File "/home/crypt/ssd1/chess-auto-bot/venv/lib/python3.10/site-packages/keyboard/_nixkeyboard.py", line 113, in init
    build_device()
  File "/home/crypt/ssd1/chess-auto-bot/venv/lib/python3.10/site-packages/keyboard/_nixkeyboard.py", line 109, in build_device
    ensure_root()
  File "/home/crypt/ssd1/chess-auto-bot/venv/lib/python3.10/site-packages/keyboard/_nixcommon.py", line 174, in ensure_root
    raise ImportError('You must be root to use this library on linux.')
ImportError: You must be root to use this library on linux.
You must be root to use this library on linux.
<class 'ImportError'> stockfish_bot.py 195

Linux users can't just run it with sudo, this will cause issues with graphical apps that use X (chrome, for example).

kusayuzayushko commented 1 year ago
index 200e4c7..96588c9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,5 +5,4 @@ PyAutoGUI~=0.9.53
 chess~=1.9.3
 stockfish~=3.28.0
 packaging~=21.3
-keyboard~=0.13.5
-PyQt5~=5.15.7
\ No newline at end of file
+PyQt5~=5.15.7
diff --git a/src/gui.py b/src/gui.py
index 3b1fab5..c91a1c1 100644
--- a/src/gui.py
+++ b/src/gui.py
@@ -12,7 +12,6 @@ from webdriver_manager.chrome import ChromeDriverManager
 from overlay import run
 from stockfish_bot import StockfishBot
 from selenium.common import WebDriverException
-import keyboard

 class GUI:
@@ -346,11 +345,6 @@ class GUI:
             if not self.opened_browser:
                 continue

-            if keyboard.is_pressed("1"):
-                self.on_start_button_listener()
-            elif keyboard.is_pressed("2"):
-                self.on_stop_button_listener()
-
     def on_open_browser_button_listener(self):
         # Set Opening Browser button state to opening
         self.opening_browser = True
diff --git a/src/stockfish_bot.py b/src/stockfish_bot.py
index 415c599..db08110 100644
--- a/src/stockfish_bot.py
+++ b/src/stockfish_bot.py
@@ -11,7 +11,6 @@ import re
 from grabbers.chesscom_grabber import ChesscomGrabber
 from grabbers.lichess_grabber import LichessGrabber
 from utilities import char_to_num
-import keyboard

 class StockfishBot(multiprocess.Process):
@@ -192,9 +191,6 @@ class StockfishBot(multiprocess.Process):
                             ((int(move_start_pos[0]), int(move_start_pos[1])), (int(move_end_pos[0]), int(move_end_pos[1]))),
                         ])
                         while True:
-                            if keyboard.is_pressed("3"):
-                                break
-
                             if len(move_list) != len(self.grabber.get_move_list()):
                                 self_moved = True
                                 move_list = self.grabber.get_move_list()

quick and dirty attempt to get rid of keyboard. Bot is now starting but only detecting a game against bots. If I run it in a game against other players if i logged in to chess.com. Playing as a guest against other players work just fine.

<class 'selenium.common.exceptions.StaleElementReferenceException'> stockfish_bot.py 241
list index out of range
<class 'IndexError'> stockfish_bot.py 128

UPD: it works just fine with a fresh account.