forked from DrakeHooks/CasinoClaim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjefebetAPI.py
More file actions
269 lines (236 loc) · 10.6 KB
/
jefebetAPI.py
File metadata and controls
269 lines (236 loc) · 10.6 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# Drake Hooks + WaterTrooper
# Casino Claim 2
# JefeBet API
import os
import asyncio
from typing import Optional, List
from dotenv import load_dotenv
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import (
TimeoutException,
NoSuchElementException,
ElementClickInterceptedException,
)
import discord
load_dotenv()
# ────────────────────────────────────────────────────────────
# JefeBet Helpers and Popup handling
# ────────────────────────────────────────────────────────────
def _present(driver, by, value, timeout=8):
return WebDriverWait(driver, timeout).until(EC.presence_of_element_located((by, value)))
def _clickable(driver, by, value, timeout=8):
return WebDriverWait(driver, timeout).until(EC.element_to_be_clickable((by, value)))
def _try_click_any_xpath(driver, xpaths: List[str], timeout_each=3) -> bool:
for xp in xpaths:
try:
btn = WebDriverWait(driver, timeout_each).until(
EC.element_to_be_clickable((By.XPATH, xp))
)
try:
btn.click()
except ElementClickInterceptedException:
driver.execute_script("arguments[0].click();", btn)
return True
except Exception:
continue
return False
POST_LOGIN_POPUP_XP = "/html/body/div[2]/div/div[2]/div[4]/a[2]"
async def check_and_close_popup(driver) -> bool:
"""Try to close the blocking popup if visible (best-effort)."""
try:
popup_close = WebDriverWait(driver, 6).until(
EC.element_to_be_clickable((By.XPATH, POST_LOGIN_POPUP_XP))
)
try:
popup_close.click()
except ElementClickInterceptedException:
driver.execute_script("arguments[0].click();", popup_close)
await asyncio.sleep(1.5)
print("[JefeBet] Popup closed.")
return True
except TimeoutException:
return False
async def ensure_post_login_popup_closed(driver) -> None:
"""
Stronger post-login guard:
1) Try to close popup
2) If not clickable, refresh as a fallback
3) Try once more after refresh
"""
closed = await check_and_close_popup(driver)
if closed:
return
# Fallback: refresh and retry
print("[JefeBet] Popup not clickable; refreshing as fallback…")
driver.refresh()
await asyncio.sleep(4)
await check_and_close_popup(driver)
def _is_logged_in(driver) -> bool:
"""Detect if already logged in."""
try:
driver.find_element(
By.XPATH,
"/html/body/app-root/app-main-header/div/div/div/div/header/div[1]/nav/div[2]/div/div[2]/nav/div/div[3]/button",
)
return True
except NoSuchElementException:
pass
try:
driver.find_element(By.CSS_SELECTOR, "header button[aria-label*='profile'], header img[alt*='avatar']")
return True
except NoSuchElementException:
return False
def _format_countdown(raw: str) -> Optional[str]:
"""Normalize countdown text to HH:MM:SS."""
if not raw:
return None
cleaned = raw.strip().replace(" ", ":")
parts = [p for p in cleaned.split(":") if p != ""]
parts = [p for p in parts if p.replace("0", "", 1).isdigit()]
if not parts:
return None
while len(parts) < 3:
parts.insert(0, "00")
return ":".join(parts[:3])
async def send_screenshot(channel: discord.abc.Messageable, driver, name="jefe.png"):
try:
driver.save_screenshot(name)
await channel.send(file=discord.File(name))
finally:
try:
if os.path.exists(name):
os.remove(name)
except Exception:
pass
# ────────────────────────────────────────────────────────────
# Main JefeBet Flow
# ────────────────────────────────────────────────────────────
async def jefebet_casino(ctx, driver, channel):
creds = os.getenv("JEFEBET")
if not creds:
await channel.send("JefeBet credentials not found in environment variables.")
return
username, password = creds.split(":", 1)
try:
print("[JefeBet] Navigating to site…")
driver.get("https://www.jefebet.com/")
await asyncio.sleep(6)
# (This popup is post-login, but best-effort in case site shows anything early)
await check_and_close_popup(driver)
if _is_logged_in(driver):
print("[JefeBet] Already logged in, skipping login.")
await claim_jefebet_bonus(ctx, driver, channel)
return
print("[JefeBet] Attempting to log in…")
try:
login_button = _clickable(
driver,
By.XPATH,
"/html/body/app-root/app-main-header/div/div/div/div/header/div[2]/div/button[2]",
timeout=8,
)
login_button.click()
await asyncio.sleep(1.0)
except TimeoutException:
print("[JefeBet] Login button not found; trying claim anyway.")
if _is_logged_in(driver):
await claim_jefebet_bonus(ctx, driver, channel)
return
await channel.send("JefeBet Authentication timed out, will try again later.")
await send_screenshot(channel, driver) # attach a screenshot for debugging
return
email_input = _present(driver, By.ID, "email", timeout=10)
password_input = _present(driver, By.ID, "password", timeout=10)
email_input.clear()
email_input.send_keys(username)
password_input.clear()
password_input.send_keys(password)
password_input.send_keys(Keys.ENTER)
print("[JefeBet] Submitted credentials.")
await asyncio.sleep(10)
# ── NEW: post-login popup handling with refresh fallback ───────────────
await ensure_post_login_popup_closed(driver)
print("[JefeBet] Login successful, proceeding to claim.")
await claim_jefebet_bonus(ctx, driver, channel)
except Exception as e:
print(f"[JefeBet] Login timeout/error: {e}")
await channel.send("JefeBet Authentication timed out, will try again later.")
try:
await send_screenshot(channel, driver)
except Exception as ss_e:
print(f"[JefeBet] Failed to send screenshot: {ss_e}")
# ────────────────────────────────────────────────────────────
# Claim Function
# ────────────────────────────────────────────────────────────
async def claim_jefebet_bonus(ctx, driver, channel):
try:
print("[JefeBet] Checking popups before claim…")
# Quick best-effort close
overlay_closed = await check_and_close_popup(driver)
if overlay_closed:
print("[JefeBet] Popup closed successfully.")
# If it's still there and clickable, refresh once before proceeding
still_present_clickable = _try_click_any_xpath(driver, [POST_LOGIN_POPUP_XP], timeout_each=1)
if still_present_clickable:
print("[JefeBet] Popup reappeared; refreshing page as fallback.")
driver.refresh()
await asyncio.sleep(4)
await check_and_close_popup(driver)
print("[JefeBet] Opening Get Coins menu…")
get_coins_xpath = (
"/html/body/app-root/app-main-header/div/div/div/div/header/div[1]/nav/div[2]/div/div[2]/nav/div/div[3]/button"
)
get_coins = _clickable(driver, By.XPATH, get_coins_xpath, timeout=10)
get_coins.click()
await asyncio.sleep(1.0)
print("[JefeBet] Opening Daily Bonus tab…")
daily_bonus = _clickable(driver, By.XPATH, '//*[@id="daily-bonus-tab"]', timeout=10)
daily_bonus.click()
await asyncio.sleep(1.0)
try:
print("[JefeBet] Attempting to click Claim button…")
claim_button = _clickable(
driver,
By.XPATH,
"//button[contains(@class, 'btn') and contains(@class, 'btn-red')]",
timeout=6,
)
claim_button.click()
await asyncio.sleep(1.0)
print("[JefeBet] Bonus claimed successfully!")
await channel.send("JefeBet 6-Hour Bonus Claimed!")
except TimeoutException:
print("[JefeBet] Claim button not found or already claimed.")
except Exception as e:
print(f"[JefeBet] Error during claim: {e}")
await channel.send(f"JefeBet claim error: {e}")
finally:
print("[JefeBet] Checking for countdown timer…")
await asyncio.sleep(1.0)
await check_and_close_popup(driver)
await asyncio.sleep(0.5)
countdown_xpaths = [
"/html/body/app-root/app-get-coin/div/div[2]/div/app-hourly-bonus/div/div/div[3]/div/label",
"/html/body/div[1]/div[2]/div/mat-dialog-container/div/div/app-get-coin/div/div[2]/div/app-hourly-bonus/div/div/div[3]/div/label",
"/html/body/div[2]/div[2]/div/mat-dialog-container/div/div/app-get-coin/div/div[2]/div/app-hourly-bonus/div/div/div[3]/div/label",
"/html/body/div[3]/div[2]/div/mat-dialog-container/div/div/app-get-coin/div/div[2]/div/app-hourly-bonus/div/div/div[5]/div/label",
]
countdown_text = None
for xp in countdown_xpaths:
try:
el = WebDriverWait(driver, 6).until(EC.presence_of_element_located((By.XPATH, xp)))
c_text = el.text.strip()
if c_text:
countdown_text = c_text
break
except Exception:
continue
formatted = _format_countdown(countdown_text or "")
if formatted:
print(f"[JefeBet] Next bonus available in {formatted}")
await channel.send(f"Next JefeBet Bonus Available in: {formatted}")
else:
print("[JefeBet] Countdown not found.")