import discord
from discord.ext import commands, tasks
from datetime import datetime, time
from zoneinfo import ZoneInfo
import json
import os
================= CONFIG =================
TOKEN = "TON_TOKEN_ICI"
CHANNEL_ID = 123456789012345678 # Remplace par ton salon
ROLE_HG = "H.G"
TIMEZONE = ZoneInfo("Europe/Paris")
STATS_FILE = "stats.json" # fichier de sauvegarde
==========================================
intents = discord.Intents.default()
intents.message_content = True
intents.reactions = True
intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
Emoji -> Type de braquage
BRAQUAGES = {
"🔵": "Supérette",
"🔴": "Ammu-Nation",
"💶": "ATM",
"🚗": "GoFast",
"🏠": "Cambriolage",
"🎁": "Coffre"
}
================= STATS =================
stats_users = {} # user_id: {✅, ❌}
stats_users_types = {} # user_id: {type: {✅, ❌}}
stats_types = {} # type: {✅, ❌}
stats_total = {"✅": 0, "❌": 0}
braquages_en_cours = {}
================= UTILS =================
def save_stats():
data = {
"stats_users": stats_users,
"stats_users_types": stats_users_types,
"stats_types": stats_types,
"stats_total": stats_total
}
with open(STATS_FILE, "w") as f:
json.dump(data, f)
def load_stats():
global stats_users, stats_users_types, stats_types, stats_total
if os.path.exists(STATS_FILE):
with open(STATS_FILE, "r") as f:
data = json.load(f)
stats_users = data.get("stats_users", {})
stats_users_types = data.get("stats_users_types", {})
stats_types = data.get("stats_types", {})
stats_total = data.get("stats_total", {"✅": 0, "❌": 0})
================= BOT READY =================
@bot.event
async def on_ready():
load_stats()
print(f"✅ Bot connecté : {bot.user}")
await bot.tree.sync()
message_quotidien.start()
classement_hebdo.start()
reset_hebdo_auto.start()
================= MESSAGE QUOTIDIEN =================
@tasks.loop(time=time(hour=0, minute=0, tzinfo=TIMEZONE))
async def message_quotidien():
channel = bot.get_channel(CHANNEL_ID)
msg = await channel.send(
"🚨 Type de braquage 🚨\n"
"Réagissez selon le braquage que vous venez de faire !\n\n"
"🔵 Supérette\n"
"🔴 Ammu-Nation\n"
"💶 ATM\n"
"🚗 GoFast\n"
"🏠 Cambriolage\n"
"🎁 Coffre"
)
for emoji in BRAQUAGES:
await msg.add_reaction(emoji)
================= RÉACTIONS =================
@bot.event
async def on_reaction_add(reaction, user):
if user.bot:
return
now = datetime.now(TIMEZONE)
# Choix du braquage
if reaction.emoji in BRAQUAGES:
type_braquage = BRAQUAGES[reaction.emoji]
msg = await reaction.message.channel.send(
f"👤 **Qui :** {user.mention}\n"
f"💼 **Type :** {type_braquage}\n"
f"⏰ **Heure :** {now.strftime('%H:%M')}\n\n"
"Réagissez :\n"
"❌ si c’est raté !\n"
"✅ si c’est gagné !"
)
braquages_en_cours[msg.id] = (user.id, type_braquage)
await msg.add_reaction("❌")
await msg.add_reaction("✅")
# Résultat
elif reaction.emoji in ["❌", "✅"] and reaction.message.id in braquages_en_cours:
user_id, type_braquage = braquages_en_cours.pop(reaction.message.id)
stats_users.setdefault(user_id, {"✅": 0, "❌": 0})
stats_users[user_id][reaction.emoji] += 1
stats_users_types.setdefault(user_id, {})
stats_users_types[user_id].setdefault(type_braquage, {"✅": 0, "❌": 0})
stats_users_types[user_id][type_braquage][reaction.emoji] += 1
stats_types.setdefault(type_braquage, {"✅": 0, "❌": 0})
stats_types[type_braquage][reaction.emoji] += 1
stats_total[reaction.emoji] += 1
save_stats() # sauvegarde à chaque braquage
================= /COMPTE =================
@bot.tree.command(name="compte", description="Voir les stats globales")
async def compte(interaction: discord.Interaction):
msg = "📊 STATISTIQUES DES BRAQUAGES 📊\n\n"
for uid, data in stats_users.items():
user = await bot.fetch_user(int(uid))
msg += f"- {user.name} → ✅ {data['✅']} | ❌ {data['❌']}\n"
msg += f"\n🌍 TOTAL GLOBAL\n✅ {stats_total['✅']} | ❌ {stats_total['❌']}"
await interaction.response.send_message(msg)
================= /MESBRAQUAGES =================
@bot.tree.command(name="mesbraquages", description="Voir tes stats personnelles")
async def mesbraquages(interaction: discord.Interaction):
uid = str(interaction.user.id)
if uid not in stats_users:
await interaction.response.send_message("📭 Aucun braquage.", ephemeral=True)
return
msg = f"📊 TES BRAQUAGES 📊\n\n✅ {stats_users[uid]['✅']} | ❌ {stats_users[uid]['❌']}\n\n"
for t, r in stats_users_types[uid].items():
msg += f"- {t} → ✅ {r['✅']} | ❌ {r['❌']}\n"
await interaction.response.send_message(msg, ephemeral=True)
================= /RESETCOMPTE (H.G) =================
@bot.tree.command(name="resetcompte", description="Reset stats (H.G)")
async def resetcompte(interaction: discord.Interaction):
if ROLE_HG not in [r.name for r in interaction.user.roles]:
await interaction.response.send_message("⛔ Rôle H.G requis", ephemeral=True)
return
stats_users.clear()
stats_users_types.clear()
stats_types.clear()
stats_total["✅"] = 0
stats_total["❌"] = 0
save_stats()
await interaction.response.send_message("♻️ Compteurs remis à zéro")
================= /POSTCOMPTE =================
@bot.tree.command(name="postcompte", description="Poster les stats globales manuellement")
async def postcompte(interaction: discord.Interaction):
channel = bot.get_channel(CHANNEL_ID)
msg = "📊 STATISTIQUES DES BRAQUAGES (MANUEL) 📊\n\n"
for uid, data in stats_users.items():
user = await bot.fetch_user(int(uid))
msg += f"- {user.name} → ✅ {data['✅']} | ❌ {data['❌']}\n"
msg += f"\n🌍 TOTAL GLOBAL\n✅ {stats_total['✅']} | ❌ {stats_total['❌']}"
await channel.send(msg)
await interaction.response.send_message("✅ Statistiques postées !", ephemeral=True)
================= CLASSEMENT DIMANCHE 20H =================
@tasks.loop(minutes=1)
async def classement_hebdo():
now = datetime.now(TIMEZONE)
if now.weekday() == 6 and now.hour == 20 and now.minute == 0:
channel = bot.get_channel(CHANNEL_ID)
classement = sorted(stats_users.items(), key=lambda x: x[1]["✅"], reverse=True)
msg = "🏆 CLASSEMENT HEBDOMADAIRE 🏆\n\n"
for i, (uid, data) in enumerate(classement, start=1):
user = await bot.fetch_user(int(uid))
msg += f"{i}. {user.name} → ✅ {data['✅']} | ❌ {data['❌']}\n"
await channel.send(msg)
================= RESET HEBDO 20H01 =================
@tasks.loop(minutes=1)
async def reset_hebdo_auto():
now = datetime.now(TIMEZONE)
if now.weekday() == 6 and now.hour == 20 and now.minute == 1:
stats_users.clear()
stats_users_types.clear()
stats_types.clear()
stats_total["✅"] = 0
stats_total["❌"] = 0
save_stats()
channel = bot.get_channel(CHANNEL_ID)
await channel.send("♻️ Reset hebdomadaire effectué – nouvelle semaine !")
bot.run(TOKEN)
import discord
from discord.ext import commands, tasks
from datetime import datetime, time
from zoneinfo import ZoneInfo
import json
import os
================= CONFIG =================
TOKEN = "TON_TOKEN_ICI"
CHANNEL_ID = 123456789012345678 # Remplace par ton salon
ROLE_HG = "H.G"
TIMEZONE = ZoneInfo("Europe/Paris")
STATS_FILE = "stats.json" # fichier de sauvegarde
==========================================
intents = discord.Intents.default()
intents.message_content = True
intents.reactions = True
intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
Emoji -> Type de braquage
BRAQUAGES = {
"🔵": "Supérette",
"🔴": "Ammu-Nation",
"💶": "ATM",
"🚗": "GoFast",
"🏠": "Cambriolage",
"🎁": "Coffre"
}
================= STATS =================
stats_users = {} # user_id: {✅, ❌}
stats_users_types = {} # user_id: {type: {✅, ❌}}
stats_types = {} # type: {✅, ❌}
stats_total = {"✅": 0, "❌": 0}
braquages_en_cours = {}
================= UTILS =================
def save_stats():
data = {
"stats_users": stats_users,
"stats_users_types": stats_users_types,
"stats_types": stats_types,
"stats_total": stats_total
}
with open(STATS_FILE, "w") as f:
json.dump(data, f)
def load_stats():
global stats_users, stats_users_types, stats_types, stats_total
if os.path.exists(STATS_FILE):
with open(STATS_FILE, "r") as f:
data = json.load(f)
stats_users = data.get("stats_users", {})
stats_users_types = data.get("stats_users_types", {})
stats_types = data.get("stats_types", {})
stats_total = data.get("stats_total", {"✅": 0, "❌": 0})
================= BOT READY =================
@bot.event
async def on_ready():
load_stats()
print(f"✅ Bot connecté : {bot.user}")
await bot.tree.sync()
message_quotidien.start()
classement_hebdo.start()
reset_hebdo_auto.start()
================= MESSAGE QUOTIDIEN =================
@tasks.loop(time=time(hour=0, minute=0, tzinfo=TIMEZONE))
async def message_quotidien():
channel = bot.get_channel(CHANNEL_ID)
msg = await channel.send(
"🚨 Type de braquage 🚨\n"
"Réagissez selon le braquage que vous venez de faire !\n\n"
"🔵 Supérette\n"
"🔴 Ammu-Nation\n"
"💶 ATM\n"
"🚗 GoFast\n"
"🏠 Cambriolage\n"
"🎁 Coffre"
)
for emoji in BRAQUAGES:
await msg.add_reaction(emoji)
================= RÉACTIONS =================
@bot.event
async def on_reaction_add(reaction, user):
if user.bot:
return
================= /COMPTE =================
@bot.tree.command(name="compte", description="Voir les stats globales")
async def compte(interaction: discord.Interaction):
msg = "📊 STATISTIQUES DES BRAQUAGES 📊\n\n"
for uid, data in stats_users.items():
user = await bot.fetch_user(int(uid))
msg += f"- {user.name} → ✅ {data['✅']} | ❌ {data['❌']}\n"
msg += f"\n🌍 TOTAL GLOBAL\n✅ {stats_total['✅']} | ❌ {stats_total['❌']}"
await interaction.response.send_message(msg)
================= /MESBRAQUAGES =================
@bot.tree.command(name="mesbraquages", description="Voir tes stats personnelles")
async def mesbraquages(interaction: discord.Interaction):
uid = str(interaction.user.id)
if uid not in stats_users:
await interaction.response.send_message("📭 Aucun braquage.", ephemeral=True)
return
msg = f"📊 TES BRAQUAGES 📊\n\n✅ {stats_users[uid]['✅']} | ❌ {stats_users[uid]['❌']}\n\n"
for t, r in stats_users_types[uid].items():
msg += f"- {t} → ✅ {r['✅']} | ❌ {r['❌']}\n"
await interaction.response.send_message(msg, ephemeral=True)
================= /RESETCOMPTE (H.G) =================
@bot.tree.command(name="resetcompte", description="Reset stats (H.G)")
async def resetcompte(interaction: discord.Interaction):
if ROLE_HG not in [r.name for r in interaction.user.roles]:
await interaction.response.send_message("⛔ Rôle H.G requis", ephemeral=True)
return
stats_users.clear()
stats_users_types.clear()
stats_types.clear()
stats_total["✅"] = 0
stats_total["❌"] = 0
save_stats()
await interaction.response.send_message("♻️ Compteurs remis à zéro")
================= /POSTCOMPTE =================
@bot.tree.command(name="postcompte", description="Poster les stats globales manuellement")
async def postcompte(interaction: discord.Interaction):
channel = bot.get_channel(CHANNEL_ID)
msg = "📊 STATISTIQUES DES BRAQUAGES (MANUEL) 📊\n\n"
for uid, data in stats_users.items():
user = await bot.fetch_user(int(uid))
msg += f"- {user.name} → ✅ {data['✅']} | ❌ {data['❌']}\n"
msg += f"\n🌍 TOTAL GLOBAL\n✅ {stats_total['✅']} | ❌ {stats_total['❌']}"
await channel.send(msg)
await interaction.response.send_message("✅ Statistiques postées !", ephemeral=True)
================= CLASSEMENT DIMANCHE 20H =================
@tasks.loop(minutes=1)
async def classement_hebdo():
now = datetime.now(TIMEZONE)
if now.weekday() == 6 and now.hour == 20 and now.minute == 0:
channel = bot.get_channel(CHANNEL_ID)
classement = sorted(stats_users.items(), key=lambda x: x[1]["✅"], reverse=True)
msg = "🏆 CLASSEMENT HEBDOMADAIRE 🏆\n\n"
for i, (uid, data) in enumerate(classement, start=1):
user = await bot.fetch_user(int(uid))
msg += f"{i}. {user.name} → ✅ {data['✅']} | ❌ {data['❌']}\n"
await channel.send(msg)
================= RESET HEBDO 20H01 =================
@tasks.loop(minutes=1)
async def reset_hebdo_auto():
now = datetime.now(TIMEZONE)
if now.weekday() == 6 and now.hour == 20 and now.minute == 1:
stats_users.clear()
stats_users_types.clear()
stats_types.clear()
stats_total["✅"] = 0
stats_total["❌"] = 0
save_stats()
channel = bot.get_channel(CHANNEL_ID)
await channel.send("♻️ Reset hebdomadaire effectué – nouvelle semaine !")
bot.run(TOKEN)