0% found this document useful (0 votes)
5 views

Message

Uploaded by

justzetsu666
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Message

Uploaded by

justzetsu666
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import discord

from discord.ext import commands


import os
import asyncio
from concurrent.futures import ThreadPoolExecutor
import aiofiles
import json

with open('config.json') as f:
config = json.load(f)

TOKEN = config["token"]
rmk1337 = commands.Bot(command_prefix="+", intents=discord.Intents.all())

DUMP_FOLDER = 'dbip'
CANAL_ID = int(config["allowed_channel_id"])
ROLE_ID = int(config["required_role_id"])
EMBED_COLOR = int(config["embed_color"], 16)
ENCODINGS = ['utf-8', 'latin-1', 'cp1252']

MAX_CONCURRENT_TASKS = 20
BLOCK_SIZE = 1024 * 1024 # 1 Mo
FILE_PROCESSING_TIMEOUT = 5
executor = ThreadPoolExecutor(max_workers=MAX_CONCURRENT_TASKS)

async def read_file_in_chunks(file_path, license, found_event):


for encoding in ENCODINGS:
try:
async with aiofiles.open(file_path, mode='r', encoding=encoding,
errors='ignore') as f:
while True:
content = await f.read(BLOCK_SIZE)
if not content:
break
if license in content:
return content
except Exception as e:
print(f"Erreur avec l'encodage {encoding} pour le fichier {file_path}:
{e}")
return None

async def process_file(file_path, license, results, found_event):


if found_event.is_set():
return

try:
content = await asyncio.wait_for(read_file_in_chunks(file_path, license,
found_event), timeout=FILE_PROCESSING_TIMEOUT)
if content:
associated_info = next((line.strip() for line in content.split('\n') if
license in line), None)
if associated_info:
results.append(associated_info)
found_event.set()
except asyncio.TimeoutError:
print(f"Le traitement du fichier {file_path} a dépassé le temps limite.")
except Exception as e:
print(f"Erreur lors du traitement du fichier {file_path}: {e}")
@rmk1337.tree.command(name="vip", description="Rechercher des informations pour une
licence FiveM")
async def vip(interaction: discord.Interaction, license: str):
if not any(role.id == ROLE_ID for role in interaction.user.roles):
await interaction.response.send_message("Vous n'avez pas le bon rôle pour
utiliser cette commande.", ephemeral=True)
return

if interaction.channel.id != CANAL_ID:
await interaction.response.send_message("Veuillez faire la commande dans le
salon VIP.", ephemeral=True)
return

embed = discord.Embed(title="VIP Recherche", description="Recherche en


cours...", color=EMBED_COLOR)
await interaction.response.send_message(embed=embed)

found_event = asyncio.Event()
results = []

semaphore = asyncio.Semaphore(MAX_CONCURRENT_TASKS)

async def sem_task(file_path):


async with semaphore:
await process_file(file_path, license, results, found_event)

files_to_process = [os.path.join(root, file)


for root, _, files in os.walk(DUMP_FOLDER)
for file in files if file.endswith(('.txt', '.sql'))]

tasks = [sem_task(file_path) for file_path in files_to_process]


await asyncio.gather(*tasks, return_exceptions=True)

if results:
results_message = results[0]
embed = discord.Embed(
title="Résultat de la Recherche",
description=results_message,
color=EMBED_COLOR
)
embed.set_footer(text=config["footer_text"])

try:
await interaction.user.send(embed=embed)
await interaction.followup.send("Les résultats ont été envoyés en
message privé.")
except discord.Forbidden:
await interaction.followup.send("Je ne peux pas vous envoyer de message
privé. Veuillez vérifier vos paramètres de confidentialité.")
except discord.HTTPException as e:
print(f"Erreur lors de l'envoi du message: {e}")
await interaction.followup.send("Erreur lors de l'envoi du message
privé. Veuillez réessayer plus tard.")
else:
embed = discord.Embed(
title="Aucune Information Trouvée",
description="Aucune information trouvée pour cette licence.",
color=EMBED_COLOR
)
embed.set_footer(text=config["footer_text"])
await interaction.followup.send(embed=embed)

@rmk1337.event
async def on_ready():
print(f"{rmk1337.user} est connecté et prêt à l'emploi. 🚀")
print("🌟 Bot développé par rmk1337 pour LookData 💻✨")

await rmk1337.change_presence(activity=discord.Game(name=config["bot_status"]))
await rmk1337.tree.sync()

rmk1337.run(TOKEN)

You might also like