From 7694fdaed50482f834738c8823fbba9f3fa293c8 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 20 Nov 2023 19:32:46 +0100 Subject: [PATCH] get a countdown --- minecraft_automation_log.txt | 147 +++++++++++++++++++++++++++++++++++ trader.py | 40 ++++++---- trader2.py | 40 ++++++---- 3 files changed, 195 insertions(+), 32 deletions(-) diff --git a/minecraft_automation_log.txt b/minecraft_automation_log.txt index a3572d3..d6216fc 100644 --- a/minecraft_automation_log.txt +++ b/minecraft_automation_log.txt @@ -2882,3 +2882,150 @@ 2023-11-19 13:28:21,062: Posted to Discord: Potion clicked. 2023-11-19 13:28:21,062: Pressing 'Esc' key. 2023-11-19 13:28:22,078: Holding 'D' key for a step. +2023-11-20 18:20:10,166: Focusing Minecraft window... +2023-11-20 18:20:12,177: Pressing Esc... +2023-11-20 18:20:14,195: Performing right click. +2023-11-20 18:20:15,297: Checking for trade window... +2023-11-20 18:20:16,380: Trade window not detected. Adjusting position. +2023-11-20 18:26:57,139: Focusing Minecraft window... +2023-11-20 18:26:59,255: Pressing Esc... +2023-11-20 18:27:01,276: Performing right click. +2023-11-20 18:27:02,380: Checking for trade window... +2023-11-20 18:27:03,403: Trade window not detected. Adjusting position. +2023-11-20 18:27:20,995: Focusing Minecraft window... +2023-11-20 18:27:23,113: Pressing Esc... +2023-11-20 18:27:25,133: Performing right click. +2023-11-20 18:27:26,236: Checking for trade window... +2023-11-20 18:27:27,290: Trade window not detected. Adjusting position. +2023-11-20 18:36:42,389: Focusing Minecraft window... +2023-11-20 18:36:44,401: Left-clicking to focus mouse in game... +2023-11-20 18:36:44,507: Pressing Esc... +2023-11-20 18:36:46,527: Performing right click. +2023-11-20 18:36:47,632: Checking for trade window... +2023-11-20 18:36:53,265: Focusing Minecraft window... +2023-11-20 18:36:55,278: Left-clicking to focus mouse in game... +2023-11-20 18:36:55,384: Pressing Esc... +2023-11-20 18:36:57,404: Performing right click. +2023-11-20 18:36:58,508: Checking for trade window... +2023-11-20 18:37:31,820: Focusing Minecraft window... +2023-11-20 18:37:33,833: Left-clicking to focus mouse in game... +2023-11-20 18:37:33,939: Pressing Esc... +2023-11-20 18:37:35,960: Performing right click. +2023-11-20 18:37:37,064: Checking for trade window... +2023-11-20 18:37:38,080: Trade window detected. +2023-11-20 18:37:38,080: Dragging slider. +2023-11-20 18:37:41,096: Taking a screenshot for color search... +2023-11-20 18:37:55,725: Focusing Minecraft window... +2023-11-20 18:37:57,737: Left-clicking to focus mouse in game... +2023-11-20 18:37:57,841: Pressing Esc... +2023-11-20 18:37:59,861: Performing right click. +2023-11-20 18:38:00,966: Checking for trade window... +2023-11-20 18:38:02,002: Trade window not detected. Adjusting position. +2023-11-20 18:39:37,413: Focusing Minecraft window... +2023-11-20 18:39:41,208: Focusing Minecraft window... +2023-11-20 18:40:48,443: Focusing Minecraft window... +2023-11-20 18:41:19,908: Focusing Minecraft window... +2023-11-20 18:41:21,924: Left-clicking to focus mouse in game... +2023-11-20 18:41:22,029: Pressing Esc... +2023-11-20 18:41:24,050: Performing right click. +2023-11-20 18:41:25,155: Checking for trade window... +2023-11-20 18:41:26,221: Trade window not detected. Adjusting position. +2023-11-20 18:57:05,271: Focusing Minecraft window... +2023-11-20 18:57:05,283: Error focusing Minecraft window: Command '['xdotool', 'search', '--name', 'Minecraft* 1.20.2 - Multiplayer (3rd-party Server)']' returned non-zero exit status 1. +2023-11-20 18:57:05,286: Performing right click. +2023-11-20 18:57:06,389: Checking for trade window... +2023-11-20 18:57:07,454: Trade window not detected. Adjusting position. +2023-11-20 18:57:13,299: Focusing Minecraft window... +2023-11-20 18:57:13,311: Error focusing Minecraft window: Command '['xdotool', 'search', '--name', 'Minecraft* 1.20.2 - Multiplayer (3rd-party Server)']' returned non-zero exit status 1. +2023-11-20 18:57:13,314: Performing right click. +2023-11-20 18:57:14,417: Checking for trade window... +2023-11-20 18:57:15,464: Trade window not detected. Adjusting position. +2023-11-20 18:59:41,904: Focusing Minecraft window... +2023-11-20 18:59:41,916: Error focusing Minecraft window: Command '['xdotool', 'search', '--name', 'Minecraft* 1.20.2 - Multiplayer (3rd-party Server)']' returned non-zero exit status 1. +2023-11-20 18:59:41,920: Performing right click. +2023-11-20 18:59:43,024: Checking for trade window... +2023-11-20 18:59:44,063: Trade window not detected. Adjusting position. +2023-11-20 19:02:54,241: Focusing Minecraft window... +2023-11-20 19:02:54,252: Error focusing Minecraft window: Command '['xdotool', 'search', '--name', 'Minecraft* 1.20.2 - Multiplayer (3rd-party Server)']' returned non-zero exit status 1. +2023-11-20 19:02:54,256: Performing right click. +2023-11-20 19:02:55,359: Checking for trade window... +2023-11-20 19:02:56,376: Trade window not detected. Adjusting position. +2023-11-20 19:03:06,629: Focusing Minecraft window... +2023-11-20 19:03:06,642: Error focusing Minecraft window: Command '['xdotool', 'search', '--name', 'Minecraft* 1.20.2 - Multiplayer (3rd-party Server)']' returned non-zero exit status 1. +2023-11-20 19:03:06,646: Performing right click. +2023-11-20 19:03:07,749: Checking for trade window... +2023-11-20 19:03:08,851: Trade window not detected. Adjusting position. +2023-11-20 19:04:27,179: Focusing Minecraft window... +2023-11-20 19:04:29,194: Left-clicking at specific coordinates to focus mouse in game... +2023-11-20 19:04:29,299: Pressing Esc... +2023-11-20 19:04:31,320: Performing right click. +2023-11-20 19:04:32,424: Checking for trade window... +2023-11-20 19:04:33,440: Trade window not detected. Adjusting position. +2023-11-20 19:04:38,366: Focusing Minecraft window... +2023-11-20 19:04:40,381: Left-clicking at specific coordinates to focus mouse in game... +2023-11-20 19:04:40,487: Pressing Esc... +2023-11-20 19:04:42,507: Performing right click. +2023-11-20 19:04:43,612: Checking for trade window... +2023-11-20 19:04:47,613: Focusing Minecraft window... +2023-11-20 19:04:49,627: Left-clicking at specific coordinates to focus mouse in game... +2023-11-20 19:04:49,732: Pressing Esc... +2023-11-20 19:04:51,753: Performing right click. +2023-11-20 19:04:52,857: Checking for trade window... +2023-11-20 19:04:53,883: Trade window not detected. Adjusting position. +2023-11-20 19:14:15,316: Performing right click. +2023-11-20 19:14:16,421: Checking for trade window... +2023-11-20 19:14:17,478: Trade window not detected. Adjusting position. +2023-11-20 19:14:23,351: Performing right click. +2023-11-20 19:14:24,455: Checking for trade window... +2023-11-20 19:14:25,506: Trade window not detected. Adjusting position. +2023-11-20 19:22:15,947: Focusing Minecraft window... +2023-11-20 19:22:17,962: Left-clicking at specific coordinates to focus mouse in game... +2023-11-20 19:22:18,668: Pressing Esc... +2023-11-20 19:22:20,689: Performing right click. +2023-11-20 19:22:26,524: Focusing Minecraft window... +2023-11-20 19:22:28,540: Left-clicking at specific coordinates to focus mouse in game... +2023-11-20 19:22:29,245: Pressing Esc... +2023-11-20 19:22:31,265: Performing right click. +2023-11-20 19:22:32,369: Checking for trade window... +2023-11-20 19:22:33,403: Trade window not detected. Adjusting position. +2023-11-20 19:22:36,098: Focusing Minecraft window... +2023-11-20 19:22:38,113: Left-clicking at specific coordinates to focus mouse in game... +2023-11-20 19:22:38,822: Pressing Esc... +2023-11-20 19:22:40,842: Performing right click. +2023-11-20 19:22:41,946: Checking for trade window... +2023-11-20 19:22:42,990: Trade window not detected. Adjusting position. +2023-11-20 19:22:48,473: Focusing Minecraft window... +2023-11-20 19:22:50,488: Left-clicking at specific coordinates to focus mouse in game... +2023-11-20 19:22:51,194: Pressing Esc... +2023-11-20 19:22:53,215: Performing right click. +2023-11-20 19:28:32,896: Please click on the Minecraft window. +2023-11-20 19:28:33,897: Starting in 3... +2023-11-20 19:28:34,897: 2... +2023-11-20 19:28:35,897: 1... +2023-11-20 19:28:36,897: Script is now running. +2023-11-20 19:28:36,901: Performing right click. +2023-11-20 19:28:38,004: Checking for trade window... +2023-11-20 19:28:39,032: Trade window not detected. Adjusting position. +2023-11-20 19:31:37,670: Please click on the Minecraft window. +2023-11-20 19:31:38,670: Starting in 3... +2023-11-20 19:31:39,670: 2... +2023-11-20 19:31:40,671: 1... +2023-11-20 19:31:41,671: Script is now running. +2023-11-20 19:31:41,671: Pressing 'Esc' key to ensure focus. +2023-11-20 19:31:42,691: Performing right click. +2023-11-20 19:31:43,795: Checking for trade window... +2023-11-20 19:31:44,805: Trade window detected. +2023-11-20 19:31:44,806: Dragging slider. +2023-11-20 19:31:47,821: Taking a screenshot for color search... +2023-11-20 19:31:50,853: Color found at (2536, 1420). Clicking at this position. +2023-11-20 19:31:50,857: Performing left click. +2023-11-20 19:31:51,961: Color found at (2536, 1420). Clicking at this position. +2023-11-20 19:31:51,965: Performing left click. +2023-11-20 19:31:53,074: Performing left click. +2023-11-20 19:31:53,177: Performing shift click. +2023-11-20 19:31:54,777: Posted to Discord: Potion clicked. +2023-11-20 19:31:54,783: Performing left click. +2023-11-20 19:31:54,888: Performing shift click. +2023-11-20 19:31:56,622: Posted to Discord: Potion clicked. +2023-11-20 19:31:56,623: Pressing 'Esc' key. +2023-11-20 19:31:57,639: Holding 'D' key for a step. diff --git a/trader.py b/trader.py index 04b318a..0de3fa9 100644 --- a/trader.py +++ b/trader.py @@ -1,6 +1,7 @@ import requests import subprocess import time +import pyautogui from PIL import Image, ImageGrab import logging @@ -51,12 +52,16 @@ def find_color_in_image(target_color, image): return None, None def focus_minecraft_window(): - log_and_print("Focusing Minecraft window...") - subprocess.run(['xdotool', 'search', '--name', 'Minecraft*1.20.2 - Multiplayer (3rd-party-Server)', 'windowactivate', '--sync']) - time.sleep(2) - log_and_print("Pressing Esc...") - subprocess.run(['xdotool', 'key', 'Escape']) - time.sleep(2) + log_and_print("Please click on the Minecraft window.") + time.sleep(1) + log_and_print("Starting in 3...") + time.sleep(1) + log_and_print("2...") + time.sleep(1) + log_and_print("1...") + time.sleep(1) + log_and_print("Script is now running.") + return True def check_trade_window(): log_and_print("Checking for trade window...") @@ -69,7 +74,7 @@ def check_trade_window(): else: log_and_print("Trade window not detected. Adjusting position.") adjustment_combinations = [('a', 0.1), ('d', 0.1), ('a', 0.2), ('d', 0.2)] - for _ in range(5): # Try up to three times + for _ in range(5): # Try up to five times for key, duration in adjustment_combinations: subprocess.run(['xdotool', 'keydown', key]) time.sleep(duration) @@ -87,9 +92,11 @@ def check_trade_window(): post_to_discord("Trade window not found.") return False - - def trade_actions(): + log_and_print("Pressing 'Esc' key to ensure focus.") + subprocess.run(['xdotool', 'key', 'Escape']) + time.sleep(1) + right_click(2725, 1203) time.sleep(1) @@ -132,10 +139,11 @@ def trade_actions(): return True # Indicate that the trade action was successful - -focus_minecraft_window() - -for _ in range(40): # Number of trades to perform - result = trade_actions() - if not result: - break # Stop the script if trade window is not detected +# Main script execution +if not focus_minecraft_window(): + log_and_print("Minecraft window not detected. Stopping script.") +else: + for _ in range(40): # Number of trades to perform + result = trade_actions() + if not result: + break # Stop the script if trade window is not detected diff --git a/trader2.py b/trader2.py index 04b318a..0de3fa9 100644 --- a/trader2.py +++ b/trader2.py @@ -1,6 +1,7 @@ import requests import subprocess import time +import pyautogui from PIL import Image, ImageGrab import logging @@ -51,12 +52,16 @@ def find_color_in_image(target_color, image): return None, None def focus_minecraft_window(): - log_and_print("Focusing Minecraft window...") - subprocess.run(['xdotool', 'search', '--name', 'Minecraft*1.20.2 - Multiplayer (3rd-party-Server)', 'windowactivate', '--sync']) - time.sleep(2) - log_and_print("Pressing Esc...") - subprocess.run(['xdotool', 'key', 'Escape']) - time.sleep(2) + log_and_print("Please click on the Minecraft window.") + time.sleep(1) + log_and_print("Starting in 3...") + time.sleep(1) + log_and_print("2...") + time.sleep(1) + log_and_print("1...") + time.sleep(1) + log_and_print("Script is now running.") + return True def check_trade_window(): log_and_print("Checking for trade window...") @@ -69,7 +74,7 @@ def check_trade_window(): else: log_and_print("Trade window not detected. Adjusting position.") adjustment_combinations = [('a', 0.1), ('d', 0.1), ('a', 0.2), ('d', 0.2)] - for _ in range(5): # Try up to three times + for _ in range(5): # Try up to five times for key, duration in adjustment_combinations: subprocess.run(['xdotool', 'keydown', key]) time.sleep(duration) @@ -87,9 +92,11 @@ def check_trade_window(): post_to_discord("Trade window not found.") return False - - def trade_actions(): + log_and_print("Pressing 'Esc' key to ensure focus.") + subprocess.run(['xdotool', 'key', 'Escape']) + time.sleep(1) + right_click(2725, 1203) time.sleep(1) @@ -132,10 +139,11 @@ def trade_actions(): return True # Indicate that the trade action was successful - -focus_minecraft_window() - -for _ in range(40): # Number of trades to perform - result = trade_actions() - if not result: - break # Stop the script if trade window is not detected +# Main script execution +if not focus_minecraft_window(): + log_and_print("Minecraft window not detected. Stopping script.") +else: + for _ in range(40): # Number of trades to perform + result = trade_actions() + if not result: + break # Stop the script if trade window is not detected