-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
59 lines (49 loc) · 2.16 KB
/
Copy pathutils.py
File metadata and controls
59 lines (49 loc) · 2.16 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
import time
from typing import Dict, Any
class ValidationError(ValueError):
"""Exception raised for invalid autoclicker configurations."""
pass
class ClickProcessor:
"""Handles input validation and simulated execution for the autoclicker."""
VALID_BUTTONS = {"left", "right", "middle"}
def __init__(self):
self.running = False
def validate_inputs(self, config: Dict[str, Any]) -> Dict[str, Any]:
"""Validates execution configuration before running the click loop."""
validated = {}
# Validate interval limit (prevent division-by-zero or system freezes)
interval = config.get("interval", 0.1)
try:
interval = float(interval)
except (TypeError, ValueError):
raise ValidationError("Interval must be a valid float value")
if interval <= 0.001:
raise ValidationError("Interval must be greater than 0.001 seconds")
validated["interval"] = interval
# Validate target mouse button
button = str(config.get("button", "left")).lower()
if button not in self.VALID_BUTTONS:
raise ValidationError(f"Mouse button must be one of {self.VALID_BUTTONS}")
validated["button"] = button
# Validate click limits (0 means infinite clicking)
clicks = config.get("clicks", 0)
try:
clicks = int(clicks)
except (TypeError, ValueError):
raise ValidationError("Clicks count must be a valid integer")
if clicks < 0:
raise ValidationError("Clicks count cannot be negative")
validated["clicks"] = clicks
return validated
def execute_safely(self, raw_config: Dict[str, Any]) -> bool:
"""Runs validation and prepares the autoclicker execution loop."""
try:
clean_config = self.validate_inputs(raw_config)
self.running = True
# Simulated iteration using the validated values
print(f"Safe config validated: {clean_config}")
return True
except ValidationError as error:
print(f"Config rejected: {error}")
self.running = False
return False