Показать сообщение отдельно

  #14  
Старый 05.01.2024, 16:55
swap commends
Познающий
Регистрация: 02.03.2023
Сообщений: 50
С нами: 1685939

Репутация: 13
По умолчанию

Python:





Код:
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
(
)
)


Цитата:

Exception ignored in:
Traceback (most recent call last):
File "C:\Users\adm1n\AppData\Local\Programs\Python\Pyth on310\lib\asyncio\proactor_events.py", line 116, in __del__
File "C:\Users\adm1n\AppData\Local\Programs\Python\Pyth on310\lib\asyncio\proactor_events.py", line 108, in close
File "C:\Users\adm1n\AppData\Local\Programs\Python\Pyth on310\lib\asyncio\base_events.py", line 745, in call_soon
File "C:\Users\adm1n\AppData\Local\Programs\Python\Pyth on310\lib\asyncio\base_events.py", line 510, in _check_closed
RuntimeError: Event loop is closed
 
Ответить с цитированием