-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
415 lines (360 loc) · 19.2 KB
/
main.py
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
409
410
411
412
413
414
415
# ----- Imports ----- #
import discord
import json
import os
import time
import random
import requests
import getpass
# ----- From Imports ----- #
from datetime import datetime
from colorama import Fore, Style
from pystyle import Write, System, Colors, Colorate, Anime
from discord.ext import tasks
from threading import Thread
from itertools import cycle
from shutil import get_terminal_size
# ----- Variables ----- #
CONFIG_PATH = 'config.json'
TOKEN_PATH = 'tokens.txt'
SERVERS_PATH = 'servers.json'
PROXIES_PATH = 'proxies.txt'
username = getpass.getuser()
# ----- Logging Class ----- #
class Logger:
def __init__(self, prefix: str = "discord.cyberious.xyz"):
self.WHITE = "\u001b[37m"
self.MAGENTA = "\033[38;5;97m"
self.MAGENTAA = "\033[38;2;157;38;255m"
self.RED = "\033[38;5;196m"
self.GREEN = "\033[38;5;40m"
self.YELLOW = "\033[38;5;220m"
self.BLUE = "\033[38;5;21m"
self.PINK = "\033[38;5;176m"
self.CYAN = "\033[96m"
self.prefix = f"{self.PINK}[{self.MAGENTA}{prefix}{self.PINK}] "
def message3(self, level: str, message: str, start: int = None, end: int = None) -> str:
time = self.get_time()
return f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] {self.PINK}[{self.CYAN}{level}{self.PINK}] -> {self.CYAN}{message}{Fore.RESET}"
def get_time(self) -> str:
return datetime.now().strftime("%H:%M:%S")
def success(self, message: str, start: int = None, end: int = None, level: str = "Success") -> None:
print(self.message3(f"{self.GREEN}{level}", f"{self.GREEN}{message}", start, end))
def failure(self, message: str, start: int = None, end: int = None, level: str = "Failure") -> None:
print(self.message3(f"{self.RED}{level}", f"{self.RED}{message}", start, end))
def warning(self, message: str, start: int = None, end: int = None, level: str = "Warning") -> None:
print(self.message3(f"{self.YELLOW}{level}", f"{self.YELLOW}{message}", start, end))
def message(self, level: str, message: str, start: int = None, end: int = None) -> None:
time = self.get_time()
if start is not None and end is not None:
print(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] {self.PINK}[{self.CYAN}{level}{self.PINK}] -> {Fore.RESET} {self.CYAN}{message}{Fore.RESET} [{Fore.CYAN}{end - start}s{Style.RESET_ALL}]")
else:
print(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] [{Fore.BLUE}{level}{self.PINK}] -> {Fore.RESET} {self.CYAN}{message}{Fore.RESET}")
def message2(self, level: str, message: str, start: int = None, end: int = None) -> None:
time = self.get_time()
if start is not None and end is not None:
print(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] {self.PINK}[{self.CYAN}{level}{self.PINK}] -> {Fore.RESET} {self.CYAN}{message}{Fore.RESET} [{Fore.CYAN}{end - start}s{Style.RESET_ALL}]", end="\r")
else:
print(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] {self.PINK}[{Fore.BLUE}{level}{self.PINK}] -> {Fore.RESET} {self.CYAN}{message}{Fore.RESET}", end="\r")
def question(self, message: str, start: int = None, end: int = None) -> None:
time = self.get_time()
i = input(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] {Fore.RESET} {self.PINK}[{Fore.BLUE}?{self.PINK}] -> {Fore.RESET} {self.CYAN}{message}{Fore.RESET}")
return i
def info(self, message: str, start: int = None, end: int = None) -> None:
time = self.get_time()
print(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] {Fore.RESET} {self.PINK}[{Fore.BLUE}!{self.PINK}] -> {Fore.RESET} {self.CYAN}{message}{Fore.RESET}")
def debug(self, message: str, start: int = None, end: int = None) -> None:
time = self.get_time()
print(f"{self.prefix}[{self.MAGENTAA}{time}{self.PINK}] {Fore.RESET} {self.PINK}[{Fore.YELLOW}DEBUG{self.PINK}] -> {Fore.RESET} {self.GREEN}{message}{Fore.RESET}")
log = Logger()
class Loader:
def __init__(self, desc="Loading...", end="\r", timeout=0.1):
self.desc = desc
self.end = end
self.timeout = timeout
self.time = datetime.now().strftime("%H:%M:%S")
self._thread = Thread(target=self._animate, daemon=True)
self.steps = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"]
self.done = False
def start(self):
self._thread.start()
return self
def _animate(self):
for c in cycle(self.steps):
if self.done:
break
print(f"\r{log.PINK}[{log.MAGENTA}discord.cyberious.xyz{log.PINK}] [{log.MAGENTAA}{self.time}{log.PINK}] {log.PINK}[{Fore.BLUE}Connection{log.PINK}] -> {Fore.RESET} {log.GREEN}{self.desc}{Fore.RESET} {c}", flush=True, end="")
time.sleep(self.timeout)
def __enter__(self):
self.start()
def stop(self):
self.done = True
cols = get_terminal_size((80, 20)).columns
print("\r" + " " * cols, end="", flush=True)
print(f"\r{self.end}", flush=True)
def __exit__(self, exc_type, exc_value, tb):
# handle exceptions with those variables ^
self.stop()
def home():
os.system('cls' if os.name == 'nt' else 'clear')
Write.Print(f"""
\t\t /$$$$$$ /$$ /$$ /$$$$$$ /$$
\t\t /$$__ $$ | $$ | $$ /$$__ $$ | $$
\t\t | $$ \__//$$$$$$ /$$$$$$ /$$$$$$$| $$ /$$ | $$ \__/ /$$$$$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$
\t\t | $$$$$$|_ $$_/ /$$__ $$ /$$_____/| $$ /$$/ | $$$$$$ /$$__ $$| $$__ $$ /$$__ $$ /$$__ $$ /$$__ $$
\t\t \____ $$ | $$ | $$ \ $$| $$ | $$$$$$/ \____ $$| $$$$$$$$| $$ \ $$| $$ | $$| $$$$$$$$| $$ \__/
\t\t /$$ \ $$ | $$ /$$| $$ | $$| $$ | $$_ $$ /$$ \ $$| $$_____/| $$ | $$| $$ | $$| $$_____/| $$
\t\t | $$$$$$/ | $$$$/| $$$$$$/| $$$$$$$| $$ \ $$ | $$$$$$/| $$$$$$$| $$ | $$| $$$$$$$| $$$$$$$| $$
\t\t \______/ \___/ \______/ \_______/|__/ \__/ \______/ \_______/|__/ |__/ \_______/ \_______/|__/
\t\t
\t\t Welcome {username} | discord.cyberious.xyz
\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\t\t ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════\n""", Colors.red_to_blue , interval=0.0000)
home()
class MyClient(discord.Client):
def __init__(self, token, proxy=None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.token = token
self.proxy = self.format_proxy(proxy)
self.config = self.load_config()
self.debug = self.config.get("debug", False)
self.servers = []
self.load_servers()
self.stock_messages = {}
self.dm_reply = None
self.use_different_messages = False
self.stock_path = None
self.min_delay = 1 # Minimum delay of 1 second
self.slowmode_intervals = {}
if self.debug:
log.debug(f"Initialized MyClient with token: {token} and proxy: {proxy}")
log.debug(f"Loaded configuration: {self.config}")
def load_config(self):
if os.path.exists(CONFIG_PATH):
with open(CONFIG_PATH, 'r') as f:
try:
config = json.load(f)
return config
except json.JSONDecodeError as e:
log.failure(f"Error decoding JSON from {CONFIG_PATH}: {e}")
return {}
else:
return {}
def load_servers(self):
if os.path.exists(SERVERS_PATH):
if self.debug:
log.debug(f"Loading servers from {SERVERS_PATH}")
with open(SERVERS_PATH, 'r') as f:
try:
self.servers = json.load(f)
if not isinstance(self.servers, list):
log.warning(f"Expected a list but got {type(self.servers)} in {SERVERS_PATH}. Reinitializing.")
self.servers = []
except json.JSONDecodeError as e:
log.warning(f"Error decoding JSON from {SERVERS_PATH} : {e}. Reinitializing.")
self.servers = []
else:
self.servers = []
if self.debug:
log.debug(f"Loaded servers: {self.servers}")
def save_servers(self):
if self.debug:
log.debug(f"Saving servers to {SERVERS_PATH}")
with open(SERVERS_PATH, 'w') as f:
json.dump(self.servers, f, indent=4)
async def send_stock_message(self, guild_id, channel_id, message):
if self.debug:
log.debug(f"Attempting to send message to Guild {guild_id} Channel {channel_id}")
guild = self.get_guild(guild_id)
if guild is None:
self.log_to_webhook(f"Guild {guild_id} not found", error=True)
log.failure(f"Guild {guild_id} not found")
input('')
return
channel = guild.get_channel(channel_id)
if channel is None:
self.log_to_webhook(f"Channel {channel_id} not found in guild {guild.name}", error=True)
log.failure(f"Channel {channel_id} not found in guild {guild.name}")
input('')
return
try:
await channel.send(message)
self.log_to_webhook(f"Successfully sent message to {guild.name} ({guild_id}) - {channel.name} ({channel_id})", guild, channel)
log.message("Success", f"Successfully sent message to {guild.name} ({guild_id}) - {channel.name} ({channel_id})")
except discord.errors.HTTPException as e:
self.log_to_webhook(f"Failed to send message to {guild.name} ({guild_id}) - {channel.name} ({channel_id}): {str(e)}", guild, channel, error=True)
log.failure(f"Failed to send message to {guild.name} ({guild_id}) - {channel.name} ({channel_id}): {str(e)}")
pass
except Exception as e:
self.log_to_webhook(f"Unexpected error while sending message to {guild.name} ({guild_id}) - {channel.name} ({channel_id}): {str(e)}", guild, channel, error=True)
log.failure(f"Unexpected error while sending message to {guild.name} ({guild_id}) - {channel.name} ({channel_id}): {str(e)}")
pass
def log_to_webhook(self, message, guild=None, channel=None, error=False):
if self.config.get("use_webhook", False):
embed = {
"title": "Stock Message Log",
"description": message,
"color": 0xff0000 if error else 0x00ff00,
"thumbnail": {
"url": guild.icon.url if guild and guild.icon else ""
},
"fields": [
{"name": "Guild", "value": guild.name if guild else "N/A", "inline": True},
{"name": "Channel", "value": channel.name if channel else "N/A", "inline": True}
],
"footer": {
"text": "Stock Message Sender",
"icon_url": self.user.avatar.url if self.user.avatar else ""
}
}
requests.post(self.config["webhook_url"], json={"embeds": [embed]})
if self.debug:
log.debug('Sent message to webhook')
else:
log.debug(f"Message: {message}")
@staticmethod
def get_tokens():
if os.path.exists(TOKEN_PATH):
with open(TOKEN_PATH, 'r') as f:
return [line.strip() for line in f]
return []
@staticmethod
def format_proxy(proxy):
if not proxy:
return None
if not proxy.startswith("http://"):
proxy = "http://" + proxy
if "@" not in proxy:
return proxy
user_pass, ip_port = proxy.split("@")
user, password = user_pass.split(":")
ip, port = ip_port.split(":")
return f"http://{user}:{password}@{ip}:{port}"
async def on_ready(self):
if hasattr(self, 'loader'):
self.loader.stop() # Stop the loader when the client is ready
home()
log.message("Logged In", f'Logged in as {self.user} (ID: {self.user.id})')
self.send_messages_loop.start()
if self.debug:
log.debug("Message sending loop started")
def configure(self):
use_saved = log.question("Use servers from servers.json? (y/n): ").lower() == 'y'
if not use_saved:
add_more = True
while add_more:
guild_id = int(log.question("Enter Guild ID: "))
channel_id = int(log.question("Enter Channel ID: "))
self.servers.append({"guild_id": guild_id, "channel_id": channel_id})
add_more = log.question("Add another server? (y/n): ").lower() == 'y'
save_to_file = log.question("Save servers to servers.json? (y/n): ").lower() == 'y'
if save_to_file:
self.save_servers()
reply_to_dms = log.question("Reply to DMs? (y/n): ").lower() == 'y'
if reply_to_dms:
self.dm_reply = log.question("Enter the DM reply message: ")
self.use_different_messages = log.question("Use different stock messages for different servers? (y/n): ").lower() == 'y'
if self.use_different_messages:
for server in self.servers:
message_path = log.question(f"Enter the stock message or path for Guild {server['guild_id']} Channel {server['channel_id']}: ")
self.stock_messages[(server['guild_id'], server['channel_id'])] = message_path
else:
self.stock_path = log.question("Enter the stock message or path: ")
if self.debug:
log.debug(f"Configuration completed. Servers: {self.servers}, DM reply: {self.dm_reply}, Use different messages: {self.use_different_messages}")
def get_stock_message(self, guild_id=None, channel_id=None):
if self.debug:
log.debug(f"Getting stock message for Guild {guild_id} Channel {channel_id}")
if self.use_different_messages and (guild_id, channel_id) in self.stock_messages:
path_or_message = self.stock_messages[(guild_id, channel_id)]
else:
path_or_message = self.stock_path
if os.path.isdir(path_or_message):
if self.debug:
log.debug(f"Loading message from directory: {path_or_message}")
files = [os.path.join(path_or_message, f) for f in os.listdir(path_or_message) if os.path.isfile(os.path.join(path_or_message, f))]
if files:
selected_file = random.choice(files)
with open(selected_file, 'r', encoding='utf-8') as f:
return f.read()
else:
log.warning(f"No files found in directory: {path_or_message}")
return None
elif os.path.isfile(path_or_message):
if self.debug:
log.debug(f"Loading message from file: {path_or_message}")
with open(path_or_message, 'r', encoding='utf-8') as f:
return f.read()
return path_or_message
async def on_message(self, message):
if message.author == self.user:
return
if isinstance(message.channel, discord.DMChannel) and self.dm_reply:
await message.channel.send(self.dm_reply)
if self.debug:
log.debug(f"Sent DM reply to {message.author}")
@tasks.loop(seconds=1) # Check every second
async def send_messages_loop(self):
for server in self.servers:
guild_id = server['guild_id']
channel_id = server['channel_id']
message = self.get_stock_message(guild_id, channel_id) if self.use_different_messages else self.get_stock_message()
if message is None:
log.warning(f"No valid stock message found for Guild {guild_id} Channel {channel_id}")
continue
guild = self.get_guild(guild_id)
if guild:
channel = guild.get_channel(channel_id)
if channel:
if (guild_id, channel_id) not in self.slowmode_intervals or time.time() >= self.slowmode_intervals[(guild_id, channel_id)]:
await self.send_stock_message(guild_id, channel_id, message)
self.slowmode_intervals[(guild_id, channel_id)] = time.time() + channel.slowmode_delay
if self.debug:
log.debug(f"Sent message to Guild {guild_id} Channel {channel_id} and updated slowmode interval")
else:
log.failure(f"Channel {channel_id} not found in guild {guild_id}")
else:
log.failure(f"Guild {guild_id} not found")
def truncate_token(token, max_length=10):
if len(token) > max_length:
return token[:max_length] + '...'
else:
return token
def run_client_with_loader(token, proxy, debug):
client = MyClient(token, proxy)
client.configure()
loader_message = f"Connecting to token {truncate_token(token)}... " if debug else "Connecting to token... "
loader = Loader(loader_message)
client.loader = loader # Assign loader to the client instance
try:
with loader:
if debug:
client.run(token)
else:
client.run(token, log_handler=None)
except Exception as e:
log.failure(f"Failed to run client: {e}")
def run_clients(tokens, proxies):
config = {}
if os.path.exists(CONFIG_PATH):
with open(CONFIG_PATH, 'r') as f:
try:
config = json.load(f)
except json.JSONDecodeError as e:
log.failure(f"Error decoding JSON from {CONFIG_PATH}: {e}")
debug = config.get("debug", False)
if len(tokens) == 1:
token = tokens[0]
proxy = random.choice(proxies) if proxies else None
run_client_with_loader(token, proxy, debug)
else:
for token in tokens:
proxy = random.choice(proxies) if proxies else None
run_client_with_loader(token, proxy, debug)
if __name__ == "__main__":
tokens = MyClient.get_tokens()
proxies = []
if os.path.exists(PROXIES_PATH):
with open(PROXIES_PATH, 'r') as f:
proxies = [line.strip() for line in f]
run_clients(tokens, proxies)