import cv2 import pyautogui import numpy as np import time import telegram import asyncio bot = telegram . Bot ( token = '---' ) chat_id = 'chat id tg' # Загрузка изображений img_accept = cv2 . imread ( 'accept.png' , 0 ) img_ready = cv2 . imread ( 'ready.png' , 0 ) async def send_message_async ( chat_id , message ) : await bot . send_message ( chat_id = chat_id , text = message ) def locate_image ( template , threshold = 0.8 ) : screenshot = pyautogui . screenshot ( ) screenshot = np . array ( screenshot ) screenshot = cv2 . cvtColor ( screenshot , cv2 . COLOR_RGB2BGR ) screenshot_gray = cv2 . cvtColor ( screenshot , cv2 . COLOR_BGR2GRAY ) result = cv2 . matchTemplate ( screenshot_gray , template , cv2 . TM_CCOEFF_NORMED ) min_val , max_val , min_loc , max_loc = cv2 . minMaxLoc ( result ) if max_val >= threshold : return ( max_loc [ 0 ] , max_loc [ 1 ] ) else : return None async def main ( ) : while True : accept_loc = locate_image ( img_accept ) if accept_loc : message = f"Нашел игру. Корды:{accept_loc}" await send_message_async ( chat_id , message ) await asyncio . sleep ( 5 ) pyautogui . press ( 'ready' ) await asyncio . sleep ( 5 ) ready_loc = locate_image ( img_ready ) if ready_loc : message = f"Нашел готовность. Корды:{ready_loc}" await send_message_async ( chat_id , message ) await asyncio . sleep ( 5 ) pyautogui . press ( 'ready' ) await asyncio . sleep ( 5 ) asyncio . run ( main ( ) )