-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathconfig_manager.py
More file actions
137 lines (108 loc) · 3.94 KB
/
config_manager.py
File metadata and controls
137 lines (108 loc) · 3.94 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
"""
Configuration file helpers for Dawn Validator BOT.
Handles:
- emails.txt
- captcha_key.txt
- proxy.txt
- tokens.json
"""
from __future__ import annotations
import json
from pathlib import Path
from typing import Dict, List, Optional
from ui import info, warn, error
BASE_DIR = Path(__file__).resolve().parent
EMAILS_FILE = BASE_DIR / "emails.txt"
CAPTCHA_FILE = BASE_DIR / "captcha_key.txt"
PROXY_FILE = BASE_DIR / "proxy.txt"
TOKENS_FILE = BASE_DIR / "tokens.json"
def _ensure_file(path: Path, header_comment: Optional[str] = None) -> None:
if path.exists():
return
content = ""
if header_comment:
content = f"# {header_comment}\n"
path.write_text(content, encoding="utf-8")
def configure_emails_interactive() -> None:
info("Configuring emails.txt")
_ensure_file(
EMAILS_FILE,
header_comment="One email per line. Example: your_email_address_1",
)
emails: List[str] = []
warn("Enter email addresses (empty line to finish):")
while True:
value = input("Email: ").strip()
if not value:
break
emails.append(value)
if not emails:
warn("Email addresses unchanged (nothing entered).")
return
EMAILS_FILE.write_text("\n".join(emails) + "\n", encoding="utf-8")
info(f"Saved {len(emails)} email(s) to {EMAILS_FILE.name}.")
def configure_captcha_key_interactive() -> None:
info("Configuring captcha_key.txt (2captcha key)")
_ensure_file(
CAPTCHA_FILE,
header_comment="2captcha key. Example: your_2captcha_key",
)
value = input("Enter your 2captcha key: ").strip()
if not value:
warn("Key unchanged (empty input).")
return
CAPTCHA_FILE.write_text(value + "\n", encoding="utf-8")
info(f"Key saved to {CAPTCHA_FILE.name}.")
def configure_proxies_interactive() -> None:
info("Configuring proxy.txt")
_ensure_file(
PROXY_FILE,
header_comment=(
"One proxy per line. Examples:\n"
"192.168.1.1:8080\n"
"http://192.168.1.1:8080\n"
"http://username:password@192.168.1.1:8080"
),
)
proxies: List[str] = []
warn("Enter proxies (empty line to finish):")
while True:
value = input("Proxy: ").strip()
if not value:
break
proxies.append(value)
if not proxies:
warn("Proxies unchanged (nothing entered).")
return
PROXY_FILE.write_text("\n".join(proxies) + "\n", encoding="utf-8")
info(f"Saved {len(proxies)} proxy(ies) to {PROXY_FILE.name}.")
def read_emails() -> List[str]:
if not EMAILS_FILE.exists():
warn("emails.txt not found. Create it via Settings.")
return []
data = EMAILS_FILE.read_text(encoding="utf-8").splitlines()
return [line.strip() for line in data if line.strip() and not line.startswith("#")]
def read_captcha_key() -> Optional[str]:
if not CAPTCHA_FILE.exists():
warn("captcha_key.txt not found. Create it via Settings.")
return None
value = CAPTCHA_FILE.read_text(encoding="utf-8").strip()
return value or None
def read_proxies() -> List[str]:
if not PROXY_FILE.exists():
warn("proxy.txt not found. Create it via Settings.")
return []
data = PROXY_FILE.read_text(encoding="utf-8").splitlines()
return [line.strip() for line in data if line.strip() and not line.startswith("#")]
def save_tokens(tokens: Dict[str, str]) -> None:
TOKENS_FILE.write_text(json.dumps(tokens, indent=2, ensure_ascii=False), encoding="utf-8")
info(f"Saved tokens for {len(tokens)} accounts to {TOKENS_FILE.name}.")
def load_tokens() -> Dict[str, str]:
if not TOKENS_FILE.exists():
error("tokens.json not found. Run Setup (automatic token retrieval) first.")
return {}
try:
return json.loads(TOKENS_FILE.read_text(encoding="utf-8"))
except json.JSONDecodeError:
error("Failed to read tokens.json — file is corrupted.")
return {}