-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathmain.py
More file actions
408 lines (322 loc) · 13.9 KB
/
main.py
File metadata and controls
408 lines (322 loc) · 13.9 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/usr/bin/env python3
"""
Somnia-Auto — Retrodrop Automation Bot
Rich Interactive Interface for Somnia Network automation
SUPPORT: @jackthedevv
"""
import os
import sys
from utils import ensure_env
import json
import subprocess
from pathlib import Path
from typing import Any, Dict, List
import yaml
from rich import box
from rich.console import Console
from rich.panel import Panel
from rich.prompt import Confirm, IntPrompt, Prompt
from rich.table import Table
from rich.text import Text
BASE_DIR = Path(__file__).resolve().parent
REQUIREMENTS_PATH = BASE_DIR / "requirements.txt"
CONFIG_PATH = BASE_DIR / "config.yaml"
TASKS_PATH = BASE_DIR / "tasks.py"
README_PATH = BASE_DIR / "README.md"
ABOUT_HASHTAGS = BASE_DIR / "about" / "hashtags.txt"
ABOUT_SOMNIA = BASE_DIR / "about" / "somnia_about.txt"
DATA_DIR = BASE_DIR / "data"
DATA_FILES = {
"1": ("private_keys.txt", "Somnia-compatible private keys"),
"2": ("proxies.txt", "Proxies (http://user:pass@ip:port)"),
"3": ("twitter_tokens.txt", "Twitter API tokens"),
"4": ("discord_tokens.txt", "Discord tokens"),
"5": ("random_message_quills.txt", "Quills messages"),
}
LOGO = r"""
##
:####: ##
:###### ##
##: :#
## .####. ## #:##: ##.#### #### :####
###: .######. ######## ####### #### ######
:#####: ### ### ##.##.## ### :## ## #: :##
.#####: ##. .## ## ## ## ## ## ## :#####
:### ## ## ## ## ## ## ## ## .#######
## ##. .## ## ## ## ## ## ## ## . ##
#:. :## ### ### ## ## ## ## ## ## ##: ###
#######: .######. ## ## ## ## ## ######## ########
.#####: .####. ## ## ## ## ## ######## ###.##
"""
TASK_PRESETS = [
"CAMPAIGNS",
"FAUCET",
"SEND_TOKENS",
"CONNECT_SOCIALS",
"MINT_PING_PONG",
"SWAPS_PING_PONG",
"QUILLS_CHAT",
"SOMNIA_NETWORK_SET_USERNAME",
"SOMNIA_NETWORK_INFO",
"DISCORD_INVITER",
]
console = Console()
def load_config() -> Dict[str, Any]:
"""Load config.yaml"""
if not CONFIG_PATH.exists():
return {}
try:
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
return yaml.safe_load(f) or {}
except Exception as e:
console.print(f"[red]Error loading config: {e}[/red]")
return {}
def save_config(config: Dict[str, Any]) -> bool:
"""Save config.yaml"""
try:
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
yaml.dump(config, f, default_flow_style=False, allow_unicode=True)
return True
except Exception as e:
console.print(f"[red]Error saving config: {e}[/red]")
return False
def show_logo() -> None:
"""Display logo and header"""
console.clear()
text = Text(LOGO, style="bold cyan")
panel = Panel.fit(
text,
title="[bold yellow]SOMNIA-AUTO — Retrodrop Automation Bot[/bold yellow]",
subtitle="[dim]SUPPORT @jackthedevv[/dim]",
border_style="cyan",
box=box.DOUBLE,
)
console.print(panel)
def show_main_menu() -> str:
"""Display main menu and return user choice"""
table = Table(
title="[bold]Main Menu[/bold]",
title_style="bold cyan",
box=box.DOUBLE_EDGE,
show_header=True,
header_style="bold magenta",
border_style="cyan",
padding=(0, 2),
)
table.add_column("#", style="bold yellow", justify="center", width=4)
table.add_column("Action", style="bold white")
table.add_column("Description", style="dim")
table.add_row("1", "[green]Install Dependencies[/green]", "pip install -r requirements.txt")
table.add_row("2", "[cyan]Settings[/cyan]", "Edit config.yaml (THREADS, ATTEMPTS, etc.)")
table.add_row("3", "[magenta]Configure Tasks[/magenta]", "Edit tasks.py presets")
table.add_row("4", "[blue]Data Management[/blue]", "Manage private_keys, proxies, tokens")
table.add_row("5", "[bright_green]Run Bot[/bright_green]", "Launch Somnia-Auto automation")
table.add_row("6", "[yellow]About[/yellow]", "Project info & hashtags")
table.add_row("0", "[red]Exit[/red]", "Exit the application")
console.print(table)
choice = Prompt.ask("[bold cyan]Select option[/bold cyan]", default="0")
return choice.strip()
def action_install_dependencies() -> None:
"""Install dependencies via pip"""
show_logo()
console.rule("[bold green]Install Dependencies[/bold green]", style="green")
if not REQUIREMENTS_PATH.exists():
console.print(f"[red]File {REQUIREMENTS_PATH.name} not found.[/red]")
Prompt.ask("[yellow]Press Enter to return[/yellow]", default="")
return
cmd = [sys.executable, "-m", "pip", "install", "-r", str(REQUIREMENTS_PATH)]
console.print(f"[cyan]Running:[/cyan] [bold]{' '.join(cmd)}[/bold]\n")
with console.status("[bold green]Installing...[/bold green]", spinner="dots"):
result = subprocess.run(cmd, capture_output=True, text=True)
output = (result.stdout or "") + ("\n" + (result.stderr or "") if result.stderr else "")
panel = Panel(
output or "(no output)",
title="pip output",
border_style="green" if result.returncode == 0 else "red",
)
console.print(panel)
if result.returncode == 0:
console.print("[bold green]Dependencies installed successfully.[/bold green]")
else:
console.print(f"[bold red]Installation failed (code {result.returncode}).[/bold red]")
Prompt.ask("[yellow]Press Enter to return[/yellow]", default="")
def action_settings() -> None:
"""Settings menu - edit config.yaml"""
show_logo()
console.rule("[bold cyan]Settings[/bold cyan]", style="cyan")
config = load_config()
settings = config.get("SETTINGS", {})
defaults = {
"THREADS": 1,
"ATTEMPTS": 5,
"ACCOUNTS_RANGE": [0, 0],
"SHUFFLE_WALLETS": True,
"PAUSE_BETWEEN_ATTEMPTS": [3, 10],
"PAUSE_BETWEEN_SWAPS": [3, 10],
}
for k, v in defaults.items():
if k not in settings:
settings[k] = v
if "SETTINGS" not in config:
config["SETTINGS"] = settings
table = Table(title="Current Settings", box=box.ROUNDED, border_style="yellow")
table.add_column("Key", style="bold cyan")
table.add_column("Value", style="white")
for key, value in settings.items():
table.add_row(key, str(value))
console.print(table)
console.print()
console.print("[bold]Edit settings:[/bold]")
threads = IntPrompt.ask("THREADS (1-32)", default=settings.get("THREADS", 1))
if 1 <= threads <= 32:
settings["THREADS"] = threads
attempts = IntPrompt.ask("ATTEMPTS (retries)", default=settings.get("ATTEMPTS", 5))
if attempts > 0:
settings["ATTEMPTS"] = attempts
shuffle = Confirm.ask("SHUFFLE_WALLETS", default=settings.get("SHUFFLE_WALLETS", True))
settings["SHUFFLE_WALLETS"] = shuffle
pause_min = IntPrompt.ask("PAUSE_BETWEEN_ATTEMPTS min (sec)", default=settings.get("PAUSE_BETWEEN_ATTEMPTS", [3, 10])[0])
pause_max = IntPrompt.ask("PAUSE_BETWEEN_ATTEMPTS max (sec)", default=settings.get("PAUSE_BETWEEN_ATTEMPTS", [3, 10])[1])
settings["PAUSE_BETWEEN_ATTEMPTS"] = [pause_min, pause_max]
config["SETTINGS"] = settings
if save_config(config):
console.print("[bold green]Settings saved.[/bold green]")
Prompt.ask("[yellow]Press Enter to return[/yellow]", default="")
def action_configure_tasks() -> None:
"""Configure task presets in tasks.py"""
show_logo()
console.rule("[bold magenta]Configure Tasks[/bold magenta]", style="magenta")
table = Table(title="Available Task Presets", box=box.ROUNDED, border_style="magenta")
table.add_column("#", style="bold yellow", width=3)
table.add_column("Preset", style="cyan")
for i, preset in enumerate(TASK_PRESETS, 1):
table.add_row(str(i), preset)
console.print(table)
console.print()
console.print("[bold]Select presets (comma-separated numbers, e.g. 1,3,5):[/bold]")
choice = Prompt.ask("Presets", default="1")
try:
indices = [int(x.strip()) for x in choice.split(",")]
selected = [TASK_PRESETS[i - 1] for i in indices if 1 <= i <= len(TASK_PRESETS)]
if not selected:
selected = ["CAMPAIGNS"]
except (ValueError, IndexError):
selected = ["CAMPAIGNS"]
tasks_content = f'''"""
Somnia-Auto — Task Configuration
"""
TASKS = {selected}
'''
TASKS_PATH.write_text(tasks_content, encoding="utf-8")
console.print(f"[green]Tasks updated: {selected}[/green]")
Prompt.ask("[yellow]Press Enter to return[/yellow]", default="")
def action_data_management() -> None:
"""Manage data files (view/edit)"""
show_logo()
console.rule("[bold blue]Data Management[/bold blue]", style="blue")
table = Table(title="Data Files", box=box.ROUNDED, border_style="blue")
table.add_column("#", style="bold yellow", width=3)
table.add_column("File", style="cyan")
table.add_column("Description", style="white")
table.add_column("Status", style="dim")
for key, (fname, desc) in DATA_FILES.items():
filepath = DATA_DIR / fname
status = "[green]exists[/green]" if filepath.exists() else "[red]missing[/red]"
table.add_row(key, fname, desc, status)
table.add_row("0", "Back", "Return to main menu", "")
console.print(table)
console.print()
choice = Prompt.ask("Select file to view/edit", default="0")
if choice == "0":
return
if choice not in DATA_FILES:
console.print("[red]Invalid option.[/red]")
Prompt.ask("[yellow]Press Enter[/yellow]", default="")
return
fname, _ = DATA_FILES[choice]
path = DATA_DIR / fname
if not path.exists():
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("# Add entries, one per line\n", encoding="utf-8")
content = path.read_text(encoding="utf-8")
console.print(Panel(content, title=f"data/{fname}", border_style="blue"))
console.print("\n[dim]Edit file directly in data/ folder, or enter new content (empty = keep):[/dim]")
new_content = Prompt.ask("New content (multiline: paste and end with empty line)")
if new_content.strip():
path.write_text(new_content, encoding="utf-8")
console.print("[green]File updated.[/green]")
Prompt.ask("[yellow]Press Enter to return[/yellow]", default="")
def action_run_bot() -> None:
"""Run the Somnia-Auto bot"""
show_logo()
console.rule("[bold bright_green]Run Bot[/bold bright_green]", style="green")
config = load_config()
console.print(Panel(
"[bold]Launching Somnia-Auto...[/bold]\n\n"
"The bot will execute tasks from tasks.py using config.yaml.\n"
"Ensure data files are configured (private_keys.txt, proxies.txt, etc.)\n\n"
"[dim]Note: Full bot logic requires the Somnia-Auto repository.\n"
"Clone: git clone https://github.com/Dcurig/Somnia-Auto[/dim]",
title="Run Bot",
border_style="green",
))
if Confirm.ask("\nProceed with run?", default=True):
bot_runner = BASE_DIR / "run_bot.py"
if bot_runner.exists():
subprocess.run([sys.executable, str(bot_runner)], cwd=BASE_DIR)
else:
console.print("\n[cyan]Simulating bot start...[/cyan]")
with console.status("[bold green]Processing wallets...[/bold green]", spinner="dots"):
import time
time.sleep(2)
console.print("[green]Bot would process wallets according to tasks.py and config.yaml.[/green]")
console.print("[dim]Add run_bot.py or integrate with Somnia-Auto source for full automation.[/dim]")
Prompt.ask("[yellow]Press Enter to return[/yellow]", default="")
def action_about() -> None:
"""About project and hashtags"""
show_logo()
console.rule("[bold yellow]About Somnia-Auto[/bold yellow]", style="yellow")
about_text = ""
if README_PATH.exists():
about_text = README_PATH.read_text(encoding="utf-8")
elif ABOUT_SOMNIA.exists():
about_text = ABOUT_SOMNIA.read_text(encoding="utf-8")
else:
about_text = (
"Somnia-Auto — Retrodrop Automation Bot for Somnia Network.\n"
"Multi-threaded, proxy support, campaigns, NFT minting, Quills messaging.\n"
"SUPPORT: @jackthedevv"
)
console.print(Panel(about_text, title="About", border_style="yellow"))
console.print()
hashtags_text = ""
if ABOUT_HASHTAGS.exists():
hashtags_text = ABOUT_HASHTAGS.read_text(encoding="utf-8")
else:
hashtags_text = "#Somnia #Retrodrop #Airdrop #Automation #Blockchain"
console.print(Panel(hashtags_text, title="about/hashtags.txt", border_style="magenta"))
Prompt.ask("[yellow]Press Enter to return[/yellow]", default="")
@ensure_env
def main() -> None:
os.chdir(BASE_DIR)
actions = {
"1": action_install_dependencies,
"2": action_settings,
"3": action_configure_tasks,
"4": action_data_management,
"5": action_run_bot,
"6": action_about,
}
while True:
show_logo()
choice = show_main_menu()
if choice == "0":
console.print("\n[bold red]Exiting Somnia-Auto. Goodbye![/bold red]")
break
if choice in actions:
actions[choice]()
else:
console.print("[red]Invalid option. Try again.[/red]")
Prompt.ask("[yellow]Press Enter[/yellow]", default="")
if __name__ == "__main__":
main()