-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
355 lines (310 loc) · 13.5 KB
/
Copy pathmain.py
File metadata and controls
355 lines (310 loc) · 13.5 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
#!/usr/bin/env python3
"""
NatsukiSpammerDroid - Kivy mobile client for PocketMine-MP bot.
Mirrors the desktop PyQt5 GUI using Kivy for Android deployment.
"""
import sys
import os
import io
import queue
import threading
import importlib
import time
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.checkbox import CheckBox
from kivy.uix.radio_button import RadioButton
from kivy.uix.spinner import Spinner
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.metrics import dp
from kivy.properties import StringProperty, BooleanProperty
from kivy.utils import platform
# ── Colours ──────────────────────────────────────────────────────────────────
BG = '#1a1a2e'
PANEL = '#16213e'
ACCENT = '#0f3460'
HIGHLIGHT = '#e94560'
TEXT_CLR = '#eaeaea'
SUB_CLR = '#888899'
GREEN = '#4caf50'
RED = '#f44336'
ORANGE = '#ff9800'
# ── Data directory ───────────────────────────────────────────────────────────
if platform == 'android':
from android.storage import app_storage_path
DATA_DIR = app_storage_path()
else:
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
# ── Stdout redirector ────────────────────────────────────────────────────────
class _QueueWriter(io.TextIOBase):
def __init__(self, q):
self._q = q
def write(self, s):
if s:
self._q.put(s)
return len(s) if s else 0
def flush(self):
pass
# ── Bot engine ───────────────────────────────────────────────────────────────
class BotEngine:
def __init__(self, log_q, stop_evt):
self.log_q = log_q
self.stop_evt = stop_evt
self.last_args = None
self.thread = None
self.running = False
self._mcbot = None
def _load(self):
try:
bot_dir = getattr(sys, '_MEIPASS', DATA_DIR)
if bot_dir not in sys.path:
sys.path.insert(0, bot_dir)
import mcbot
self._mcbot = importlib.reload(mcbot)
return True
except Exception as e:
self.log_q.put(f"[ERROR] Cannot import mcbot: {e}\n")
return False
def start(self, args):
if self.running:
return False
self.last_args = args
self.running = True
self.stop_evt.clear()
self.thread = threading.Thread(target=self._run, args=(args,), daemon=True)
self.thread.start()
return True
def stop(self):
if not self.running:
return
self.running = False
self.stop_evt.set()
self.log_q.put("\n[GUI] Stopping bots...\n")
def is_running(self):
return self.running
def _run(self, args):
old_stdout = sys.stdout
sys.stdout = _QueueWriter(self.log_q)
try:
if not self._load():
self.running = False
return
self.log_q.put(f"\n{'='*45}\n")
self.log_q.put(f" Connecting to {args[0]}:{args[1]}\n")
self.log_q.put(f"{'='*45}\n\n")
self._mcbot.run(
host=args[0], port=args[1], nombre=args[2],
bots=args[3], tiempo=args[4], register_cmd=args[5],
mensajes_raw=args[6], msg_intervalo=args[7],
proxy_enabled=args[8], bots_per_proxy=args[9],
nick_wordlist_enabled=args[10],
stop_event=self.stop_evt,
)
except SystemExit:
pass
except Exception as exc:
import traceback
self.log_q.put(f"\n[ERROR] {exc}\n{traceback.format_exc()}\n")
finally:
sys.stdout = old_stdout
self.running = False
self.log_q.put("\n[GUI] Bot engine finished.\n")
# ── Kivy App ─────────────────────────────────────────────────────────────────
class NatsukiApp(App):
log_text = StringProperty('')
def build(self):
self.title = 'Natsuki Spammer'
self.stop_evt = threading.Event()
self.log_q = queue.Queue()
self.engine = BotEngine(self.log_q, self.stop_evt)
root = BoxLayout(orientation='vertical', padding=dp(8), spacing=dp(6))
root.bg_color = BG
# ── Header ────────────────────────────────────────────────────────
header = BoxLayout(size_hint_y=None, height=dp(36))
header.add_widget(Label(
text='Natsuki Spammer', bold=True, font_size=dp(16),
color=HIGHLIGHT, size_hint_x=0.7, halign='left', valign='middle'))
self.status_lbl = Label(
text='Idle', font_size=dp(11), color=SUB_CLR,
size_hint_x=0.3, halign='right', valign='middle')
header.add_widget(self.status_lbl)
root.add_widget(header)
# ── Scrollable form ───────────────────────────────────────────────
scroll = ScrollView()
form = GridLayout(cols=1, spacing=dp(6), size_hint_y=None)
form.bind(minimum_height=form.setter('height'))
def add_section(title, widgets):
lbl = Label(text=title, bold=True, font_size=dp(12),
color=HIGHLIGHT, size_hint_y=None, height=dp(28),
halign='left', valign='middle')
lbl.bind(size=lbl.setter('text_size'))
form.add_widget(lbl)
for w in widgets:
form.add_widget(w)
def make_row(label_text, input_widget, hint=''):
row = BoxLayout(size_hint_y=None, height=dp(36), spacing=dp(6))
row.add_widget(Label(text=label_text, font_size=dp(10),
color=SUB_CLR, size_hint_x=0.35,
halign='left', valign='middle'))
if hint:
input_widget.hint_text = hint
input_widget.font_size = dp(11)
input_widget.background_color = (0.1, 0.12, 0.18, 1)
input_widget.foreground_color = (0.9, 0.9, 0.9, 1)
input_widget.cursor_color = (0.9, 0.9, 0.9, 1)
input_widget.size_hint_x = 0.65
row.add_widget(input_widget)
return row
def make_check(text, variable):
row = BoxLayout(size_hint_y=None, height=dp(30), spacing=dp(6))
cb = CheckBox(size_hint_x=0.15, active=False)
cb.color = HIGHLIGHT
cb.bind(active=lambda inst, val: setattr(variable, 'value', val))
row.add_widget(cb)
row.add_widget(Label(text=text, font_size=dp(10),
color=TEXT_CLR, size_hint_x=0.85,
halign='left', valign='middle'))
return row
# -- Connection --
self.v_ip = TextInput(text='127.0.0.1', multiline=False)
self.v_port = TextInput(text='19132', multiline=False)
add_section('Connection', [
make_row('Server', self.v_ip, 'IP or domain'),
make_row('Port', self.v_port),
])
# -- Bots --
self.v_name = TextInput(text='Bot', multiline=False)
self.v_bots = TextInput(text='1', multiline=False)
self.v_time = TextInput(text='0', multiline=False)
self.v_nickwl = BooleanProperty(False)
add_section('Bots', [
make_row('Name', self.v_name),
make_check('Use wordlist (nicks.txt)', self.v_nickwl),
make_row('Amount', self.v_bots),
make_row('Duration (s)', self.v_time),
])
# -- Register --
self.v_reg = TextInput(text='', multiline=False)
self.reg_choice = StringProperty('')
add_section('Register', [
make_row('Command', self.v_reg, 'e.g. /register'),
self._make_reg_radio('/register', '/register'),
self._make_reg_radio('/r', '/r'),
self._make_reg_radio('(empty) - none', ''),
])
# -- Spam --
self.v_msgs = TextInput(text='Hello!', multiline=False)
self.v_inter = TextInput(text='5', multiline=False)
add_section('Spam', [
make_row('Messages', self.v_msgs, 'separated by |'),
make_row('Interval (s)', self.v_inter),
])
# -- Proxy --
self.v_proxy = BooleanProperty(False)
self.v_bpp = TextInput(text='1', multiline=False)
add_section('Proxy', [
make_check('Enable proxies', self.v_proxy),
make_row('Bots/proxy', self.v_bpp),
])
scroll.add_widget(form)
root.add_widget(scroll)
# ── Log area ──────────────────────────────────────────────────────
self.log_label = Label(
text='', font_size=dp(9), color=TEXT_CLR,
size_hint_y=0.35, halign='left', valign='top',
text_size=(Window.width - dp(16), None))
log_scroll = ScrollView(size_hint_y=0.35)
log_scroll.add_widget(self.log_label)
root.add_widget(log_scroll)
# ── Buttons ───────────────────────────────────────────────────────
btn_row = BoxLayout(size_hint_y=None, height=dp(44), spacing=dp(8))
self.btn_start = Button(text='START', background_color=(0.3, 0.7, 0.3, 1),
bold=True, font_size=dp(12))
self.btn_start.bind(on_press=self._start)
btn_row.add_widget(self.btn_start)
self.btn_stop = Button(text='STOP', background_color=(0.8, 0.2, 0.2, 1),
bold=True, font_size=dp(12), disabled=True)
self.btn_stop.bind(on_press=self._stop)
btn_row.add_widget(self.btn_stop)
root.add_widget(btn_row)
# ── Polling ───────────────────────────────────────────────────────
self._log_buffer = []
Clock.schedule_interval(self._poll_log, 0.1)
return root
def _make_reg_radio(self, text, value):
row = BoxLayout(size_hint_y=None, height=dp(28), spacing=dp(6))
rb = RadioButton(group='reg', size_hint_x=0.15)
rb.color = HIGHLIGHT
if value == '':
rb.active = True
rb.bind(active=lambda inst, val: setattr(self, 'reg_choice', value) if val else None)
row.add_widget(rb)
row.add_widget(Label(text=text, font_size=dp(9), color=SUB_CLR,
size_hint_x=0.85, halign='left', valign='middle'))
return row
def _poll_log(self, dt):
try:
while True:
line = self.log_q.get_nowait()
self._log_buffer.append(line)
except queue.Empty:
pass
if self._log_buffer:
self.log_label.text += ''.join(self._log_buffer)
self._log_buffer.clear()
def _start(self, inst):
try:
port = int(self.v_port.text)
bots = int(self.v_bots.text)
tiempo = int(self.v_time.text)
inter = int(self.v_inter.text)
bpp = int(self.v_bpp.text)
except ValueError:
self.log_label.text += '[ERROR] Invalid number field\n'
return
args = [
self.v_ip.text.strip() or '127.0.0.1',
port,
self.v_name.text.strip() or 'Bot',
bots,
tiempo,
self.v_reg.text.strip(),
self.v_msgs.text.strip() or 'Hello!',
inter,
self.v_proxy.value,
bpp,
self.v_nickwl.value,
]
self.engine.stop_evt.clear()
if self.engine.start(args):
self.btn_start.disabled = True
self.btn_stop.disabled = False
self.status_lbl.text = 'Running'
self.status_lbl.color = GREEN
self.log_label.text += f"\n{'='*45}\n Starting {args[3]} bot(s)\n{'='*45}\n\n"
Clock.schedule_interval(self._check_status, 0.5)
def _stop(self, inst):
self.engine.stop()
self.btn_start.disabled = False
self.btn_stop.disabled = True
self.status_lbl.text = 'Idle'
self.status_lbl.color = SUB_CLR
def _check_status(self, dt):
if not self.engine.is_running():
self.btn_start.disabled = False
self.btn_stop.disabled = True
self.status_lbl.text = 'Idle'
self.status_lbl.color = SUB_CLR
return False
return True
def on_stop(self):
if self.engine.is_running():
self.engine.stop()
if __name__ == '__main__':
NatsukiApp().run()