lobby_adapter: Rueckfall klickt echt (CGEvent) statt JS, Join-Knopf ueber Zeile
This commit is contained in:
+77
-2
@@ -229,11 +229,11 @@ def _lobby_buyin(frist=10.0):
|
||||
for _ in range(max(1, int(frist / 0.5))):
|
||||
knoepfe = _knoepfe()
|
||||
if "claim chips" in knoepfe and not bestaetigt:
|
||||
cdp_ausfuehren(["--click", "Claim Chips"])
|
||||
_klick_echt(_text_selektor("claim chips"), "Claim Chips")
|
||||
time.sleep(0.6)
|
||||
continue
|
||||
if "buy-in" in knoepfe:
|
||||
cdp_ausfuehren(["--click", "Buy-In"])
|
||||
_klick_echt(_text_selektor("buy-in"), "Buy-In")
|
||||
bestaetigt = True
|
||||
time.sleep(1.0)
|
||||
continue
|
||||
@@ -243,6 +243,78 @@ def _lobby_buyin(frist=10.0):
|
||||
return bestaetigt
|
||||
|
||||
|
||||
def _fenster_versatz():
|
||||
"""(x, y) des Lobby-Fensters plus Fensterleiste - fuer ECHTE Klicks.
|
||||
|
||||
Warum nicht `element.click()` per JS: der Client haengt an React-Ereignissen; ein
|
||||
synthetischer JS-Klick loest sie nicht zuverlaessig aus, ein echter Mausklick schon."""
|
||||
import sys as _s, os as _o
|
||||
for _p in (_o.path.dirname(_o.path.dirname(_o.path.abspath(__file__))),
|
||||
_o.path.join(_o.path.dirname(_o.path.dirname(_o.path.abspath(__file__))), "hand")):
|
||||
if _p not in _s.path:
|
||||
_s.path.insert(0, _p)
|
||||
import fenster as _f
|
||||
fenster_liste = [f for f in _f.alle() if f.get("rect") and f.get("titel") == "CoinPoker"]
|
||||
if not fenster_liste:
|
||||
return (0, 0)
|
||||
f = fenster_liste[0]
|
||||
x, y, b, h = f["rect"]
|
||||
try:
|
||||
innen = json.loads(cdp_ausfuehren(["--eval",
|
||||
"JSON.stringify({w: window.innerWidth, h: window.innerHeight})"]) or "{}")
|
||||
except Exception:
|
||||
innen = {}
|
||||
rand_oben = max(0.0, h - float(innen.get("h") or h))
|
||||
rand_links = max(0.0, (b - float(innen.get("w") or b)) / 2)
|
||||
return (x + rand_links, y + rand_oben)
|
||||
|
||||
|
||||
def _klick_echt(was, beschreibung=None):
|
||||
"""Ein Element per ECHTEM Mausklick treffen (Selektor oder Knopftext). -> bool."""
|
||||
js = """(() => {
|
||||
const e = %s;
|
||||
if (!e) return null;
|
||||
e.scrollIntoView({block: "center"});
|
||||
const r = e.getBoundingClientRect();
|
||||
return JSON.stringify({x: r.left + r.width / 2, y: r.top + r.height / 2});
|
||||
})()""" % was
|
||||
try:
|
||||
mitte = json.loads(cdp_ausfuehren(["--eval", js]) or "null")
|
||||
except Exception:
|
||||
mitte = None
|
||||
if not mitte:
|
||||
return False
|
||||
import sys as _s, os as _o, time as _t
|
||||
for _p in (_o.path.join(_o.path.dirname(_o.path.dirname(_o.path.abspath(__file__))), "hand"),):
|
||||
if _p not in _s.path:
|
||||
_s.path.insert(0, _p)
|
||||
import ctypes as _ct
|
||||
AS = _ct.CDLL("/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices")
|
||||
AS.CGEventCreateMouseEvent.restype = _ct.c_void_p
|
||||
AS.CGEventCreateMouseEvent.argtypes = [_ct.c_void_p, _ct.c_uint32, _ct.c_void_p, _ct.c_uint32]
|
||||
|
||||
class _P(_ct.Structure):
|
||||
_fields_ = [("x", _ct.c_double), ("y", _ct.c_double)]
|
||||
|
||||
dx, dy = _fenster_versatz()
|
||||
px, py = int(dx + mitte["x"]), int(dy + mitte["y"])
|
||||
p_ = _P(px, py)
|
||||
AS.CGEventPost(0, _ct.c_void_p(AS.CGEventCreateMouseEvent(None, 5, _ct.byref(p_), 0))) # hin
|
||||
_t.sleep(0.25)
|
||||
for art in (1, 2): # druecken, loslassen
|
||||
AS.CGEventPost(0, _ct.c_void_p(AS.CGEventCreateMouseEvent(None, art, _ct.byref(p_), 0)))
|
||||
_t.sleep(0.09)
|
||||
_t.sleep(0.4)
|
||||
return True
|
||||
|
||||
|
||||
def _text_selektor(text):
|
||||
"""Selektor fuer einen Knopf mit diesem Text (sprachunabhaengig ueber aria-label/text)."""
|
||||
return ('[...document.querySelectorAll("button,[role=button],.ui-clickable")]'
|
||||
'.find(n => ((n.getAttribute("aria-label")||"") + " " + (n.innerText||""))'
|
||||
'.trim().toLowerCase().includes(%s))' % json.dumps(text.lower()))
|
||||
|
||||
|
||||
def reiter_waehlen(reiter):
|
||||
"""Erst schauen, dann klicken: ist der Reiter aktiv, kein Klick. Sonst klicken und prüfen, dass
|
||||
er es wurde. -> (ok, Text). Bleibt ein anderer Reiter aktiv, ist das ein Fehlschlag; ist keiner
|
||||
@@ -386,6 +458,9 @@ def tisch_oeffnen(reiter, name=None, guthaben=None, sitzt_schon=0, band=None, me
|
||||
# Vor jedem Versuch frisch zaehlen - ein voriger Versuch kann ein Fenster geoeffnet haben.
|
||||
vorher = len(fenster.tischfenster())
|
||||
res = cdp_ausfuehren(["--eval", KLICK_ZEILE.replace("__ID__", kandidat["id"])])
|
||||
time.sleep(0.5)
|
||||
# Die Zeile waehlt nur AUS - der Knopf heisst "Join" und steht rechts. Echter Klick.
|
||||
_klick_echt(_text_selektor("join"), "Join")
|
||||
# Der Beitritt haengt einen Lobby-Dialog nach (Claim Chips, Buy-In) - erst der oeffnet den Tisch.
|
||||
_lobby_buyin()
|
||||
time.sleep(1.5)
|
||||
|
||||
Reference in New Issue
Block a user