 |
|

03.01.2024, 15:52
|
|
Участник форума
Регистрация: 31.12.2022
Сообщений: 201
С нами:
1774087
Репутация:
33
|
|
Сообщение от swap commends
а как реализовать что бы после нажатия на кнопку, отправлялось сообщение в тг?
code:
Сообщение от Спойлер
test.py:
Код:
import
cv2
import
pyautogui
import
numpy
as
np
import
time
import
telegram
import
asyncio
bot
=
telegram
.
Bot
(
token
=
'token tg'
)
chat_id
=
'chat id tg'
# Загрузка изображений
img_vosem
=
cv2
.
imread
(
'vosem.png'
,
0
)
img_dva
=
cv2
.
imread
(
'dva.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
:
vosem_loc
=
locate_image
(
img_vosem
)
if
vosem_loc
:
message
=
f"Нашел 8. Корды:{vosem_loc}"
await
send_message_async
(
chat_id
,
message
)
time
.
sleep
(
5
)
pyautogui
.
press
(
'8'
)
time
.
sleep
(
5
)
dva_loc
=
locate_image
(
img_dva
)
if
dva_loc
:
message
=
f"Нашел 2. Корды:{dva_loc}"
await
send_message_async
(
chat_id
,
message
)
time
.
sleep
(
5
)
pyautogui
.
press
(
'2'
)
time
.
sleep
(
5
)
loop
=
asyncio
.
get_event_loop
(
)
loop
.
run_until_complete
(
main
(
)
)
|
|
|

04.01.2024, 22:13
|
|
Познающий
Регистрация: 02.03.2023
Сообщений: 50
С нами:
1685939
Репутация:
13
|
|
Сообщение от teensik
Сообщение от teensik
bot = telegram.Bot(token='token tg')
AttributeError: module 'telegram' has no attribute 'Bot'
Сообщение от teensik
# Загрузка изображений
img_vosem = cv2.imread('vosem.png', 0)
img_dva = cv2.imread('dva.png', 0)
я же могу тут вставить адресс скриншота где у меня он лежит?
|
|
|

05.01.2024, 01:43
|
|
Участник форума
Регистрация: 31.12.2022
Сообщений: 201
С нами:
1774087
Репутация:
33
|
|
Сообщение от swap commends
AttributeError: module 'telegram' has no attribute 'Bot'
pip install python-telegram-bot
Сообщение от swap commends
я же могу тут вставить адресс скриншота где у меня он лежит?
скрин должен лежать там же, где и скрипт, просто замени название
|
|
|

05.01.2024, 16:55
|
|
Познающий
Регистрация: 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
|
|
|

05.01.2024, 18:56
|
|
Участник форума
Регистрация: 31.12.2022
Сообщений: 201
С нами:
1774087
Репутация:
33
|
|
Сообщение от swap commends
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
(
)
)
дай тг свой
|
|
|
|
 |
|
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|