-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
373 lines (305 loc) · 15 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
# hi!!
import subprocess
try:
import platform
import sys
import os
import asyncio
import json
import ctypes
import time
import asyncio
import config
from Commands import *
from colorama import Fore, Style, Back
import discord
from discord.ext import commands
from discord.ext.tasks import loop
import requests
except ImportError:
import platform
import sys
if sys.platform == 'win32':
subprocess.check_call([sys.executable, "-m", "pip", "install", '-r' , 'requirements.txt'])
else:
subprocess.check_call([sys.executable, "-m", "pip3", "install", '-r' , 'requirements.txt'])
import os
import asyncio
import json
import ctypes
import time
import asyncio
import config
from Commands import *
from colorama import Fore, Style, Back
import discord
from discord.ext import commands
from discord.ext.tasks import loop
import requests
os.system('cls' if os.name == 'nt' else 'clear')
def set_terminal_title(title):
system = platform.system()
if system == 'Windows':
ctypes.windll.kernel32.SetConsoleTitleW(title)
elif system == 'Darwin':
subprocess.run(['osascript', '-e', f'tell application "Terminal" to set custom title of front window to "{title}"'])
elif system == 'Linux':
sys.stdout.write(f"\x1b]2;{title}\x07")
sys.stdout.flush()
try:
set_terminal_title("| Latency Manager |")
except Exception as e:
print(f"Error while trying to change the terminal name: {e}")
repo_owner = "Sitois"
repo_name = "Latency"
latency_version = "v1.0"
print(Fore.LIGHTCYAN_EX + f""" /$$ /$$
| $$ | $$
| $$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$$ /$$ /$$
| $$ |____ $$|_ $$_/ /$$__ $$| $$__ $$ /$$_____/| $$ | $$
| $$ /$$$$$$$ | $$ | $$$$$$$$| $$ \ $$| $$ | $$ | $$
| $$ /$$__ $$ | $$ /$$| $$_____/| $$ | $$| $$ | $$ | $$
| $$$$$$$$| $$$$$$$ | $$$$/| $$$$$$$| $$ | $$| $$$$$$$| $$$$$$$
|________/ \_______/ \___/ \_______/|__/ |__/ \_______/ \____ $$
/$$ | $$
| $$$$$$/
\______/ {latency_version}""", Style.RESET_ALL)
def check_latest_version(repo_owner, repo_name):
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest"
response = requests.get(url)
if response.status_code == 200:
release_info = response.json()
latest_version = release_info['tag_name']
return latest_version
else:
return None
def call_check_repo():
global latency_version
global repo_owner
global repo_name
current_version = latency_version
latest_version = check_latest_version(repo_owner, repo_name)
if latest_version:
if not latest_version == current_version:
print(Fore.BLUE, "[INFO]", f"Une nouvelle version ({latest_version}) est disponible: https://github.com/{repo_owner}/{repo_name}/releases/tag/{latest_version}")
print(f" Vous utilisez actuellement la version {current_version}", Style.RESET_ALL)
try:
call_check_repo()
except Exception as e:
print(f"Error while trying to check the last Latency version: {e}")
print(Fore.LIGHTYELLOW_EX, "[#]", Fore.YELLOW, "Démarrage du manager...")
prefix = config.prefix
owner_id = config.owner_id
whitelist = config.whitelist
tokens_list = []
intents_main_bot = discord.Intents.default()
intents_main_bot.dm_messages = True
intents_secondary_bot = discord.Intents.default()
intents_secondary_bot.messages = True
intents_secondary_bot.members = True
intents_secondary_bot.presences = True
class MainBot(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.secondary_bots = {}
async def update_presence(self):
await self.bot.wait_until_ready()
while not self.bot.is_closed():
activity = discord.Activity(type=discord.ActivityType.streaming, name=f"⌘ {len(tokens_list)} Connected !", url=config.streaming_url, application_id=self.bot.user.id)
await self.bot.change_presence(activity=activity, status=discord.Status.dnd)
await asyncio.sleep(120)
@commands.command(name="wl", hidden=True)
async def wl(self, ctx, *, message):
if ctx.author.id in owner_id:
split_message = message
try:
whitelist.append(int(split_message))
except:
await ctx.send("Ce n'est pas une ID valide !")
return
await ctx.send(f"<@{split_message.strip()}> a bien été ajouté à la wl !")
@commands.command(name="bl", hidden=True)
async def bl_command(self, ctx, user_id: int):
if ctx.author.id in owner_id:
if user_id in whitelist:
whitelist.remove(user_id)
await ctx.send(f"<@{user_id}> a bien été supprimé de la whitelist !")
else:
await ctx.send(f"{user_id} n'est pas dans la whitelist.")
@commands.command(name=config.list_command, hidden=True)
async def list_command(self, ctx):
if ctx.author.id in owner_id:
users_list = [f"<@{user_id}>," for user_id in whitelist]
owners_list = [f"<@{owner_id}>," for owner_id in owner_id]
users_str = '\n'.join(users_list)
owners_str = '\n'.join(owners_list)
embed = discord.Embed(
title="🌠| Info:",
color=0xFF0000,
description=fr"""> 🌈 __Users__: {users_str}
> 🚀 __Owners__: {owners_str}"""
)
embed.set_image(url="https://media.discordapp.net/attachments/1135264530188992562/1194342119989575832/MGflOC7.jpg?ex=65b000c7&is=659d8bc7&hm=c64b7087090c66bcea992d538bab97f208a880191863ee3b2f3b41cd739d1902&=&format=webp&width=744&height=419")
await ctx.send(embed=embed)
@commands.command(name="owner", hidden=True)
async def owner_command(self, ctx, user_id: int):
if ctx.author.id in owner_id:
if user_id not in owner_id:
owner_id.append(user_id)
await ctx.send(f"{user_id} a bien été ajouté à la liste des owners !")
else:
await ctx.send(f"{user_id} est déjà dans la liste des owners.")
@commands.command(name="clear", hidden=True)
async def clear_command(self, ctx, num_messages: int):
if ctx.author.id in owner_id:
if 0 < num_messages <= 100:
await ctx.message.delete()
await ctx.channel.purge(limit=num_messages)
await ctx.send(f"🚮| {num_messages} messages ont été supprimés.", delete_after=3)
else:
await ctx.send("❗ Le nombre de messages à supprimer doit être compris entre 1 et 100.")
@commands.command(name="restart", hidden=True)
async def restart_command(self, ctx):
if ctx.author.id in owner_id:
def restart_selfbot():
python = sys.executable
os.execl(python, python, *sys.argv)
await ctx.send("🔄️ Manager redémarré (patientez quelques secondes...).")
restart_selfbot()
@commands.command(name="stop", hidden=True)
async def stop_command(self, ctx):
if ctx.author.id in owner_id:
await ctx.send("🔴 Manager stoppé.")
await self.bot.close()
exit()
@commands.command(name="help", hidden=True)
async def help_command(self, ctx):
if ctx.author.id in owner_id:
await ctx.send(f"> Use `{config.bot_prefix}{config.help_command}` instead !")
@commands.command(name="un_owner", hidden=True)
async def un_owner_command(self, ctx, user_id: int):
if ctx.author.id in owner_id:
if user_id in owner_id:
owner_id.remove(user_id)
await ctx.send(f"{user_id} a bien été supprimé de la liste des propriétaires !")
else:
await ctx.send(f"{user_id} n'est pas dans la liste des propriétaires.")
@commands.command(name="eval", hidden=True)
async def eval_command(self, ctx):
if ctx.author.id in owner_id:
message_split = ctx.message.content.split()
message = ctx.message.content.replace(f"{message_split[0]} ", "")
try:
await ctx.channel.send(f"""✅| Résultat:
```py
{eval(message)}
```""")
except Exception as e:
await ctx.channel.send(f"""❌| Erreur
```py
{e}
```""")
@commands.command(name=config.help_command, hidden=True)
async def secret_help_command(self, ctx):
if ctx.author.id in owner_id:
embed = discord.Embed(
title="Help Menu",
description=f"""`{config.bot_prefix}{config.list_command}` -> Présente la liste des Users et Owners.
`{config.bot_prefix}wl <user_id>` -> Permet de whitelist quelqu'un avec son ID.
`{config.bot_prefix}bl <user_id>` -> Permet de supprimer quelqu'un de la whitelist avec son ID.
`{config.bot_prefix}owner <user_id>` -> Permet d'ajouter quelqu'un à la liste des Owners.
`{config.bot_prefix}un_owner <user_id>` -> Permet de supprimr quelqu'un de la liste des Owners.
`{config.bot_prefix}eval <code>` -> Permet d'évaluer du code Python.
`{config.bot_prefix}stop` -> Permet de stoppé le manager.
`{config.bot_prefix}restart` -> Permet de redémarré le manager.
`{config.bot_prefix}clear <nombre>` -> Permet de supprimer les messages du salon.
`{config.bot_prefix}start <token>` -> **SEULEMENT EN MP**, permet d'ajouter quelqu'un avec son token.""",
color=0x3498db
)
embed.set_image(url="https://media.discordapp.net/attachments/1135264530188992562/1194342119989575832/MGflOC7.jpg?ex=65b000c7&is=659d8bc7&hm=c64b7087090c66bcea992d538bab97f208a880191863ee3b2f3b41cd739d1902&=&format=webp&width=744&height=419")
await ctx.send(embed=embed)
@commands.command(name=config.start_command, hidden=True)
async def start_bot(self, ctx, *, token):
if isinstance(ctx.channel, discord.DMChannel):
if ctx.author.id in whitelist:
if not token in tokens_list:
try:
SecondaryBot.save_bot_data(ctx.author.id, ctx.author.name, token)
new_bot = SecondaryBot.create_new_instance(self.bot, token)
print(Fore.MAGENTA + " [!]", Fore.LIGHTMAGENTA_EX + f" Token: {token}", Style.RESET_ALL)
msg = await ctx.send(f"✅ Vous êtes conecté !\n💡 Commencez par ``{config.prefix}help`` !")
tokens_list.append(token)
await new_bot.start(token, bot=False)
self.secondary_bots[new_bot.user.id] = new_bot
except discord.LoginFailure:
await msg.edit(content="❌ Échec de connexion. Token incorrect.")
print(Fore.LIGHTRED_EX, "[-]", Fore.RED, f"Token fourni par @{ctx.author.name}({ctx.author.id}) incorrect.", Style.RESET_ALL)
tokens_list.pop()
except Exception as e:
await msg.edit(content=f"❗ Une erreur rare s'est produite. MP `{config.support_username}`.")
print(Fore.LIGHTCYAN_EX, "[!!!]", Fore.CYAN, f"Une erreur rare s'est produite par @{ctx.author.name}({ctx.author.id}). Erreur: {e}", Style.RESET_ALL)
tokens_list.pop()
else:
await ctx.send("❌ Vous êtes déjà connecté !")
else:
await ctx.send("❗ Vous n'avez pas été wl !")
class SecondaryBot(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print(Fore.GREEN, "[+]", Fore.LIGHTGREEN_EX, f'Nouveau compte connecté en tant que @{self.bot.user.name}({self.bot.user.id})', Style.RESET_ALL)
await self.bot.change_presence(status=discord.Status.idle, activity=discord.Activity(type=discord.ActivityType.competing, name=config.name, details=config.details, assets=config.assets, state=config.state))
@commands.Cog.listener()
async def on_message(self, ctx):
if ctx.author.id == self.bot.user.id:
if ctx.content.startswith(f"{config.prefix}unlogin"):
await ctx.edit(content="❕ Déconnecté")
time.sleep(5)
await ctx.delete()
with open(f"./db/{ctx.author.name}.json", "r") as file:
data = json.load(file)
token_json = data["token"]
tokens_list.remove(token_json)
db_file_path = f"./db/{ctx.author.name}.json"
if os.path.exists(db_file_path):
os.remove(db_file_path)
await self.bot.close()
@staticmethod
def save_bot_data(bot_id, bot_name, token):
db_dir = "./db/"
file_path = os.path.join(db_dir, f"{bot_name}.json")
if not os.path.exists(file_path):
with open(file_path, "w") as file:
bot_data = {
"id": bot_id,
"name": bot_name,
"token": token
}
json.dump(bot_data, file, indent=4)
async def start(self, token, bot=True):
await self.bot.start(token, bot=bot)
@staticmethod
def create_new_instance(original_bot, new_token):
new_bot = commands.Bot(command_prefix='!', intents=intents_secondary_bot, help_command=None)
new_bot.add_cog(SecondaryBot(new_bot))
# Utils
new_bot.add_cog(Clear_command(new_bot))
# Helps
new_bot.add_cog(Help_command(new_bot))
new_bot.add_cog(General_command(new_bot))
# RichPresence
new_bot.add_cog(Templates_command(new_bot))
new_bot.shared_token = new_token
return new_bot
bot = commands.Bot(command_prefix=config.bot_prefix, intents=intents_main_bot, help_command=None)
bot.add_cog(MainBot(bot))
@bot.event
async def on_ready():
print(Fore.RED, "[~]", Fore.LIGHTRED_EX, f'Manager connecté en tant que {bot.user}', Style.RESET_ALL)
print(Fore.MAGENTA ,"------------------", Style.RESET_ALL)
bot.loop.create_task(MainBot(bot).update_presence())
try:
bot.run(config.bot_token, bot=True)
except discord.LoginFailure:
print("Token Incorrect. Entrez un token valide dans config.py")