1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
| import telebot.apihelper
from telebot import *
from selenium import webdriver as sel
from selenium.webdriver.common.by import By
from selenium.common.exceptions import *
from logging import WARNING
from time import sleep
options = sel.ChromeOptions()
#options.add_argument("--disable-gpu")
#options.add_argument('--headless')
drv = sel.Chrome(options)
bot = TeleBot("TOKEN", parse_mode="HTML")
vklogin = "LOGIN"
vkpass = "PASS"
def newthread(name: str = None):
def wrapper(func):
name_ = name
def wrapper_(*args, **kwargs):
nname = name_
try:
if (nname == None):
name = func.__name__
else:
name = str(nname)
if(len(args)>0):
if(hasattr(args[0], "from_user")):
threading.Thread(target=func, args=args, kwargs=kwargs,
name=(name+" by ID "+str(args[0].from_user.id))).start()
elif(hasattr(args[0], "message")):
threading.Thread(target=func, args=args, kwargs=kwargs,
name=(name + " by ID " + str(args[0].message.from_user.id))).start()
elif(isinstance(args[0], str)):
threading.Thread(target=func, args=args, kwargs=kwargs,
name=(name + " with URL " + str(args[0]))).start()
else:
raise AttributeError
else:
threading.Thread(target=func, args=args, kwargs=kwargs,
name=name).start()
except KeyboardInterrupt:
pass
return wrapper_
return wrapper
#drv.set_page_load_timeout(5)
class GetPage:
def __init__(self, url, time = 3, keep_alive = True):
self.url = url
self.time = time
self.alive = keep_alive
def __enter__(self):
for c,window in enumerate(drv.window_handles):
if(window==drv.current_window_handle):
break
drv.execute_script(f"window.open('{self.url}');")
drv.switch_to.window(drv.window_handles[c+1])
drv.implicitly_wait(self.time)
sleep(self.time)
print(f'Needed URL: {self.url}; Currect URL: "{drv.current_url}"')
self.window = drv.current_window_handle
return self.window
def __exit__(self, exc_type, exc_val, exc_tb):
if(not exc_tb == None):
print(f"GetPage error: [{exc_type.__name__}] {exc_val} {exc_tb}")
if(self.alive==False):
w = drv.current_window_handle
drv.switch_to.window(self.window)
drv.close()
#drv.switch_to.window(w)
del w
del self.url
del self.time
del self.window
del self
print(f"Agent: '{drv.execute_script('return navigator.userAgent')}'")
stop = True
@bot.message_handler(commands=["start"])
@newthread()
def Start(message: types.Message):
stop = False
mess = bot.send_message(message.chat.id, "Загрузка...", reply_to_message_id=message.message_id)
with GetPage("https://luckyduck.app", 2) as f:
main = None
forms = []
while(main==None):
main = drv.find_element(By.CLASS_NAME, "crash")
sleep(0.2)
forms = main.find_elements(By.CLASS_NAME, "crash-form")
form1, form2 = forms[0], forms[1]
bet1, auto1, play1 = form1.find_elements(By.CLASS_NAME, "game-form")[0], \
form1.find_elements(By.CLASS_NAME, "game-form")[1], \
form1.find_element(By.CLASS_NAME, "game-form-button")
bet2, auto2, play2 = form2.find_elements(By.CLASS_NAME, "game-form")[0], \
form2.find_elements(By.CLASS_NAME, "game-form")[1], \
form2.find_element(By.CLASS_NAME, "game-form-button")
markup = types.InlineKeyboardMarkup()
markup.row(types.InlineKeyboardButton("Ставка 1", callback_data="bet1"),
types.InlineKeyboardButton("Авто-вывод 1", callback_data="auto1"))
markup.row(types.InlineKeyboardButton("Ставка 2", callback_data="bet2"),
types.InlineKeyboardButton("Авто-вывод 2", callback_data="auto2"))
markup.row(types.InlineKeyboardButton("Играть 1", callback_data="play1"),
types.InlineKeyboardButton("Играть 2", callback_data="play2"))
balance = drv.find_elements(By.CLASS_NAME, "navbar-balance")
if(not balance == []):
cash = balance[0].find_elements(By.CLASS_NAME, 'amount')[0].find_element(By.TAG_NAME, 'span').text.strip()
else:
bot.edit_message_text("Авторизация VK...", mess.chat.id, mess.message_id)
drv.find_element(By.CLASS_NAME,"navbar-authorization").find_elements(By.CLASS_NAME,"btn-wrapper")[1].find_element(By.TAG_NAME,"button").click()
sleep(0.5)
drv.find_element(By.CLASS_NAME, "login-basic-methods__item_vkontakte").click()
sleep(5)
for c, window in enumerate(drv.window_handles):
if (window == drv.current_window_handle):
break
drv.switch_to.window(drv.window_handles[c+1])
i = drv.find_elements(By.TAG_NAME, "input")
while(i==[]):
i = drv.find_elements(By.TAG_NAME, "input")
sleep(0.1)
i = i[0]
i.click()
i.send_keys(vklogin)
drv.find_element(By.CLASS_NAME, "vkc__DefaultSkin__button").find_elements(By.TAG_NAME, "button")[0].click()
sleep(1)
i = drv.find_element(By.XPATH, "/html/body/div[1]/div/div/div/div/div[1]/div/div/div/div/form/div[1]/div[3]/div/div/input")
i.click()
i.send_keys(vkpass)
drv.find_element(By.CLASS_NAME, "vkc__EnterPasswordNoUserInfo__buttonWrap").find_element(By.TAG_NAME, "button").click()
sleep(1)
drv.find_element(By.CLASS_NAME, "vkc__AcceptPrivacyPolicy__content").find_elements(By.TAG_NAME, "button")[1].click()
bot.edit_message_text("Авторизация VK успешна. Загрузка стартовой страницы...", mess.chat.id, mess.message_id)
sleep(3)
drv.switch_to.window(f)
while(balance == []):
balance = drv.find_elements(By.CLASS_NAME, "navbar-balance")
sleep(0.5)
cash = balance[0].find_elements(By.CLASS_NAME, 'amount')[0].find_element(By.TAG_NAME, 'span').text.strip()
bot.edit_message_text("Получение данных...", mess.chat.id, mess.message_id)
sleep(0.1)
main.find_element(By.XPATH, "/html/body/div[1]/div/div/div[6]/div[1]/div/div/div[2]/div[1]/div[1]/div/div[2]/div[1]/div/button").click()
while(True):
try:
cash = balance[0].find_elements(By.CLASS_NAME, 'amount')[0].find_element(By.TAG_NAME,
'span').text.strip()
text = f"{'Кошелек':27}| {cash} ₽\n" \
f"{'Ставка 1':29}| {bet1.get_attribute('value').strip()} ₽\n" \
f"{'Авто-вывод 1':23}| X{auto1.get_attribute('value').strip()}\n" \
f"{'Ставка 2':29}| {bet2.get_attribute('value').strip()} ₽\n" \
f"{'Авто-вывод 2':23}| X{auto2.get_attribute('value').strip()}\n" \
f"{'Пинг':32}| {main.find_element(By.CLASS_NAME, 'crash-chart-network__ping').text}\n"
if (not (main.find_element(By.XPATH, "/html/body/div[1]/div/div/div[6]/div[1]/div/div/div[2]/div[1]/div[1]/div/div[2]/div[2]/div/div[3]/div[1]/strong").text.strip() == "" or main.find_element(By.XPATH, "/html/body/div[1]/div/div/div[6]/div[1]/div/div/div[2]/div[1]/div[1]/div/div[2]/div[2]/div/div[3]/div[1]/strong").text.strip() == "00:00")):
text += f"{'Обратный отсчет':16}| {main.find_element(By.XPATH, '/html/body/div[1]/div/div/div[6]/div[1]/div/div/div[2]/div[1]/div[1]/div/div[2]/div[2]/div/div[2]/div[1]/strong').text.strip()}\n"
else:
text += f"{'Высота':29}| {main.find_element(By.XPATH, '/html/body/div[1]/div/div/div[6]/div[1]/div/div/div[2]/div[1]/div[1]/div/div[2]/div[2]/div/div[3]/div[1]/strong').text.strip()}\n" \
f"{'Время':29}| {main.find_element(By.XPATH, '/html/body/div[1]/div/div/div[6]/div[1]/div/div/div[2]/div[1]/div[1]/div/div[2]/div[2]/div/div[3]/div[3]/strong').text.strip()}\n"
text += f"{'История':27}| "
text_old = "Загрузка..."
while (True):
try:
history = main.find_element(By.XPATH,
"/html/body/div[1]/div/div/div[6]/div[1]/div/div/div[2]/div[1]/div[1]/div/div[2]/div[1]/div/div").find_elements(
By.TAG_NAME, "div")
text_ = ""
for c, div in enumerate(history, 1):
if (not div.text.strip() == ""):
if (c > 1):
text_ += ", "
text_ += f"{div.text.strip()}"
text_old = text_
break
except (StaleElementReferenceException, NoSuchElementException):
text_ = text_old
text_ += "\n"
text += text_
text += f"{'Игроков':28}| {main.find_element(By.XPATH, '/html/body/div[1]/div/div/div[6]/div[1]/div/div/div[2]/div[2]/div/div[1]/div[1]/div[2]/span/span').text.strip()}\n" \
f"{'Сумма':29}| {main.find_element(By.XPATH, '/html/body/div[1]/div/div/div[6]/div[1]/div/div/div[2]/div[2]/div/div[1]/div[2]/div[2]/span/span/span').text.strip()}"
bot.edit_message_text(text, mess.chat.id, mess.message_id,reply_markup=markup)
except (telebot.apihelper.ApiTelegramException, NoSuchElementException):
continue
print("start")
bot.infinity_polling(timeout=180, long_polling_timeout=360, logger_level=WARNING) |